|
|
|
|
@ -1,4 +1,3 @@ |
|
|
|
|
from datetime import datetime |
|
|
|
|
from getpass import getpass |
|
|
|
|
from time import sleep |
|
|
|
|
import json |
|
|
|
|
@ -9,6 +8,32 @@ from arango import ArangoClient |
|
|
|
|
|
|
|
|
|
from config import * |
|
|
|
|
|
|
|
|
|
# Starta koppling till arangodb |
|
|
|
|
# Avkryptera lösen till arango |
|
|
|
|
try: |
|
|
|
|
# Om scriptet körs på Macbook finns löseordet i en fil |
|
|
|
|
with open('password_arango.txt') as f: |
|
|
|
|
pwd = f.readline() |
|
|
|
|
except FileNotFoundError: |
|
|
|
|
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) |
|
|
|
|
|
|
|
|
|
from helpers import now |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def checked_members(): |
|
|
|
|
cursor = db.aql.execute( |
|
|
|
|
@ -33,10 +58,17 @@ def count_docs(col): |
|
|
|
|
) |
|
|
|
|
return cursor.next() |
|
|
|
|
|
|
|
|
|
def report_blocked(profile, users): |
|
|
|
|
db.insert_document({ |
|
|
|
|
'_id':f'reports/{now()}', |
|
|
|
|
'profile': profile.name, |
|
|
|
|
'users': [user.username for user in users], |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def write_report(users, pictures): |
|
|
|
|
now = datetime.now().strftime("%Y-%m-%d %H:%M:%S") |
|
|
|
|
db.insert_document({ |
|
|
|
|
'_id':f'reports/{now}', |
|
|
|
|
'_id':f'reports/{now()}', |
|
|
|
|
'users': [user.username for user in users], |
|
|
|
|
'members': count_docs('members'), |
|
|
|
|
'total_picture_reactions':count_docs('picture_reactions'), |
|
|
|
|
@ -74,30 +106,10 @@ def friends_of_user(user): |
|
|
|
|
|
|
|
|
|
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") |
|
|
|
|
_print(profile.name, f'{profile.name} blockerad och borttagen {now()}.' |
|
|
|
|
) |
|
|
|
|
break |
|
|
|
|
except: |
|
|
|
|
print("Fel lösenord.") |
|
|
|
|
sleep(1) |
|
|
|
|
|
|
|
|
|
# TODO #2 Bättre funktion för backup av databasen |
|
|
|
|
|
|
|
|
|
def backup(db): |
|
|
|
|
"""Skapar en json-backup för specificerade collections. |
|
|
|
|
@ -113,7 +125,7 @@ def backup(db): |
|
|
|
|
d[col] = l |
|
|
|
|
with open('data/backup.json', 'w') as f: |
|
|
|
|
json.dump(d, f) |
|
|
|
|
print(f'Senaste backup: {datetime.now().strftime("%Y-%m-%d %H:%M:%S")}') |
|
|
|
|
print(f'Senaste backup: {now()}') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db = ArangoClient(hosts=host_arango).db(db_arango, username=user_arango, password=pwd) |
|
|
|
|
|