Last active
December 20, 2021 08:28
-
-
Save salvah22/07fe98657e28d5b89f02f45188f76614 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
S1: https://www.crummy.com/software/BeautifulSoup/ | |
S2: https://stackoverflow.com/questions/2610395/python-script-to-check-website-for-a-tag | |
""" | |
import os, time | |
from urllib.request import urlopen | |
from bs4 import BeautifulSoup | |
def soup_search(soup): | |
for (index, value) in enumerate((x for x in str(soup).splitlines() if x != ""), start=1,): | |
# ebynerate(###) removes all the empty lines, so that they shouldn't be part of the line count: | |
# Specify the tag you want to find | |
# If the tag is found, it will return `1`, else `-1` | |
if value.find('<a href="https://windscribe.com">') != -1: | |
print(f"Line: {index}.\t Found: '{value}' ") | |
a1 = value.split(' </a>') | |
a2 = a1[0].split('"> v') | |
break | |
return a2[1] | |
def main(webpage): | |
page = urlopen(webpage) | |
#soup = BeautifulSoup(page, "lxml") | |
soup = BeautifulSoup(page, "html.parser") | |
windscribe_version = soup_search(soup) | |
#os.chdir(os.path.dirname(__file__)) | |
os.chdir('~/proyectos/python/') | |
fn = 'windscribe_current_version.txt' | |
if os.path.exists('windscribe_current_version.txt'): | |
with open(fn, 'r') as f1: | |
current_version = f1.read().rstrip('\n') | |
else: | |
with open(fn, 'w') as f1: | |
f1.write(f'{windscribe_version}') | |
print('windscribe_current_version.txt updated') | |
current_version = windscribe_version | |
if windscribe_version != current_version: | |
os.system(f'notify-send "Windscribe updated from {current_version} to {windscribe_version}" --app-name="Windscribe Version Check" -t 3000') | |
with open(fn, 'w') as f1: | |
f1.write(f'{windscribe_version}') | |
print('windscribe_current_version.txt updated') | |
os.chdir('~/') | |
with open('NEW_WINDSCRIBE_VERSION_FOUND', 'w') as f1: | |
f1.write('aaa') | |
else: print('no new version found') | |
if __name__ == '__main__': | |
time.sleep(30) | |
main("https://windscribe.com/changelog/linux") | |
os.system(f'notify-send "done checking windscribe version" --app-name="Windscribe Version Check"') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment