Created
December 2, 2017 08:16
-
-
Save sarg/c437d2bda46907417a4b3a984e01fc5b to your computer and use it in GitHub Desktop.
Fetch velobike.ru statistics.
This file contains 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 | |
from requests.auth import HTTPBasicAuth | |
settings = { | |
'url' : 'http://apivelobike.velobike.ru', | |
'login' : '', | |
'pin' : '', | |
'year' : '2017' | |
} | |
res = requests.post(f"{settings['url']}/profile/authorize", auth=(settings['login'], settings['pin'])) | |
session = res.json()['SessionId'] | |
res = requests.get(f"{settings['url']}/ride/history", headers={'SessionId': session}) | |
rides = res.json()['Items'] | |
year = lambda r: r['StartDate'].startswith(settings['year']) | |
notBroken = lambda r: r['StartBikeParkingNumber'] != r['EndBikeParkingNumber'] or r['CoveredDistance'] > 200 | |
totalDistance = 0 | |
count = 0 | |
pay = 0 | |
for r in rides: | |
if not year(r): | |
continue | |
if r['Type'] == 'Ride' and notBroken(r): | |
count += 1 | |
totalDistance += r['CoveredDistance'] | |
pay += r['Price'] | |
print(f"At the year {settings['year']} you have ridden {count} times and covered {int(totalDistance/1000)} km. Money spent: {pay}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment