Last active
March 29, 2021 07:57
-
-
Save GluTbl/7980cbd986ac2d3b37bf5b699562900e to your computer and use it in GitHub Desktop.
[Website Update Checker] Detect any change in website
This file contains hidden or 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
from time import sleep | |
import playsound | |
import requests | |
old = b"" | |
filestring = "old_data_request.txt" | |
def getRequest(): | |
url = 'http://www.google.com/' #Make sure changing this html file get some update | |
r = requests.get(url) | |
return r | |
def playAlert(): | |
print("Ring") | |
playsound.playsound("./alarmsound.mp3", True) | |
pass | |
def readbyte(fileloc: str): | |
in_file = open(fileloc, "rb") # opening for [r]eading as [b]inary | |
data = in_file.read() # if you only wanted to read 512 bytes, do .read(512) | |
in_file.close() | |
return data | |
playAlert() | |
istherechange = False | |
from pathlib import Path | |
my_file = Path(filestring) | |
if my_file.is_file(): | |
old = readbyte(filestring) | |
else: | |
try: | |
print("Requesting for fresh....") | |
req = getRequest() | |
if (req.status_code == 200): | |
with open(filestring, 'wb') as the_file: | |
the_file.write(req.content) | |
the_file.close() | |
old = readbyte(filestring) | |
else: | |
print("Error 101") | |
exit() | |
except : | |
willcheck = False | |
print("Error 102") | |
exit() | |
while (True): | |
willcheck = False | |
newtext = b"" | |
if len(old) == 0: | |
print("old is empty!!!") | |
exit() | |
else: | |
try: | |
newreq = getRequest() | |
if newreq.status_code == 200: | |
willcheck = True | |
newtext = newreq.content | |
else: | |
willcheck = False | |
print("Error 103") | |
except: | |
willcheck = False | |
print("Error 104") | |
if willcheck: | |
if old == newtext: | |
print("No Update") | |
print("Old:-->" + str(len(old))) | |
print("New:-->" + str(len(newtext))) | |
else: | |
print("Some new update") | |
istherechange = True | |
if (istherechange): | |
break | |
sleep(10) | |
while True: | |
playAlert() | |
print("Some new update") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment