diff options
author | Evgeny Zinoviev <me@ch1p.io> | 2022-03-16 16:31:39 +0300 |
---|---|---|
committer | Evgeny Zinoviev <me@ch1p.io> | 2022-03-16 16:31:39 +0300 |
commit | 35d86a39e2a23fee7d24a2b759c31c8712eb8ab7 (patch) | |
tree | 9ccd1e92c8e8aa411d6d4f7dc95dfecab12f5023 | |
parent | 2dd41e65a3ef9bf2f0060aa58b1e0f672ab440d7 (diff) |
update
-rw-r--r-- | mgs.py | 9 | ||||
-rw-r--r-- | requirements.txt | 2 | ||||
-rwxr-xr-x | telegram_notify.py | 23 |
3 files changed, 22 insertions, 12 deletions
@@ -1,4 +1,10 @@ -import requests, textract, re, os, tempfile, random, string +import requests +import textract +import re +import os +import tempfile +import random +import string from bs4 import BeautifulSoup from typing import List, Dict @@ -13,6 +19,7 @@ regex = r"""(?i)\b((?:https?:(?:/{1,3}|[a-z0-9%])|[a-z0-9.\-]+[.](?:com|net|org| def strgen(n: int) -> str: return ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(n)).lower() + def get_links(s: str) -> List[str]: return list(set(re.findall(regex, s))) diff --git a/requirements.txt b/requirements.txt index baac057..8f59782 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ requests~=2.25.1 textract~=1.6.3 beautifulsoup4~=4.8.0 -ch1p~=0.0.4
\ No newline at end of file +ch1p~=0.0.7
\ No newline at end of file diff --git a/telegram_notify.py b/telegram_notify.py index 9876740..da05994 100755 --- a/telegram_notify.py +++ b/telegram_notify.py @@ -24,13 +24,13 @@ if __name__ == '__main__': cases = mgs.get_cases() # read state - jst = State(file=args.state_file, default=dict(cases=[])) - data = jst.read() + state = State(file=args.state_file, + default=dict(cases=[])) # loop through cases results = [] for case in cases: - if case['statement_number'] in data['cases']: + if case['statement_number'] in state['cases']: continue matched = False @@ -38,19 +38,22 @@ if __name__ == '__main__': if mydomain in case['decision_text']: matched = True results.append('%s found in %s' % (mydomain, case['statement_number'])) - data['cases'].append(case['statement_number']) + state['cases'].append(case['statement_number']) if matched: break - # remember found cases - jst.write(data) - # if found anything, send to telegram if results: text = '\n'.join(results) - text = 'new mos-gorsud findings:\n' + text + text = 'new MGS findings:\n' + text - telegram_notify(text=escape(text), parse_mode='HTML', token=args.token, chat_id=args.chat_id) + telegram_notify(text=escape(text), + parse_mode='HTML', + token=args.token, + chat_id=args.chat_id) except: - telegram_notify(text='error: '+escape(traceback.format_exc()), parse_mode='HTML', token=args.token, chat_id=args.chat_id) + telegram_notify(text='error: '+escape(traceback.format_exc()), + parse_mode='HTML', + token=args.token, + chat_id=args.chat_id) |