Last active
September 26, 2023 13:36
-
-
Save RickDB/bd511654c5543102dd0ff90fd550af89 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
import http.client | |
import json | |
import os.path | |
import requests | |
import re | |
import urllib | |
# Vul hier Megekko Order ID in | |
orderId = "" | |
# Vul hier je postcode in | |
postcalCode = "" | |
# Indien je een notificatie wilt ontvangen via Pushbullet vul hier dan je access token in | |
# https://www.pushbullet.com/#settings | |
pushbulletAccessToken = "" | |
# Indien je een notificatie wilt ontvangen via Pushover vul hier dan je user token en app api token in | |
# https://pushover.net/ | |
pushoverUserKey = "" | |
pushoverAppApiToken = "" | |
# Indien je een notificatie wilt ontvangen via Gotify vul hier dan je url en app api token in | |
# https://gotify.net/ | |
gotifyUrl = "" | |
gotifyApiToken = "" | |
# Indien je altijd een push notificatie wilt sturen ook bij ongewijzigde wachtrij status zet onderstaand dan op True | |
alwaysSendNotication = False | |
# Hieronder verder niets aanpassen | |
queueUrl = "https://www.megekko.nl/scripts/wachtrij/wachtrij.php" | |
regexOrderData = r"(?=(Artikel|Artikelnr|Jouw positie:)<.+?<div.+?>(.+?)<)" | |
status = '' | |
if os.path.isfile("status.txt"): | |
f = open("status.txt", "r") | |
status = f.readline() | |
f.close() | |
def start(): | |
data = {'ajax': 'lookup', 'orderid': orderId, 'postcode': postcalCode} | |
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:83.0) Gecko/20100101 Firefox/83.0', 'referer': 'https://www.megekko.nl/info/RTX-3080'} | |
response = requests.post(queueUrl, data=data, headers=headers) | |
#print(response) | |
result = response.text | |
#print(type(result)) | |
#print(result) | |
pattern = re.compile('(?=(?P<key>Artikel|Artikelnr|Jouw positie:)<.+?<div.+?>(?P<value>.+?)<)', re.DOTALL | re.IGNORECASE) | |
artikelNr = '' | |
artikel = '' | |
positie = '' | |
data = {m['key']: m['value'] for m in pattern.finditer(result)} | |
if data['Artikelnr']: | |
artikelNr = data['Artikelnr'] | |
if data['Artikel']: | |
artikel = data['Artikel'] | |
if data['Jouw positie:']: | |
positie = data['Jouw positie:'] | |
print('Artikel nr. : %s' % (artikelNr)) | |
print('Artikel: %s' % (artikel)) | |
print('Positie: %s' % (positie)) | |
if status != positie: | |
f = open("status.txt", "w") | |
f.write(positie) | |
f.close() | |
if pushbulletAccessToken != '': | |
if status != positie or alwaysSendNotication: | |
title = 'Megekko wachtrij positie: %s' % (positie) | |
body = '%s \nPositie: %s' % (artikel, positie) | |
send_notification_via_pushbullet(title, body) | |
if pushoverUserKey != '' and pushoverAppApiToken != '': | |
if status != positie or alwaysSendNotication: | |
body = '%s \nPositie: %s' % (artikel, positie) | |
send_notification_via_pushover(body) | |
if gotifyUrl != '' and gotifyApiToken != '': | |
if status != positie or alwaysSendNotication: | |
title = 'Megekko wachtrij positie: %s' % (positie) | |
body = '%s \nPositie: %s' % (artikel, positie) | |
send_notification_via_gotify(title, body) | |
def send_notification_via_pushbullet(title, body): | |
""" Sending notification via pushbullet. | |
Args: | |
title (str) : title of text. | |
body (str) : Body of text. | |
""" | |
data_send = {"type": "note", "title": title, "body": body} | |
resp = requests.post('https://api.pushbullet.com/v2/pushes', data=json.dumps(data_send), | |
headers={'Authorization': 'Bearer ' + pushbulletAccessToken, 'Content-Type': 'application/json'}) | |
if resp.status_code != 200: | |
raise Exception('Notificatie versturen is mislukt, controleer access token.') | |
else: | |
print('Notificatie is verstuurd') | |
def send_notification_via_pushover(body): | |
conn = http.client.HTTPSConnection("api.pushover.net:443") | |
conn.request("POST", "/1/messages.json", | |
urllib.parse.urlencode({ | |
"token": pushoverAppApiToken, | |
"user": pushoverUserKey, | |
"message": '%s' % (body), | |
}), { "Content-type": "application/x-www-form-urlencoded" }) | |
conn.getresponse() | |
print('Notificatie is verstuurd') | |
def send_notification_via_gotify(title, body): | |
data_send = {"title": title, "message": body, "priority": 5} | |
resp = requests.post(gotifyUrl + '/message', data=json.dumps(data_send), | |
headers={'X-Gotify-Key': gotifyApiToken, 'Content-Type': 'application/json'}) | |
if resp.status_code != 200: | |
raise Exception('Notificatie versturen is mislukt, controleer access token en URL.') | |
else: | |
print('Notificatie is verstuurd') | |
start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Oorzaak was extra security check bij wachtrij tool, werkt na aanpassing van vandaag weer 👍