summaryrefslogtreecommitdiff
path: root/binance-announcements-scraping-bot.py
diff options
context:
space:
mode:
authorEvgeny Zinoviev <me@ch1p.io>2021-09-18 16:33:05 +0300
committerEvgeny Zinoviev <me@ch1p.io>2021-09-18 16:33:05 +0300
commita1531068942af9b83e07eaebfe7b3ef98bc30dc4 (patch)
treee8562325dcd7ffeaaa741ae26a304ab5d7590eb6 /binance-announcements-scraping-bot.py
parented1bd774404b66b744ebe19dc2f63e15a36bb6d8 (diff)
fix markup parsing
Diffstat (limited to 'binance-announcements-scraping-bot.py')
-rwxr-xr-xbinance-announcements-scraping-bot.py23
1 files changed, 16 insertions, 7 deletions
diff --git a/binance-announcements-scraping-bot.py b/binance-announcements-scraping-bot.py
index 7809470..4d7d14a 100755
--- a/binance-announcements-scraping-bot.py
+++ b/binance-announcements-scraping-bot.py
@@ -1,9 +1,10 @@
#!/usr/bin/env python3
-import sys, traceback
+import traceback
from requests import get
from bs4 import BeautifulSoup
from ch1p import State, telegram_notify
from html import escape
+from argparse import ArgumentParser
def scrap_announcements():
@@ -23,10 +24,7 @@ def scrap_announcements():
}
for link in c.find_next('div').select('a[data-bn-type="link"]'):
- id = link.get('id')
- if id is None:
- continue
- if not link.get('id').startswith('supportList'):
+ if link.text.strip().lower() == 'view more':
continue
href = link.get('href')
@@ -47,6 +45,10 @@ def scrap_announcements():
if __name__ == '__main__':
+ parser = ArgumentParser()
+ parser.add_argument('--stdout', action='store_true')
+ args = parser.parse_args()
+
state = State(default=dict(urls=[]))
try:
blocks = []
@@ -66,7 +68,14 @@ if __name__ == '__main__':
if blocks:
message = '<b>Binance Announcements</b>\n\n'
message += '\n\n'.join(blocks)
- telegram_notify(text=message, parse_mode='HTML', disable_web_page_preview=True)
+
+ if args.stdout:
+ print(message)
+ else:
+ telegram_notify(text=message, parse_mode='HTML', disable_web_page_preview=True)
except:
- telegram_notify(text='error: ' + escape(traceback.format_exc()), parse_mode='HTML') \ No newline at end of file
+ if args.stdout:
+ traceback.print_exc()
+ else:
+ telegram_notify(text='error: ' + escape(traceback.format_exc()), parse_mode='HTML') \ No newline at end of file