-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscripts.py
More file actions
89 lines (77 loc) · 2.44 KB
/
scripts.py
File metadata and controls
89 lines (77 loc) · 2.44 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import argparse
from datetime import date
from telegram.database import PgDatabase
from telegram.scripts import activity_over_time, export, inactive_users
def parse_args():
# Top level parser
parser = argparse.ArgumentParser(
description="Analysis of collected Telegram data (chats, messages, and media)"
)
subparsers = parser.add_subparsers(dest="commands")
# Parser options for activity_over_time
parser_aot = subparsers.add_parser(
"activity-over-time",
help="plots activity over time for collected data",
)
parser_aot.add_argument(
"--dialog-id",
type=int,
help="specify dialog to analyze. If not provided, all dialogs will be analyzed",
)
parser_aot.add_argument(
"--min-date",
type=date.fromisoformat,
default=date(2020, 1, 1),
help="lower bound of date interval to analyze (YYYY-MM-DD)",
)
parser_aot.add_argument(
"--max-date",
type=date.fromisoformat,
default=date.today(),
help="upper bound of date interval to analyze (YYYY-MM-DD)",
)
# Parser options for inactive_users
parser_iu = subparsers.add_parser(
"inactive-users",
help="finds percentage of users in a chat that have sent less than n messages",
)
parser_iu.add_argument(
"--dialog-id",
type=int,
required=True,
help="specify dialog to analyze",
)
parser_iu.add_argument(
"--min-messages",
type=int,
default=3,
help="minumum number of messages to consider a user active",
)
# Parser options for export
parser_ex = subparsers.add_parser("export", help="export postgres database as file")
parser_ex.add_argument(
"--dest-file",
type=str,
default="backup.sql",
help="destination file for exported database",
)
parser_ex.add_argument(
"--compress", action="store_true", help="compress destination file"
)
return parser.parse_args()
def main():
"""
The main telegram-bot analysis program. Runs several small scripts that
provide useful insights in collected data.
"""
args = parse_args()
db = PgDatabase()
match args.commands:
case "activity-over-time":
activity_over_time(args, db)
case "inactive-users":
inactive_users(args, db)
case "export":
export(args)
if __name__ == "__main__":
main()