Created
July 28, 2016 23:46
-
-
Save leotop/9aee610b8575abdc1894f3bca9584216 to your computer and use it in GitHub Desktop.
Пример работы с подсказками DaData на Python. Использует пакет requests (http://docs.python-requests.org/).
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 -*- | |
import json | |
import requests | |
API_KEY = 'YOUR_API_KEY' | |
BASE_URL = 'https://suggestions.dadata.ru/suggestions/api/4_1/rs/suggest/%s' | |
def suggest(query, resource): | |
url = BASE_URL % resource | |
headers = { | |
'Authorization': 'Token %s' % API_KEY, | |
'Content-Type': 'application/json', | |
} | |
data = { | |
'query': query | |
} | |
r = requests.post(url, data=json.dumps(data), headers=headers) | |
return r.json() | |
print suggest(u'москва хабаровская', 'address') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment