-
Notifications
You must be signed in to change notification settings - Fork 9
/
statistics
executable file
·73 lines (61 loc) · 2.19 KB
/
statistics
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/python3
'''Helper for tweeting bot statistics'''
import argparse
import configparser
import datetime
import logging
from Externals import setup_database, set_arguments, setup_network, test_network_arguments
import Persistence
logger = Persistence.init_logger('statistics')
one_day = datetime.timedelta(days=1)
today = datetime.date.today()
first = today.replace(day=1)
january_first = first.replace(month=1)
parser = argparse.ArgumentParser(description=__doc__)
set_arguments(parser)
Persistence.set_logging_args(parser, 'INFO')
parser.add_argument('--since',
dest='since',
help='Time frame for statistics',
required=False,
choices=['0', 'month', 'year'],
default=0)
args = parser.parse_args()
configuration = configparser.ConfigParser()
configuration.read(args.config)
args.config = configuration
network = test_network_arguments(args)
logger.setLevel(getattr(logging, args.log_level))
logger.debug("statistics running args: %s", args)
if args.since == "0":
since = 0
since_text = 'Beginn'
elif args.since == 'month':
since = (first - one_day).strftime("%Y%m01")
since_text = 'Anfang letzten Monats'
elif args.since == 'year':
since = (january_first - one_day).strftime("%Y0101")
since_text = 'Anfang letzten Jahres'
sql = setup_database(args, network)
counts = sql.count_status(since=since)
text = f"""Zeit für Statistik! Daten für die Zeit seit {since_text}. Ich habe:
• {counts.get('found', 0)} Kürzel beantwortet, für
• {counts.get('notfound', 0)} Kürzel keine lange Version erkannt und
• {counts.get('blacklist', 0)} nicht beantwortet, weil sie auf der Blacklist standen.
Die populärsten Kürzel waren:
"""
for row in sql.popular_abbrs(since):
text += f"• {row['S']} ({row['C']}×)\n\u200b"
text += """
Die populärsten Quellen waren:
"""
for row in sql.popular_sources(since):
text += f"• {row['S']} ({row['C']}×)\n\u200b"
text += """
(Keine Garantie für richtiges Zählen)"""
print(text.replace("\u200b", ""))
if args.readwrite:
nw_api = setup_network(network, args, {})
nw_api.post(text)
else:
logger.info("Readonly: not really sending that status.")