From 36f59a3a84009e471357119857243a6c2577bc4c Mon Sep 17 00:00:00 2001 From: Evgeny Zinoviev Date: Tue, 20 Apr 2021 00:42:06 +0300 Subject: udpate --- telegram_notify.py | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 telegram_notify.py (limited to 'telegram_notify.py') diff --git a/telegram_notify.py b/telegram_notify.py new file mode 100644 index 0000000..427659c --- /dev/null +++ b/telegram_notify.py @@ -0,0 +1,50 @@ +import requests +from mgs import MGSPiracy +from argparse import ArgumentParser +from jstate import JState + +if __name__ == '__main__': + # parse arguments + parser = ArgumentParser() + parser.add_argument('--state-file', required=True) + parser.add_argument('--token', help='Telegram bot token', required=True) + parser.add_argument('--chat-id', type=int, help='Telegram chat id (with bot)', required=True) + parser.add_argument('--from', type=int, default=1, help='First page', dest='_from') + parser.add_argument('--to', type=int, default=5, help='Last page') + parser.add_argument('--domains', nargs='+', required=True) + args = parser.parse_args() + + # get recent cases + mgs = MGSPiracy(from_page=args._from, to_page=args.to) + cases = mgs.get_cases() + + # read state + jst = JState(args.state_file, default=dict(cases=[])) + data = jst.read() + + # loop through cases + results = [] + for case in cases: + if case['statement_number'] in data['cases']: + continue + + matched = False + for mydomain in args.domains: + if mydomain in case['decision_text']: + matched = True + results.append('%s found in %s' % (mydomain, case['statement_number'])) + data['cases'].append(case['statement_number']) + + if matched: + break + + # remember found cases + jst.write(data) + + # if found anything, send to telegram + if results: + text = 'new mos-gorsud findings:\n'.join(results) + r = requests.post('https://api.telegram.org/bot%s/sendMessage' % args.token, data={ + 'chat_id': args.chat_id, + 'text': text + }) \ No newline at end of file -- cgit v1.2.3