You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
77 lines
1.8 KiB
77 lines
1.8 KiB
from datetime import datetime |
|
from getpass import getpass |
|
from time import sleep |
|
|
|
import nacl.secret |
|
import nacl.utils |
|
from arango import ArangoClient |
|
|
|
from config import * |
|
|
|
|
|
def checked_members(): |
|
cursor = db.aql.execute( |
|
""" |
|
FOR doc IN members |
|
FILTER doc.checked == true |
|
RETURN doc._key |
|
""" |
|
) |
|
members_checked = set([doc for doc in cursor]) |
|
return members_checked |
|
|
|
|
|
def get_profile(): |
|
""" Hämtar profil om det inte gjorts förut """ |
|
cursor = db.aql.execute( |
|
""" |
|
FOR doc IN profiles |
|
FILTER doc.in_use == false |
|
FILTER doc.created == true |
|
RETURN doc |
|
""" |
|
) |
|
return cursor.next() |
|
|
|
|
|
def friends_of_user(user): |
|
"""Returnernar användare som reagerat på user:s bilder""" |
|
cursor = db.aql.execute( |
|
""" |
|
FOR doc IN picture_reactions |
|
FILTER doc._to == @user |
|
RETURN DISTINCT doc._from |
|
""", |
|
bind_vars={"user": "members/" + user}, |
|
) |
|
return [doc[8:] for doc in cursor] |
|
|
|
|
|
def remove_profile(profile): |
|
db.collection("profiles").delete(profile['_key'], silent=True, ignore_missing=True) |
|
print( |
|
f'{profile} blockerad och borttagen {datetime.now().strftime("%Y%m%d_%H:%M:%S")}.' |
|
) |
|
|
|
# TODO #2 Funktion för backup av databasen |
|
|
|
|
|
# Starta koppling till arangodb |
|
# Avkryptera lösen till arango |
|
for i in range(0, 6, 1): |
|
if i == 5: |
|
exit() |
|
try: |
|
key = "sssladnnklja" + getpass() |
|
pwd = ( |
|
nacl.secret.SecretBox(key.encode()) |
|
.decrypt(pwd_arango, encoder=nacl.encoding.HexEncoder) |
|
.decode("utf-8") |
|
) |
|
break |
|
except: |
|
print("Fel lösenord.") |
|
sleep(1) |
|
|
|
|
|
db = ArangoClient(hosts=host_arango).db(db_arango, username=user_arango, password=pwd)
|
|
|