def get_station_infos(cls, station_id):
req = requests.get(settings.VELIB_API_BASE_URL,
params={'apikey': settings.VELIB_API_KEY,
'dataset': 'stations-velib-disponibilites-en-temps-reel',
'fields': 'name,bike_stands,available_bikes,status',
'q': 'number:"{}"'.format(station_id),
'timezone': timezone.get_current_timezone_name()})
if not req.ok:
return None
data = req.json()
if not data.get('nhits', 0):
# No matching data found
return None
data = data['records'][0]['fields']
return {
'station': data['name'],
'slots': data['bike_stands'],
'bikes': data['available_bikes'],
'status': data['status'] == 'OPEN'
}
评论列表
文章目录