add pushover notification
This commit is contained in:
26
scrap.py
26
scrap.py
@ -18,8 +18,24 @@ import threading
|
|||||||
import time
|
import time
|
||||||
import sys
|
import sys
|
||||||
import dateutil
|
import dateutil
|
||||||
|
import os
|
||||||
|
import requests
|
||||||
from datetime import date, timedelta
|
from datetime import date, timedelta
|
||||||
|
|
||||||
|
try:
|
||||||
|
token = os.environ["APP_TOKEN"]
|
||||||
|
user = os.environ["USER_KEY"]
|
||||||
|
except KeyError as e:
|
||||||
|
print(f"Missing environment variable: {e.args[0]}")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
pushover_req_data = {
|
||||||
|
"token": token,
|
||||||
|
"user": user,
|
||||||
|
"message": "",
|
||||||
|
}
|
||||||
|
print(pushover_req_data)
|
||||||
|
|
||||||
if(len(sys.argv) != 2):
|
if(len(sys.argv) != 2):
|
||||||
print("missing team id, usage :", sys.argv[0], "<project_id>")
|
print("missing team id, usage :", sys.argv[0], "<project_id>")
|
||||||
exit(1);
|
exit(1);
|
||||||
@ -33,8 +49,12 @@ while(True):
|
|||||||
res = connIntra.get_available_slot(getUrl)
|
res = connIntra.get_available_slot(getUrl)
|
||||||
for x in res:
|
for x in res:
|
||||||
if x["ids"] not in found:
|
if x["ids"] not in found:
|
||||||
start = dateutil.parser.isoparse(x["start"]).strftime("%d/%m %H:%M")
|
start = dateutil.parser.isoparse(x["start"]).strftime("%d/%m at %H:%M")
|
||||||
end = dateutil.parser.isoparse(x["end"]).strftime("%d/%m %H:%M")
|
end = dateutil.parser.isoparse(x["end"]).strftime("%d/%m at %H:%M")
|
||||||
print("\aslot found starting at", start, ",ending at", end);
|
text = "slot found starting " + start + " ,ending " + end;
|
||||||
|
pushover_req_data["message"] = text
|
||||||
|
response = requests.post("https://api.pushover.net/1/messages.json", data=pushover_req_data)
|
||||||
|
print("request sent", response.status_code, response.text)
|
||||||
|
print("\a" + text);
|
||||||
found.add(x["ids"])
|
found.add(x["ids"])
|
||||||
time.sleep(1);
|
time.sleep(1);
|
||||||
|
|||||||
Reference in New Issue
Block a user