Changes to _print(), container etc

pull/5/head
Lasse Edfast 5 years ago
parent 9ffc8b017c
commit 388e8c71e9
  1. 31
      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,
)

Loading…
Cancel
Save