From 1d003cf394231918cdd165cc256da17b1d1dcef0 Mon Sep 17 00:00:00 2001 From: Evgeny Zinoviev Date: Sun, 25 Apr 2021 23:59:51 +0300 Subject: initial --- vivaldi-update-checker.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 vivaldi-update-checker.py (limited to 'vivaldi-update-checker.py') diff --git a/vivaldi-update-checker.py b/vivaldi-update-checker.py new file mode 100644 index 0000000..b0053ee --- /dev/null +++ b/vivaldi-update-checker.py @@ -0,0 +1,41 @@ +import requests, re + +from packaging import version +from ch1p import State, telegram_notify +from bs4 import BeautifulSoup +from html import escape + + +class VersionNotFoundError(RuntimeError): pass + + +class VivaldiUpdateChecker: + def __init__(self): + pass + + def get(self): + r = requests.get('https://vivaldi.com/blog/') + soup = BeautifulSoup(r.text, 'html.parser') + links = soup.select('.download-vivaldi-sidebar a') + for link in links: + if link['href'] == 'https://vivaldi.com/download/': + return re.search(r'\((.*?)\)', link.get_text().strip()).group(1) + raise VersionNotFoundError("version not found") + + +if __name__ == '__main__': + state = State(default={'prev_version': '0.0'}) + + try: + checker = VivaldiUpdateChecker() + cur_version = checker.get() + + if version.parse(state['prev_version']) < version.parse(cur_version): + message = 'New Vivaldi version: %s. Download here: https://vivaldi.com/download/' % (cur_version) + state['prev_version'] = cur_version + telegram_notify(text=message, parse_mode='HTML') + + except VersionNotFoundError: + print('version not found') + pass + -- cgit v1.2.3