How to store Dict type result in database?
<p>I am using  using <strong>facebook.graphAPI</strong> in python for searching restaurants in some specific city. The result it gives back is in <strong>DICT</strong> type.<br>
My Code:</p>

<pre><code>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')
</code></pre>

<p>the result is like the picture given below. which is clearly not readable. 
<a href="http://i.stack.imgur.com/Alxyz.png" rel="nofollow">enter image description here</a></p>

<p>So make I tried to make it readable. And it looks like this    </p>

<pre><code>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 &amp;amp; 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'
},
....
</code></pre>

<p>I want to store the result into the database. I don't know <strong>How</strong> to do it? Please help me out it would be appreciated alot.<br>
So I need instructions as how to use a database driver to store the data and retrieve it.  </p>

<p>Start by having an accessible Database server. Either set one up locally or if you have the means, set one up remotely. 
The image you attached to the question looks like a windows terminal, so download the MySQL Community Server for windows <a href="http://dev.mysql.com/downloads/mysql/" rel="nofollow">here</a>. </p>

<p>The set up should be fairly straight forward. 
Keep your login credentials (most commonly used are -> username:root, password:root) somewhere secure. You'll be asked if and which password you'd like.</p>

<p>When the server is up and running, it'll be available on <code>127.0.0.1:3306</code> by default. Now if you have some experience in MySQL, you'll know how to set up a basic database with some tables for your data to go in. (I'm assuming you have.)</p>

<p>Once it's up and running, install mysql for python by executing 
<code>pip install MySQL-python</code> (this works for Python 2.7 as far as I know, use <code>pip install mysqlclient</code> for python 3+). This will install a python library that you can use in your code. Simply add the import statement for whichever library you chose at the top of your code as such: <code>import &lt;library_name&gt;</code>.</p>

<p>Now I can't give you exact code because I know know which python version you're on but whichever you choose, there'll be documentation out there how to use it.</p>

<p>It'll be in the following steps: </p>

<ol>
<li>Add the database connection details to the mysqlclient 
 a. address (localhost:3306, ...)
 b. username (root, ...) 
 c. password (root, ...)
 d. database_name (your_database_name)</li>
<li>Create a cursor object which allows you to traverse the database tables</li>
<li>Add an SQL statement to the cursor (i.e. SELECT * FROM CUSTOMERS)</li>
<li>Place the result from your cursor execution into a variable</li>
<li>Happy days</li>
</ol>

python json facebook-graph-api