Skip to content

Instantly share code, notes, and snippets.

@ThomasG77
Created March 17, 2016 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ThomasG77/e488251696a00de73631 to your computer and use it in GitHub Desktop.
Save ThomasG77/e488251696a00de73631 to your computer and use it in GitHub Desktop.
Python sample to call to adresse.data.gouv.fr
# 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