Skip to content

Instantly share code, notes, and snippets.

@leotop
Created July 28, 2016 23:46
Show Gist options
  • Save leotop/9aee610b8575abdc1894f3bca9584216 to your computer and use it in GitHub Desktop.
Save leotop/9aee610b8575abdc1894f3bca9584216 to your computer and use it in GitHub Desktop.
Пример работы с подсказками DaData на Python. Использует пакет requests (http://docs.python-requests.org/).
# -*- 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