Added _print()

pull/5/head
Lasse Edfast 5 years ago
parent c536eb80c0
commit 2569dfca7f
  1. 40
      facebook/helpers.py

@ -28,7 +28,7 @@ def update_cookie(cookies, profile_name):
pickle.dump(cookies, f) pickle.dump(cookies, f)
def write_error(nr, e="", traceback="", soup="", user="", url="", url_name=""): def write_error(nr, e="", traceback="", soup="", user="", url="", url_name="", profile=""):
"""Skriver info efter error till arango """Skriver info efter error till arango
Args: Args:
@ -45,14 +45,15 @@ def write_error(nr, e="", traceback="", soup="", user="", url="", url_name=""):
url = "ingen url" url = "ingen url"
url_name = "ingen url" url_name = "ingen url"
print(e) # FELSÖKNING # BARA VID FELSÖKNING
_print(profile.container, e)
_print(profile.container, traceback)
key = datetime.now().strftime("%Y%m%d_%H:%M:%S")
doc = { doc = {
"_key": key, "_key": f"{now()}_{profile.container})",
"number": nr, "number": nr,
"error": nr, "error": nr,
"user": str(user), "user": str(user.username),
"error": str(e), "error": str(e),
"url": str(url), "url": str(url),
"url_name": url_name, "url_name": url_name,
@ -68,5 +69,32 @@ def write_error(nr, e="", traceback="", soup="", user="", url="", url_name=""):
silent=True, silent=True,
) )
except Exception as e: except Exception as e:
print(e) _print(profile.container, 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):
""" Write a "print" to the database (and prints in in the terminal)
Args:
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'.
silent (bool, optional): If a print should be done in the terminal. Defaults to False.
"""
if silent == False:
print(text, end=end)
if user != '':
user = f"{user} - "
db.insert_document(
"prints",
{'_key': container, 'print':{now(): f"{user}{text.strip()}"}},
overwrite_mode="update",
silent=True,
merge=True
)
Loading…
Cancel
Save