Skip to content

Instantly share code, notes, and snippets.

@miglen
Created August 25, 2020 15:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miglen/2e44d78a1e8c84c9adf5e3989f5ea8eb to your computer and use it in GitHub Desktop.
Save miglen/2e44d78a1e8c84c9adf5e3989f5ea8eb to your computer and use it in GitHub Desktop.
Automatic booking of flyefit.ie sessions.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import datetime
import requests
from bs4 import BeautifulSoup
"""
The following script books specified sessions for
tomorrow in flyefiet gym web app.
"""
# Very sensitive data
credentials = {
'email_address': 'flyefit@miglen.com',
'password': '5febfe7b5ca24a76803ec4b69e315cfd'
}
str_tomorrow = (datetime.date.today() + datetime.timedelta(days=1)).strftime("%Y-%m-%d")
url_booking = "https://myflye.flyefit.ie/myflye/book-workout/167/3/{}".format(str_tomorrow)
# Set each slot to True to book
slots = {
"05:30 - 06:45": False,
"07:00 - 08:15": False,
"08:30 - 09:45": False,
"10:00 - 11:15": False,
"11:30 - 12:45": False,
"13:00 - 14:15": False,
"14:30 - 15:45": False,
"16:00 - 17:15": False,
"17:30 - 18:45": False,
"19:00 - 20:15": True, # Book this one
"20:30 - 21:45": False,
"22:00 - 23:15": False
}
# Login
session = requests.Session()
session.post("https://myflye.flyefit.ie/login", data=credentials)
print("[DEBUG] Logging in {} ...".format(credentials['email_address']))
# Get the sessions tomorrow
soup = BeautifulSoup(session.get(url_booking).text, 'html.parser')
for slot in slots:
if slots[slot] == True:
print("[DEBUG] Slot: {} | Checking... ".format(slot))
course_field = soup.find(text=slot).parent.parent.parent.select("p.btn-primary")[0]
if course_field.text.strip() == 'Not Yet Open':
print("[ERROR] Slot: {} is Not Open Yet. ".format(slot))
elif course_field.text.strip() == 'Booked':
print("[DEBUG] Slot: {} is Already Booked. ".format(slot))
elif hasattr(course_field, 'data-course-id'):
session.post("https://myflye.flyefit.ie/api/course_book", data={'course_id':course_field['data-course-id']})
print("[DEBUG] Slot: {} is Now Successfuly Booked. ".format(slot))
else:
print("[ERROR] Slot: {} | Parsing error.".format(slot))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment