-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapi.py
More file actions
32 lines (25 loc) · 772 Bytes
/
api.py
File metadata and controls
32 lines (25 loc) · 772 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import requests
import socketio
base_url = 'https://cartracker-api.fly.dev/api/v1/garages/'
sio = socketio.Client()
sio.connect('https://cartracker-api.fly.dev')
class Garage:
def __init__(self, garage):
self.id = garage['_id']
self.name = garage['garageName']
self.address = garage['address']
self.capacity = garage['capacity']
self.cars_in_lot = garage['carsInLot']
def to_dict(self):
return {
'_id': self.id,
'carsInLot': int(self.cars_in_lot)
}
def put_garage(garage: Garage):
sio.emit('garageUpdate', garage.to_dict())
def get_garages():
resp = requests.get(base_url)
garages = []
for g in resp.json():
garages.append(Garage(g))
return garages