velib.py 文件源码

python
阅读 17 收藏 0 点赞 0 评论 0

项目:lenuage 作者: laboiteproject 项目源码 文件源码
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'
        }
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号