master
parent
64eb32245b
commit
91046da67f
4 changed files with 108 additions and 2 deletions
@ -0,0 +1,13 @@ |
|||||||
|
FROM python:alpine |
||||||
|
|
||||||
|
WORKDIR / |
||||||
|
|
||||||
|
COPY requirements.txt . |
||||||
|
|
||||||
|
RUN pip install -r requirements.txt |
||||||
|
|
||||||
|
ADD docker/stats/. . |
||||||
|
|
||||||
|
ENTRYPOINT [ "python", "facebook/mrkoll.py" ] |
||||||
|
|
||||||
|
# docker buildx build --file docker/stats/Dockerfile --platform linux/arm64,linux/amd64 -t mrkoll . |
||||||
@ -0,0 +1,27 @@ |
|||||||
|
black==21.8b0 |
||||||
|
certifi==2020.6.20 |
||||||
|
chardet==4.0.0 |
||||||
|
click==8.0.1 |
||||||
|
httplib2==0.18.1 |
||||||
|
idna==2.10 |
||||||
|
mypy-extensions==0.4.3 |
||||||
|
packaging==21.0 |
||||||
|
pathspec==0.9.0 |
||||||
|
platformdirs==2.3.0 |
||||||
|
pycurl==7.43.0.6 |
||||||
|
PyJWT==2.1.0 |
||||||
|
pyparsing==2.4.7 |
||||||
|
PySimpleSOAP==1.16.2 |
||||||
|
python-apt==2.2.1 |
||||||
|
python-arango==7.2.0 |
||||||
|
python-debian==0.1.39 |
||||||
|
python-debianbts==3.1.0 |
||||||
|
regex==2021.8.28 |
||||||
|
reportbug==7.10.3 |
||||||
|
requests==2.25.1 |
||||||
|
requests-toolbelt==0.9.1 |
||||||
|
setuptools-scm==6.3.1 |
||||||
|
six==1.16.0 |
||||||
|
tomli==1.2.1 |
||||||
|
typing-extensions==3.10.0.2 |
||||||
|
urllib3==1.26.5 |
||||||
@ -0,0 +1,66 @@ |
|||||||
|
from datetime import datetime |
||||||
|
from getpass import getpass |
||||||
|
from time import sleep |
||||||
|
|
||||||
|
from arango import ArangoClient |
||||||
|
|
||||||
|
|
||||||
|
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_webshare |
||||||
|
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) |
||||||
|
|
||||||
|
# Sov för att fortsätta senare |
||||||
|
if continuous: |
||||||
|
print(now()) |
||||||
|
sleep(86400) |
||||||
|
else: |
||||||
|
break |
||||||
|
|
||||||
|
|
||||||
|
# Info för arangodb |
||||||
|
user_arango = "Stats" |
||||||
|
db_arango = "facebook" |
||||||
|
host_arango = "http://192.168.1.10: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) |
||||||
Loading…
Reference in new issue