|
|
|
|
@ -28,7 +28,7 @@ def update_cookie(cookies, profile_name): |
|
|
|
|
pickle.dump(cookies, f) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def write_error(nr, e="", traceback="", soup="", user="", url="", url_name="", profile=""): |
|
|
|
|
def write_error(nr, e=" ", traceback="", soup="", user="", url="", url_name="", profile=""): |
|
|
|
|
"""Skriver info efter error till arango |
|
|
|
|
|
|
|
|
|
Args: |
|
|
|
|
@ -36,21 +36,28 @@ def write_error(nr, e="", traceback="", soup="", user="", url="", url_name="", p |
|
|
|
|
e (str, optional): error. Defaults to "". |
|
|
|
|
traceback (str, optional): The traceback from traceback.format_exc(). Defaults to "". |
|
|
|
|
soup (str, optional): Soup. Defaults to "". |
|
|
|
|
user (str, optional): The user. Defaults to "". |
|
|
|
|
user (class, optional): The user. Defaults to "". |
|
|
|
|
url (str, optional): Url, if any. Defaults to "". |
|
|
|
|
count (int, optional): Count, if any. Defaults to 0. |
|
|
|
|
url_name (str, optional): The description of the url, if any. Defaults to "". |
|
|
|
|
profile (user, optional): The profile. |
|
|
|
|
""" |
|
|
|
|
if url == "": |
|
|
|
|
url = "ingen url" |
|
|
|
|
url_name = "ingen url" |
|
|
|
|
|
|
|
|
|
# BARA VID FELSÖKNING |
|
|
|
|
_print(profile.container, e) |
|
|
|
|
_print(profile.container, traceback) |
|
|
|
|
|
|
|
|
|
try: |
|
|
|
|
# BARA VID FELSÖKNING |
|
|
|
|
print(profile, user, e) |
|
|
|
|
print(profile, user, traceback.format_exc()) |
|
|
|
|
_print(profile, user, e) |
|
|
|
|
_print(profile, user, traceback.format_exc()) |
|
|
|
|
except Exception as e: |
|
|
|
|
print('Kunde inte skriva error print till databasen.') |
|
|
|
|
print(e) |
|
|
|
|
if "e" not in locals(): |
|
|
|
|
e = 'Unknown error' |
|
|
|
|
doc = { |
|
|
|
|
"_key": f"{now()}_{profile.container})", |
|
|
|
|
"_key": f"{now()}_{profile.lookingup})", |
|
|
|
|
"number": nr, |
|
|
|
|
"error": nr, |
|
|
|
|
"user": str(user.username), |
|
|
|
|
@ -58,9 +65,9 @@ def write_error(nr, e="", traceback="", soup="", user="", url="", url_name="", p |
|
|
|
|
"url": str(url), |
|
|
|
|
"url_name": url_name, |
|
|
|
|
"soup": str(soup), |
|
|
|
|
"traceback": str(traceback), |
|
|
|
|
"traceback": str(traceback).split('\n'), |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try: |
|
|
|
|
db.insert_document( |
|
|
|
|
"errors", |
|
|
|
|
@ -69,32 +76,48 @@ def write_error(nr, e="", traceback="", soup="", user="", url="", url_name="", p |
|
|
|
|
silent=True, |
|
|
|
|
) |
|
|
|
|
except Exception as e: |
|
|
|
|
_print(profile.container, user, e) |
|
|
|
|
_print(profile, user, e) |
|
|
|
|
|
|
|
|
|
def now(): |
|
|
|
|
""" Returns current date and time as string""" |
|
|
|
|
return datetime.now().strftime("%Y-%m-%d_%H:%M:%S") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _print(container, user, text, end='\n', silent=False): |
|
|
|
|
def nowstamp(): |
|
|
|
|
""" Returns current date and time as timestamp""" |
|
|
|
|
return int(datetime.now().timestamp()) |
|
|
|
|
|
|
|
|
|
def _print(profile, user, text, end='\n', silent=False, sleeptime=0): |
|
|
|
|
""" Write a "print" to the database (and prints in in the terminal) |
|
|
|
|
|
|
|
|
|
Args: |
|
|
|
|
container (string): the value of profile.container, meaning the "original" user. |
|
|
|
|
lookingup (string): the value of profile.lookingup, meaning the "original" user. |
|
|
|
|
user (class): The user username currelntly beeing looked up. |
|
|
|
|
text (string): What should be written. |
|
|
|
|
end (str, optional): The end value for print. Defaults to '\n'. |
|
|
|
|
silent (bool, optional): If a print should be done in the terminal. Defaults to False. |
|
|
|
|
""" |
|
|
|
|
|
|
|
|
|
from classes import User |
|
|
|
|
|
|
|
|
|
if silent == False: |
|
|
|
|
print(text, end=end) |
|
|
|
|
if user != '': |
|
|
|
|
user = f"{user} - " |
|
|
|
|
|
|
|
|
|
if isinstance(user, User): |
|
|
|
|
if isinstance(text, list): |
|
|
|
|
to_print = {user.username: text} |
|
|
|
|
else: |
|
|
|
|
to_print = f"{user.username} - {text.strip()}" |
|
|
|
|
|
|
|
|
|
else: |
|
|
|
|
if isinstance(text, list): |
|
|
|
|
to_print = {user: text} |
|
|
|
|
else: |
|
|
|
|
to_print = f"{text.strip()}" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.insert_document( |
|
|
|
|
"prints", |
|
|
|
|
{'_key': container, 'print':{now(): f"{user}{text.strip()}"}}, |
|
|
|
|
{'_key': profile.lookingup, 'print':{now(): to_print}}, |
|
|
|
|
overwrite_mode="update", |
|
|
|
|
silent=True, |
|
|
|
|
merge=True |
|
|
|
|
) |
|
|
|
|
) |
|
|
|
|
sleep(sleeptime) |