Skip to content

Instantly share code, notes, and snippets.

@matael
Last active December 11, 2015 19:49
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matael/4651025 to your computer and use it in GitHub Desktop.
Save matael/4651025 to your computer and use it in GitHub Desktop.
OpenData : parkings de nantes

Licences

Script

Licence du script python lui-même ::

DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 
        Version 2, December 2004 

Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>

Everyone is permitted to copy and distribute verbatim or modified copies of this license document, and changing it is allowed as long as the name is changed.

DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE

TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

  1. You just DO WHAT THE FUCK YOU WANT TO.

Données

Licence des données : ODbL

#!/usr/bin/env python
#-*- coding: utf8 -*-
import sys
import os
import json
from urllib.request import urlopen
from matplotlib import pyplot as plt
api_key = '5H7IGDGF78UQAOF'
base_url = 'http://data.nantes.fr/api/'
command = 'getDisponibiliteParkingsPublics/1.0/'
format = '/?output=json'
# recreate full url
full_url = "{}{}{}{}".format(
base_url,
command,
api_key,
format
)
# get the data :
data_handle = urlopen(full_url)
data = json.loads(data_handle.read().decode())
# handle eventual errors
if data['opendata']['answer']['status']['@attributes']['code'] != "0":
print("A error occured :\n\n{}".format(
data['opendata']['answer']['status']['@attributes']['code']
))
sys.exit(1)
# shorten a bit this fucking hash-ception
parkings = data['opendata']['answer']['data']['Groupes_Parking']['Groupe_Parking']
# extract places
lien_nom_places = {_['Grp_nom']:_['Grp_disponible'] for _ in parkings}
noms = [_ for _ in lien_nom_places.keys()]
places = [int(lien_nom_places[_]) for _ in noms]
# recreate a x-axis
width = 0.8 # width of a bar
left = [_*width for _ in range(len(places))]
plt.bar(left, places, width=width)
plt.xticks(left, noms, rotation=85)
plt.grid('on')
plt.title("Places disponibles dans les parkings de Nantes")
plt.tight_layout()
plt.savefig('places')
#!/usr/bin/env python
#-*- coding: utf8 -*-
import sys
import os
from json import loads
from urllib.request import urlopen
from matplotlib import pyplot as plt
def main():
api_key = '5H7IGDGF78UQAOF'
base_url = 'http://data.nantes.fr/api/'
command = 'getDisponibiliteParkingsPublics/1.0/'
format = '/?output=json'
# recreate full url
full_url = "{}{}{}{}".format(
base_url,
command,
api_key,
format
)
# get the data :
data_handle = urlopen(full_url)
data = loads(data_handle.read().decode())
# handle eventual errors
if data['opendata']['answer']['status']['@attributes']['code'] != "0":
print("A error occured :\n\n{}".format(
data['opendata']['answer']['status']['@attributes']['code']
))
sys.exit(1)
# shorten a bit this fucking hash-ception
parkings = data['opendata']['answer']['data']['Groupes_Parking']['Groupe_Parking']
# extract places
lien_nom_places = {}
for _ in parkings:
if _['Grp_exploitation'] == '0':
lien_nom_places[_['Grp_nom']] = 100
else:
lien_nom_places[_['Grp_nom']] = \
100.0-(int(_['Grp_disponible'])/int(_['Grp_exploitation']))*100
# lien_nom_places = {_['Grp_nom']:
# (100.0-(int(_['Grp_disponible'])/int(_['Grp_exploitation']))*100)
# for _ in parkings}
noms = [_ for _ in lien_nom_places.keys()]
places = [lien_nom_places[_] for _ in noms]
# recreate a x-axis
width = 0.8 # width of a bar
left = [_*width for _ in range(len(places))]
plt.bar(left, places, width=width)
plt.xticks(left, noms, rotation=85)
plt.grid('on')
plt.title("Pourcentage de remplissage des parkings de Nantes")
plt.tight_layout()
plt.savefig('places')
if __name__=='__main__': main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment