Last active
April 6, 2022 06:36
-
-
Save cice/486d235f22f284ecbd7c20177c983429 to your computer and use it in GitHub Desktop.
Slot booking script for superbloc.nrw
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
# frozen_string_literal: true | |
# Usage: | |
# Install required gems: | |
# | |
# gem install rest-client | |
# gem install activesupport | |
# gem install awesome_print | |
# | |
# Add your data in MY_DATA, maybe change the tariff (TARIFF_ID[:usc]), then run | |
# | |
# ruby book_bloc.rb 17:00 2022-04-13 | |
# | |
# with your desired date and time | |
require 'rubygems' | |
require 'rest-client' | |
require 'active_support/all' | |
require 'awesome_print' | |
RestClient.log = 'stdout' | |
module BookBloc | |
API = "https://backend.dr-plano.de" | |
CLIENT_ID = 41582823 # SuperBloc | |
SHIFT_MODEL_ID = 87898650 # The normal entry, use 87900293 for the "early" (weekdays til 1pm) | |
TARIFF_ID = { | |
abo: 87899956, # Eintritt 11er Karte | Zeitkarte | Abo | |
reduced: 87899960, # Eintritt ermäßigt | |
kids: 87899958, # Eintritt Kinder | |
normal: 87899336, # Eintritt normal | |
usc: 87899954, # Eintritt Urban Sports | Gympass | Qualitrain | Sportnavi | |
} | |
HEADERS = { | |
'Referer' => 'https://www.superblock.nrw/', | |
'Origin' => 'https://www.superblock.nrw/', | |
'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.3 Safari/605.1.15', | |
'Accept-Language' => 'en-GB,en;q=0.9', | |
'Accept-Encoding' => 'gzip, deflate, br' | |
} | |
MY_DATA = { | |
dateOfBirthString: '1990-12-24', | |
firstName: 'Max', | |
lastName: 'Mustermann', | |
email: '[email protected]', | |
dateOfBirth: '1990-12-24', | |
} | |
module_function | |
def call(date) | |
desired_slot_timestamp = timestamp(date) | |
response = RestClient.get("#{API}/courses_dates?id=#{SHIFT_MODEL_ID}&advanceToFirstMonthWithDates&start=#{desired_slot_timestamp}&end=#{timestamp(date + 1.day)}", HEADERS) | |
slots = JSON.parse(response.body) | |
slot = slots.find do |s| | |
s.dig('dateList', 0, 'start') == desired_slot_timestamp | |
end | |
raise "No slot available" unless slot && slot['state'] == 'BOOKABLE' | |
ap RestClient.post("#{API}/bookable", JSON.dump(booking_payload(slot)), {**HEADERS, 'Content-Type' => 'application/json'}) | |
end | |
def timestamp(time) | |
(time.to_i * 1000) | |
end | |
def booking_payload(slot) | |
{ | |
shiftSelector: slot['selector'], | |
clientId: CLIENT_ID, | |
shiftModelId: SHIFT_MODEL_ID, | |
desiredDate: nil, | |
type: 'booking', | |
streetAndHouseNumber: '-', | |
postalCode: '00000', | |
city: '-', | |
phoneMobile: '-', | |
participants: [ | |
{ | |
isBookingPerson: true, | |
tariffId: TARIFF_ID[:usc], | |
**MY_DATA | |
} | |
], | |
**MY_DATA | |
} | |
end | |
end | |
date = Date.parse(ARGV[1]) | |
time = Time.parse(ARGV[0], date) | |
BookBloc.call(time) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment