From 388e8c71e99a991ad5a17405ff55766371fc6ea9 Mon Sep 17 00:00:00 2001 From: Lasse Date: Wed, 28 Apr 2021 14:23:19 +0200 Subject: [PATCH] Changes to _print(), container etc --- facebook/helpers.py | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/facebook/helpers.py b/facebook/helpers.py index c27d960..68af4b0 100644 --- a/facebook/helpers.py +++ b/facebook/helpers.py @@ -22,13 +22,13 @@ def sleep_(t): sleep(random.randrange(0, 10, 1) / 4) # TODO #1 spara cookies till db -def update_cookie(cookies, profile_name): +def update_cookie(cookies, profile): """ 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) -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 Args: @@ -45,19 +45,20 @@ def write_error(nr, e=" ", traceback="", soup="", user="", url="", url_name="", if url == "": url = "ingen url" url_name = "ingen url" - 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) + # 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.lookingup})", + "_key": f"{now()}_{profile.container})", "number": nr, "error": nr, "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) 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. text (string): What should be written. 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( "prints", - {'_key': profile.lookingup, 'print':{now(): to_print}}, + {'_key': str(profile.container), 'print':{now(): to_print}}, overwrite_mode="update", silent=True, )