2015-11-05 67 views
1

我正在使用這種方法獲得comments上的page data.Its工作正常,但我需要將數據轉儲到MongoDB。使用這種方法插入的數據,但作爲一個單一的文件。我想存儲每個評論應該有一個單獨的文件與我從API得到的信息。如何將面部數據存儲到mongodb中?

from facepy import GraphAPI 
import json 
import pymongo 
import json 
connection = pymongo.MongoClient("mongodb://localhost") 

facebook = connection.facebook 
commen = facebook.comments 
access = '' 
#message 
graph = GraphAPI(access) 
page_id= 'micromaxinfo' 
datas= graph.get(page_id+'/posts?fields=comments,created_time', page=True, retry=5) 

posts=[] 


for data in datas: 
    print data 

    commen.insert(data) 
    break 

輸出MongoDB中存儲:

{ 
      "created_time" : "2015-11-04T08:04:14+0000", 
      "id" : "120735417936636_1090909150919253", 
      "comments" : { 
       "paging" : { 
        "cursors" : { 
         "after" : "WTI5dGJXVnVkRjlqZFhKemIzSTZNVEE1TVRReE5ESTVOelV6TlRRd05Ub3hORFEyTnpFNU5UTTU=", 
         "before" : "WTI5dGJXVnVkRjlqZFhKemIzSTZNVEE1TURrd09UVTRNRGt4T1RJeE1Eb3hORFEyTmpJME16Z3g=" 
        } 
       }, 
       "data" : [ 
        { 
         "created_time" : "2015-11-04T08:06:21+0000", 
         "message" : "my favorite mobiles on canvas silver", 
         "from" : { 
          "name" : "Velchamy Alagar", 
          "id" : "828304797279948" 
         }, 
         "id" : "1090909130919255_1090909580919210" 
        }, 
        { 
         "created_time" : "2015-11-04T08:10:13+0000", 
         "message" : "Micromax mob. मैने कुछ दिन पहले Micromax Bolt D321 mob. खरिद लिया | Bt मेरा मोबा. बहुत गरम होता है Without internate. और internate MB कम समय मेँ ज्यादा खर्च होती है | कोई तो help करो.", 
         "from" : { 
          "name" : "Amit Gangurde", 
          "id" : "1637669796485258" 
         }, 
         "id" : "1090909130919255_1090910364252465" 
        }, 
        { 
         "created_time" : "2015-11-04T08:10:27+0000", 
         "message" : "Nice phones.", 
         "from" : { 
          "name" : "Nayan Chavda", 
          "id" : "1678393592373659" 
         }, 
         "id" : "1090909130919255_1090910400919128" 
        }, 
        { 
         "created_time" : "2015-11-04T08:10:54+0000", 
         "message" : "sir micromax bolt a089 mobile ki battery price kitna. #micromax mobile", 
         "from" : { 
          "name" : "Arit Singha Roy", 
          "id" : "848776351903695" 
         }, 

因此從技術上講我想在存儲領域data唯一信息來:

{ 
          "created_time" : "2015-11-04T08:10:54+0000", 
          "message" : "sir micromax bolt a089 mobile ki battery price kitna. #micromax mobile", 
          "from" : { 
           "name" : "Arit Singha Roy", 
           "id" : "848776351903695" 
          } 

如何進入我的數據庫呢?

回答

0

您可以使用pentaho數據集成開放源代碼ETL工具。我用它來存儲來自JSON輸出的特定字段以用於推文。

選擇您想要從JSON解析和Oracle中選擇一個輸出CSV或表格輸出中的字段等

希望這有助於

enter image description here

enter image description here

+0

感謝的人我將嘗試這一點,並回到你身邊 –

相關問題