특정 도시의 식당 검색을 위해 파이썬에서 facebook.graphAPI을 사용하고 있습니다. 돌려주는 결과는 DICT 타입입니다.
내 코드 :데이터베이스에 Dict 유형 결과를 저장하는 방법?
import facebook
import json
# get access_token from https://developers.facebook.com/tools/access_token/
graph = facebook.GraphAPI(access_token='EAAHuWhpN91gBAEcZCammDhlB2w0Q4FO1TH1J09IfZBBtJE8ruu78KNjdOxu38AOp9GxB0gv5YlSetJ70WLscYmMkpY2SrQkGWRQcojaZBZCb52kkHKs1yE868DJ9MEjrCRIMfeVZBVRwNfuT27gUFhaVomOzpyd3lHxYelx82qQZDZD', version='2.7')
profile = graph.get_object("me")
print profile
rests=graph.request('search', {'q': 'Restaurants in Lahore', 'type': 'place'})
print type(rests)
for key in rests:
print "key: %s , value: %s" % (key, rests[key])
#TO get posts of Restaurant with id 816463355086343
posts = graph.get_connections('816463355086343', 'posts')
결과는 아래 그림과 같다. 명확하게 읽을 수는 없습니다. enter image description here
그래서 읽을 수 있도록 노력하겠습니다. 그리고이 모양은
key: data , value:
[
{
u'category': u'Hotel',
u'id': u'106037262807337',
u'location':
{
u'city': u'Lahore',
u'zip': u'',
u'country': u'Pakistan',
u'longitude': 74.3356207,
u'state': u'',
u'street': u'PC Hotel Lahore, Mall Road Pakistan',
u'latitude': 31.5480206
},
u'category_list':
[
{
u'id': u'165679780146824',
u'name': u'Food & Restaurant'
},
{
u'id': u'180699075298665',
u'name': u'Hospitality Service'
},
{
u'id': u'164243073639257',
u'name': u'Hotel'
}
],
u'name': u'Pearl Continental, Lahore'
},
{
u'category': u'Local business',
u'id': u'125484227592406',
u'location':
{
u'city': u'Lahore',
u'zip': u'',
u'country': u'Pakistan',
u'longitude': 74.417206363636,
u'state': u'',
u'street': u'masjad chok',
u'latitude': 31.612784545455
},
u'category_list':
[
{
u'id': u'150534008338515',
u'name': u'Barbecue Restaurant'
}
],
u'name': u'Lahore Defence'
},
....
결과를 데이터베이스에 저장하려고합니다. 나는 모른다 어떻게 그것을 할 수 있습니까? 많이 받아 주시면 고맙습니다.
데이터베이스 드라이버를 사용하여 데이터를 저장하고 검색하는 방법에 대한 지침이 필요합니다.
당신은 문자열로 저장하고 당신이 그것을 꺼내 때, 그것을 읽고'json' 라이브러리를 사용하여 분석 할 수있다. –
어떤 종류의 데이터베이스를 저장하려고합니까? – MooingRawr
pickle을 사용하여 dict 정보를 serialize-deserialize 할 수 있습니다. – stuartnox