Created
September 20, 2019 13:33
-
-
Save Romern/10618bc3976f1945866849ac08c07af1 to your computer and use it in GitHub Desktop.
velocity api
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
import requests | |
import json | |
#Station 53 ist Mörgensstraße | |
baseurl = "https://cms.velocity-aachen.de/backend" | |
def login(email, password): | |
#Login: | |
param = {"j_username": email, | |
"j_password": password, | |
"_spring_security_remember_me": "true", | |
"submit": "Login"} | |
ret = requests.post(f'{baseurl}/api/authentication', params=param) | |
return re.search("JSESSIONID=[A-Z0-9]{32}", ret.headers["Set-Cookie"])[0].split("=")[1] | |
def get_available_stations(stationid): | |
ret = requests.get(f'{baseurl}/app/stations/{stationid}/slots/full') | |
return json.loads(ret.text) | |
def book_bike(stationid, jsessionid): #(reservieren ist kostenlos!) | |
#POST für reservieren | |
#Only JSESSIONID needed | |
cookie = {"JSESSIONID": jsessionid} | |
ret = requests.post(f'{baseurl}/app/stations/{stationid}/book', cookies=cookie) | |
return json.loads(ret.text) | |
def unbook_bike(jsessionid): #(reservierung abbrechen) | |
cookie = {"JSESSIONID": jsessionid} | |
ret = requests.delete(f'{baseurl}/app/booking', cookies=cookie) | |
return (ret.status_code == 200) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment