|
|
|
@ -1,6 +1,7 @@ |
|
|
|
from datetime import datetime |
|
|
|
from datetime import datetime |
|
|
|
from getpass import getpass |
|
|
|
from getpass import getpass |
|
|
|
from time import sleep |
|
|
|
from time import sleep |
|
|
|
|
|
|
|
import json |
|
|
|
|
|
|
|
|
|
|
|
import nacl.secret |
|
|
|
import nacl.secret |
|
|
|
import nacl.utils |
|
|
|
import nacl.utils |
|
|
|
@ -21,6 +22,29 @@ def checked_members(): |
|
|
|
return members_checked |
|
|
|
return members_checked |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def count_docs(col): |
|
|
|
|
|
|
|
cursor = db.aql.execute( |
|
|
|
|
|
|
|
""" |
|
|
|
|
|
|
|
FOR doc IN @@col |
|
|
|
|
|
|
|
COLLECT WITH COUNT INTO length |
|
|
|
|
|
|
|
RETURN length |
|
|
|
|
|
|
|
""", |
|
|
|
|
|
|
|
bind_vars={"@col": col} |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
return cursor.next() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def write_report(users, pictures): |
|
|
|
|
|
|
|
now = datetime.now().strftime("%Y-%m-%d %H:%M:%S") |
|
|
|
|
|
|
|
db.insert_document({ |
|
|
|
|
|
|
|
'_id':f'reports/{now}', |
|
|
|
|
|
|
|
'users': [user.username for user in users], |
|
|
|
|
|
|
|
'members': count_docs('members'), |
|
|
|
|
|
|
|
'total_picture_reactions':count_docs('picture_reactions'), |
|
|
|
|
|
|
|
'pictures':count_docs('pictures'), |
|
|
|
|
|
|
|
'new_pictures': pictures |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_profile(): |
|
|
|
def get_profile(): |
|
|
|
""" Hämtar profil om det inte gjorts förut """ |
|
|
|
""" Hämtar profil om det inte gjorts förut """ |
|
|
|
cursor = db.aql.execute( |
|
|
|
cursor = db.aql.execute( |
|
|
|
@ -74,4 +98,21 @@ for i in range(0, 6, 1): |
|
|
|
sleep(1) |
|
|
|
sleep(1) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def backup(db): |
|
|
|
|
|
|
|
"""Skapar en json-backup för specificerade collections. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Args: |
|
|
|
|
|
|
|
db: databaskoppling till aktuell databas |
|
|
|
|
|
|
|
""" |
|
|
|
|
|
|
|
d = {} |
|
|
|
|
|
|
|
for col in ['members', 'pictures', 'picture_reactions', 'profiles']: |
|
|
|
|
|
|
|
l = [] |
|
|
|
|
|
|
|
for doc in db.collection(col).all(): |
|
|
|
|
|
|
|
l.append(doc) |
|
|
|
|
|
|
|
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")}') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db = ArangoClient(hosts=host_arango).db(db_arango, username=user_arango, password=pwd) |
|
|
|
db = ArangoClient(hosts=host_arango).db(db_arango, username=user_arango, password=pwd) |
|
|
|
|