summaryrefslogtreecommitdiff
path: root/telegram_notify.py
diff options
context:
space:
mode:
authorEvgeny Zinoviev <me@ch1p.io>2022-05-07 16:53:03 +0300
committerEvgeny Zinoviev <me@ch1p.io>2022-05-07 16:53:03 +0300
commit3bfca2f2fbabb72ffbda01e016fd53852eb3998e (patch)
treeca7fafb886e47e07a52c0092f490061245fdc2e4 /telegram_notify.py
parentd554e1c1c9ff6ae5b828dc4281208bb705dd350b (diff)
refactor a bitHEADmaster
Diffstat (limited to 'telegram_notify.py')
-rwxr-xr-xtelegram_notify.py43
1 files changed, 27 insertions, 16 deletions
diff --git a/telegram_notify.py b/telegram_notify.py
index a834b34..0ccb2b9 100755
--- a/telegram_notify.py
+++ b/telegram_notify.py
@@ -1,6 +1,9 @@
#!/usr/bin/env python3
import traceback
-from mgs import MGSPiracy
+import mosgorsud
+import requests
+import urllib3.exceptions
+
from argparse import ArgumentParser
from ch1p import State, telegram_notify
from html import escape
@@ -10,21 +13,24 @@ 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('--token', required=True,
+ help='Telegram bot token',)
+ parser.add_argument('--chat-id', type=int, required=True,
+ help='Telegram chat id (with bot)')
+ parser.add_argument('--from', type=int, default=1, dest='_from',
+ help='First page')
+ parser.add_argument('--to', type=int, default=5,
+ help='Last page')
parser.add_argument('--domains', nargs='+', required=True)
- args = parser.parse_args()
+ arg = parser.parse_args()
try:
# get recent cases
- mgs = MGSPiracy(from_page=args._from, to_page=args.to)
- cases = mgs.get_cases()
+ cases = mosgorsud.get_cases(from_page=arg._from, to_page=arg.to)
# read state
- state = State(file=args.state_file,
+ state = State(file=arg.state_file,
default=dict(cases=[]))
# loop through cases
@@ -34,10 +40,10 @@ if __name__ == '__main__':
continue
matched = False
- for mydomain in args.domains:
+ for mydomain in arg.domains:
if mydomain in case['decision_text']:
matched = True
- results.append('%s found in %s' % (mydomain, case['statement_number']))
+ results.append('%s found in %s (%s)' % (mydomain, case['statement_number'], case['doc_link']))
state['cases'].append(case['statement_number'])
if matched:
@@ -50,14 +56,19 @@ if __name__ == '__main__':
telegram_notify(text=escape(text),
parse_mode='HTML',
- token=args.token,
- chat_id=args.chat_id)
+ token=arg.token,
+ chat_id=arg.chat_id)
except KeyboardInterrupt:
pass
+ except (TimeoutError, requests.exceptions.ConnectionError, urllib3.exceptions.MaxRetryError):
+ telegram_notify(text='mosgorsud error: network timeout',
+ token=arg.token,
+ chat_id=arg.chat_id)
+
except:
- telegram_notify(text='error: '+escape(traceback.format_exc()),
+ telegram_notify(text='mosgorsud error: '+escape(traceback.format_exc()),
parse_mode='HTML',
- token=args.token,
- chat_id=args.chat_id)
+ token=arg.token,
+ chat_id=arg.chat_id)