Created
February 17, 2023 13:15
-
-
Save Realiserad/b8c83114b3db35e98475f77e852c31c3 to your computer and use it in GitHub Desktop.
Bli notifierad när en bandag med Sydskånes Emse blir ledig!
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
| #!/usr/bin/python3 | |
| from selenium import webdriver | |
| from selenium.webdriver.firefox.options import Options | |
| from selenium.webdriver.common.by import By | |
| import json | |
| import notify2 | |
| import requests | |
| # The message template used for notifications. | |
| template=""" | |
| En bandag med Sydskånes Emse är tillgänglig för bokning! | |
| Klicka här för att boka: {link} | |
| """ | |
| # SSEMSE-ID or email address and password used to log in. | |
| username = '' | |
| password = '' | |
| trackdays = [ | |
| # Go to https://sydskanesemse.nu/bandagar and click on the trackday you want to monitor for cancellations. | |
| # Then copy the link from the browser and paste it here. | |
| 'link': 'https://sydskanesemse.nu/event/2023-08-25_ring-knutstorp', | |
| # Type of ticket. Possible options (not all options may be available for all events): | |
| # [ 'Gul Grupp', 'Blå Grupp', 'Röd Grupp', 'Polkagris Grupp', 'Vit Grupp', 'Flaggvakt', 'Deltagare' ] | |
| 'type': 'Vit Grupp' | |
| } | |
| ] | |
| def notify(trackday): | |
| notification = notify2.Notification( | |
| summary='Ny bandag!', | |
| message=template.format(link = trackday['link']), | |
| icon="/tmp/ssemse.png") | |
| notification.show() | |
| notify2.init('ssemse') | |
| logo = requests.get('https://bayimg.com/701d8b3e951c5219bf0bde4bda498ad08cb77195.jpg') | |
| open('/tmp/ssemse.png', 'wb').write(logo.content) | |
| options = Options() | |
| options.headless = True | |
| driver = webdriver.Firefox(options = options) | |
| driver.get('https://sydskanesemse.nu/logintc') | |
| # Accept cookies | |
| driver.find_element(By.ID, 'cookie_action_close_header').click() | |
| # Log in | |
| driver.find_element(By.ID, 'username-843').send_keys(username) | |
| driver.find_element(By.ID, 'user_password-843').send_keys(password) | |
| driver.find_element(By.ID, 'um-submit-btn').click() | |
| for trackday in trackdays: | |
| page = driver.get(trackday['link']) | |
| ticket = driver.find_element(by = By.XPATH, value="//*[contains(text(), '{type}')]".format(type = trackday['type'])).find_element(By.XPATH, value='..') | |
| if json.loads(ticket.get_attribute('data-available')): | |
| notify(trackday) | |
| driver.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment