Created
March 17, 2016 15:22
-
-
Save ThomasG77/e488251696a00de73631 to your computer and use it in GitHub Desktop.
Python sample to call to adresse.data.gouv.fr
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
# coding: utf-8 | |
"""Call to adresse.data.gouv.fr API.""" | |
import codecs | |
import io | |
from collections import OrderedDict | |
import requests | |
requests_session = requests.Session() | |
kwargs = { | |
'data': OrderedDict([ | |
('columns', ['numero_libelle_de_voie', 'commune']), | |
('postcode', 'code_postal') | |
]), | |
'method': 'post', | |
'files': OrderedDict([ | |
('data', ('annuaire-des-debits-de-tabac-part.csv', | |
io.BytesIO( | |
open('annuaire-des-debits-de-tabac-part.csv', 'rb').read() | |
))) | |
]), | |
'stream': True, | |
'url': 'http://api-adresse.data.gouv.fr/search/csv/' | |
} | |
response = requests_session.request(**kwargs) | |
with codecs.open('/tmp/out.csv', 'wb', 'utf-8') as f: | |
f.write(response.text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment