Skip to content

Instantly share code, notes, and snippets.

@k4nfr3
Last active June 30, 2023 15:02
Show Gist options
  • Save k4nfr3/eddac3471ca62fd6f840bfbb5ef7baa3 to your computer and use it in GitHub Desktop.
Save k4nfr3/eddac3471ca62fd6f840bfbb5ef7baa3 to your computer and use it in GitHub Desktop.
velocity.ch daily script to repurchase my free parking as I'm using it daily
import requests
import json
# Proxy settings fo debug (with burp or other)
proxy_enable = False
proxy = {
'http': 'http://127.0.0.1:8080',
'https': 'http://127.0.0.1:8080'
}
# Login credentials
username = 'myemail@domain.com'
password = 'mypassword'
print("*** Start")
# Step 1: Get JWT token
if not proxy_enable: proxy = {} # disable proxy settings
requests.packages.urllib3.disable_warnings() # disable warnings
useragent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/114.0' # let's not stick out with the User-Agent
headers = {'User-Agent': useragent }
response = requests.post('https://www.velocity.ch/api/token/', json={'username': username, 'password': password}, headers=headers, proxies=proxy, verify=False)
if response.status_code == 200:
content = response.content.decode('utf-8')
token = json.loads(content)['access']
print('STEP 1 : JWT token obtained successfully:')
del username # no more needed after getting the JWT Token
del password # no more needed after getting the JWT Token
else:
print('STEP 1 : Failed to obtain JWT token. Error code:', response.status_code)
exit(1)
# Step 2: Make a POST request with JWT token
headers = {'Authorization': 'JWT '+ token, 'Content-Type': 'application/json', 'User-Agent': useragent}
response = requests.get('https://www.velocity.ch/api/v1/customers/by-user-id/', headers=headers, proxies=proxy, verify=False)
if response.status_code == 200:
print('STEP 2 : Get User details request successful')
content = response.content.decode('utf-8')
#[uuid], firstname, lastname, [cbike][uuid], [cbike][0][name] , cfavorites][0][parking][uuid] , cfavorites][0][parking][name]
answer = json.loads(content)
uuidCustomer = answer['uuid']
firstname = answer['firstname']
lastname = answer['lastname']
print('STEP 2 : ', uuidCustomer, firstname, lastname)
favparkinguuid = answer['cfavorites'][0]['parking']['uuid']
favparkingname = answer['cfavorites'][0]['parking']['name']
print('STEP 2 : ', favparkinguuid, favparkingname)
favbikeuuid = answer['cbike'][0]['uuid']
favbikename = answer['cbike'][0]['name']
print('STEP 2 : ', favbikeuuid, favbikename)
else:
print('STEP 2 : Get User details failed. Error code:', response.status_code)
exit(0)
# Step 3: Get Prestation UUID for FAVParking UUID
response = requests.get('https://www.velocity.ch/api/v1/parkings/' + favparkinguuid + '/prestationtypes/', headers=headers, proxies=proxy, verify=False)
content = response.content.decode('utf-8')
if response.status_code == 200:
answer3 = json.loads(content)
print('STEP 3 : Get prestation for FAV Parking ' + favparkinguuid + ' successful')
prestationsuuid = answer3[0]['uuid']
print('STEP 3 : PrestationsUUID = ',prestationsuuid)
else:
print('STEP 3 : GET prestations request failed. Error code:', response.status_code)
exit(0)
# Step 4: Get 24h free UUID from prestation UUID
response = requests.get('https://www.velocity.ch/api/v1/vparkings/' + prestationsuuid + '/?current=True&language=EN', headers=headers, proxies=proxy, verify=False)
found_suitable_prestation = False
if response.status_code == 200:
content = response.content.decode('utf-8')
answer4 = json.loads(content)
print('STEP 4 : Get prestation for prestationsuuid : ' + prestationsuuid + ' successful')
for prestaoffer in answer4['vpprestations']:
prestaofferuuid = prestaoffer['uuid']
prestaoffername = prestaoffer['label_fr']
prestaoffersectorid = prestaoffer['sector_id']
isfree = prestaoffer['is_free']
if isfree :
print('STEP 4 : ', prestaoffername, prestaoffersectorid, prestaofferuuid, 'GRATUIT' )
found_suitable_prestation = True
break
else:
print('STEP 4 : GET prestations UUID request failed. Error code:', response.status_code)
exit(0)
if not found_suitable_prestation:
print("Exiting, could not found suitable free prestation")
exit(0)
# Step 5 : Purchase the free 24h
#POST /api/v1/purchases/
purchase_payload = {
'uuidCustomer': uuidCustomer,
'listPrestations': prestaofferuuid
}
response = requests.post('https://www.velocity.ch/api/v1/purchases/', json=purchase_payload, headers=headers, proxies=proxy, verify=False)
if response.status_code == 200:
content = response.content.decode('utf-8')
answer5 = json.loads(content)
purchaseUuid = answer5['purchaseUuid']
payment_status = answer5['payment_status']
print('STEP 5 : Purchase prestations successfull : ' + purchaseUuid )
else:
print('STEP 5 : Purchase prestations failed. Error code:', response.status_code)
exit(0)
if payment_status != 0:
print("Error in Payement_Status value returned is not ZERO : " + payment_status)
exit(0)
# Step 6 : Link purchase to fav bike
linkbike_payload = {
'uuidBike': favbikeuuid
}
response = requests.put('https://www.velocity.ch/api/v1/purchases/' + purchaseUuid + '/associate-bike/', json=linkbike_payload, headers=headers, proxies=proxy, verify=False)
if response.status_code == 201:
content = response.content.decode('utf-8')
print('STEP 6 : Purchase link to bike successfully : ' + purchaseUuid )
else:
print('STEP 6 : Purchase link to bike. Error code:', response.status_code)
exit(0)
print("*** Finished Successfully")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment