|
|
|
@ -22,13 +22,13 @@ def sleep_(t): |
|
|
|
sleep(random.randrange(0, 10, 1) / 4) |
|
|
|
sleep(random.randrange(0, 10, 1) / 4) |
|
|
|
|
|
|
|
|
|
|
|
# TODO #1 spara cookies till db |
|
|
|
# TODO #1 spara cookies till db |
|
|
|
def update_cookie(cookies, profile_name): |
|
|
|
def update_cookie(cookies, profile): |
|
|
|
""" Uppdaterar cookie för browser """ |
|
|
|
""" Uppdaterar cookie för browser """ |
|
|
|
with open("data/cookie_{}.pkl".format(profile_name), "wb") as f: |
|
|
|
with open("data/cookie_{}.pkl".format(profile.name), "wb") as f: |
|
|
|
pickle.dump(cookies, f) |
|
|
|
pickle.dump(cookies, f) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def write_error(nr, e=" ", traceback="", soup="", user="", url="", url_name="", profile=""): |
|
|
|
def write_error(nr, profile, e=" ", traceback="", soup="", user="", url="", url_name=""): |
|
|
|
"""Skriver info efter error till arango |
|
|
|
"""Skriver info efter error till arango |
|
|
|
|
|
|
|
|
|
|
|
Args: |
|
|
|
Args: |
|
|
|
@ -45,19 +45,20 @@ def write_error(nr, e=" ", traceback="", soup="", user="", url="", url_name="", |
|
|
|
if url == "": |
|
|
|
if url == "": |
|
|
|
url = "ingen url" |
|
|
|
url = "ingen url" |
|
|
|
url_name = "ingen url" |
|
|
|
url_name = "ingen url" |
|
|
|
try: |
|
|
|
# try: |
|
|
|
# BARA VID FELSÖKNING |
|
|
|
# # BARA VID FELSÖKNING |
|
|
|
print(profile, user, e) |
|
|
|
# print(profile, user, e) |
|
|
|
print(profile, user, traceback.format_exc()) |
|
|
|
# print(profile, user, traceback.format_exc()) |
|
|
|
_print(profile, user, e) |
|
|
|
# _print(profile, user, e) |
|
|
|
_print(profile, user, traceback.format_exc()) |
|
|
|
# _print(profile, user, traceback.format_exc()) |
|
|
|
except Exception as e: |
|
|
|
# except Exception as e: |
|
|
|
print('Kunde inte skriva error print till databasen.') |
|
|
|
# print('Kunde inte skriva error print till databasen.') |
|
|
|
print(e) |
|
|
|
# print(e) |
|
|
|
if "e" not in locals(): |
|
|
|
if "e" not in locals(): |
|
|
|
e = 'Unknown error' |
|
|
|
e = 'Unknown error' |
|
|
|
|
|
|
|
|
|
|
|
doc = { |
|
|
|
doc = { |
|
|
|
"_key": f"{now()}_{profile.lookingup})", |
|
|
|
"_key": f"{now()}_{profile.container})", |
|
|
|
"number": nr, |
|
|
|
"number": nr, |
|
|
|
"error": nr, |
|
|
|
"error": nr, |
|
|
|
"user": str(user.username), |
|
|
|
"user": str(user.username), |
|
|
|
@ -90,7 +91,7 @@ def _print(profile, user, text, end='\n', silent=False, sleeptime=0): |
|
|
|
""" Write a "print" to the database (and prints in in the terminal) |
|
|
|
""" Write a "print" to the database (and prints in in the terminal) |
|
|
|
|
|
|
|
|
|
|
|
Args: |
|
|
|
Args: |
|
|
|
lookingup (string): the value of profile.lookingup, meaning the "original" user. |
|
|
|
container (string): the value of profile.container, meaning the "original" user. |
|
|
|
user (class): The user username currelntly beeing looked up. |
|
|
|
user (class): The user username currelntly beeing looked up. |
|
|
|
text (string): What should be written. |
|
|
|
text (string): What should be written. |
|
|
|
end (str, optional): The end value for print. Defaults to '\n'. |
|
|
|
end (str, optional): The end value for print. Defaults to '\n'. |
|
|
|
@ -116,7 +117,7 @@ def _print(profile, user, text, end='\n', silent=False, sleeptime=0): |
|
|
|
|
|
|
|
|
|
|
|
db.insert_document( |
|
|
|
db.insert_document( |
|
|
|
"prints", |
|
|
|
"prints", |
|
|
|
{'_key': profile.lookingup, 'print':{now(): to_print}}, |
|
|
|
{'_key': str(profile.container), 'print':{now(): to_print}}, |
|
|
|
overwrite_mode="update", |
|
|
|
overwrite_mode="update", |
|
|
|
silent=True, |
|
|
|
silent=True, |
|
|
|
) |
|
|
|
) |
|
|
|
|