53 lines
1.5 KiB
Python
53 lines
1.5 KiB
Python
#!/usr/bin/env python3
|
|
|
|
import configparser
|
|
import urllib.request
|
|
|
|
import telegram
|
|
|
|
def check_availability():
|
|
request = urllib.request.Request(
|
|
url="https://manage.edis.at/whmcs/cart.php?a=add&pid=976",
|
|
headers={"user-agent": "Edis Availability Check (https://kumig.it/kumitterer/edis-availability-check/)"}
|
|
)
|
|
|
|
response = urllib.request.urlopen(request).read().decode()
|
|
|
|
if "Oops, there's a problem" in response:
|
|
return False
|
|
|
|
return True
|
|
|
|
def notify(text, token, recipients):
|
|
bot = telegram.Bot(token.split()[0])
|
|
|
|
for recipient in recipients.split():
|
|
if recipient == "#":
|
|
break
|
|
|
|
try:
|
|
bot.send_message(recipient, text)
|
|
print("Notified recipient %s" % recipient)
|
|
except:
|
|
print("Could not notify recipient %s" % recipient)
|
|
|
|
def main():
|
|
config = configparser.ConfigParser()
|
|
config.read("settings.ini")
|
|
|
|
available = check_availability()
|
|
|
|
if available and not config.getboolean("STATUS", "Notified"):
|
|
notify("HP DL320 Graz is available now!", config["TELEGRAM"]["Token"], config["TELEGRAM"]["Recipients"])
|
|
config["STATUS"]["Notified"] = "yes"
|
|
elif config.getboolean("STATUS", "Notified") and not available:
|
|
notify("HP DL320 Graz is no longer available!", config["TELEGRAM"]["Token"], config["TELEGRAM"]["Recipients"])
|
|
config["STATUS"]["Notified"] = "no"
|
|
else:
|
|
return
|
|
|
|
with open("settings.ini", "w") as configfile:
|
|
config.write(configfile)
|
|
|
|
if __name__ == "__main__":
|
|
main() |