-
Notifications
You must be signed in to change notification settings - Fork 0
/
monitor.py
executable file
·47 lines (37 loc) · 1.05 KB
/
monitor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import time
import logging
import subprocess
import traceback
from datetime import datetime, timedelta
from config.constants import *
from utils.db import Db
SECOND = 1
MINUTE = 60*SECOND
HOUR = 60*MINUTE
MSG="""\
\N{ROBOT FACE} Downloading the full #StackOverflow history from the @waybackmachine for {duration} now
At this point I have read {fcount} files
"""
def timedelta_format(td):
d = td.days
s = td.seconds
h, s = divmod(s, HOUR)
m, s = divmod(s, MINUTE)
return "{} days, {} hours and {} minutes".format(d, h, m)
db = Db(DB_URI, timeout=DB_TIMEOUT)
while True:
try:
orig = datetime(2020, 2, 1, 4, 17)
delta = datetime.today() - orig
ts = timedelta_format(delta)
fcount = db.fcount()
msg = MSG.format(duration=ts, fcount=fcount)
print()
print(msg)
TWEET_CMD=['t', 'update', 'XXXX']
TWEET_CMD[-1] = msg
subprocess.run(TWEET_CMD)
except Exception as e:
logging.error(traceback.format_exc())
finally:
time.sleep(16*HOUR)