Initial commit
This commit is contained in:
commit
98bdca71cd
4 changed files with 66 additions and 0 deletions
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
settings.ini
|
||||
venv/
|
||||
.vscode
|
53
check.py
Normal file
53
check.py
Normal file
|
@ -0,0 +1,53 @@
|
|||
#!/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()
|
1
requirements.txt
Normal file
1
requirements.txt
Normal file
|
@ -0,0 +1 @@
|
|||
python-telegram-bot
|
9
settings.dist.ini
Normal file
9
settings.dist.ini
Normal file
|
@ -0,0 +1,9 @@
|
|||
[TELEGRAM]
|
||||
token = INSERT_TOKEN_HERE # Your Telegram bot's token
|
||||
recipients = 1234567 7654321 # Telegram chat IDs to notify, separated by spaces
|
||||
|
||||
# No changes beyond this point
|
||||
|
||||
[STATUS]
|
||||
notified = no
|
||||
|
Loading…
Reference in a new issue