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.
74 lines
1.9 KiB
74 lines
1.9 KiB
from datetime import datetime |
|
from getpass import getpass |
|
from time import sleep |
|
|
|
from arango import ArangoClient |
|
from json2html import json2html |
|
|
|
|
|
def now(): |
|
""" Returns current date and time as string""" |
|
return datetime.now().strftime("%Y-%m-%d_%H:%M:%S") |
|
|
|
def write_stats(db, continuous=False): |
|
while True: |
|
d = {} |
|
for col in db.collections(): |
|
if not col['system']: |
|
d[col['name']] = db.collection(col['name']).count() |
|
del d['stats'] |
|
#d['time'] = now() |
|
cursor = db.aql.execute( |
|
""" |
|
FOR doc IN members |
|
FILTER doc.checked == true |
|
COLLECT WITH COUNT INTO length |
|
RETURN length |
|
""" |
|
) |
|
d['checked_members'] = cursor.next() |
|
|
|
|
|
# Hur många konton per säljare som finns kvar |
|
cursor = db.aql.execute( |
|
''' |
|
for doc in profiles |
|
filter has(doc, "vendor") |
|
COLLECT vendor = doc.vendor WITH COUNT INTO length |
|
RETURN { |
|
"vendor" : vendor, |
|
"active" : length |
|
} |
|
''') |
|
d['active_vendors'] = [doc for doc in cursor] |
|
|
|
d['_key'] = now()[:13] |
|
db.insert_document( "stats", d, overwrite=True) |
|
|
|
# Skriv en html-fil |
|
with open('website/fb-webbapp/stats.html', 'a+') as html: |
|
html.truncate(0) |
|
html.write('<!DOCTYPE html> <br>') |
|
|
|
html.write(json2html.convert(json = d)) |
|
|
|
# Sov för att fortsätta senare |
|
if continuous: |
|
sleep(86400) |
|
else: |
|
break |
|
|
|
# Info för arangodb |
|
user_arango = "Stats" |
|
db_arango = "facebook" |
|
host_arango = "http://192.168.0.4:8529" |
|
|
|
# Starta koppling till arangodb |
|
# Avkryptera lösen till arango |
|
pwd = getpass(f'Arangolösenord för {user_arango}:').strip() |
|
|
|
db = ArangoClient(hosts=host_arango).db( |
|
db_arango, username=user_arango, password=pwd |
|
) |
|
|
|
write_stats(db, continuous=True)
|
|
|