Sunday, 15 June 2014

how to insert specific json into sqlite database using python 3 -


Using Python 3, I want to download the API data, which has been returned as JSON, and then I only want to include specific (especially). Column or field or whatever?) In a simlight database. Therefore, I have problems with me here and I have:

Using the Python Request module:

import import module sqlite3 import request import json Header = {'Authority': 'ujbOsdlknfsodiflksdonosB4aA =', 'Accept': 'Application / JS'} R = Request .get ('https://api.lendingclub.com/api/investor/v1/accounts/94837758/ Well, the first issue is how do I get the requested JSON data into something (a dictionary?) Using the dragon. It may be that ... I

  jason.loads (r.text)  

Then I create the table in which I want to insert specific data:

  curs.execute ('' Creating Tablet Data (Loan is not an Instider, Note AMRX is not real '' '')  

No problem But now, even if JSON data looks something like this (although there are hundreds of records) ...

  {"myNotes": [{"loanId": 11111, "note id" : 22222, "Order ID": 33333, "Purpose": "Debt Consolidation", "Cabarted": True, "A "Credit Card Refinance", "Canberbed": "Christian Credit": 12.1, "Principal Pending": 20.94, "Credit Card Refinance", "Redirected": "Down", "Loan Amount": 10800, "Note Amount": 25, "Received Payment": 5.88 ",", "Loan ID": "11111," Note ID: 22222, "Order ID": 33333, "Objective" "Credit-Tired": "UP", "Loan Amount": 3000, "Note Amount": 25, Payment Received ": 7.65," Acquired Interest ": 11.92," Prosperation ": 19.76,}]  

>

I only call data points to the SQLite database," Loan ID "and "note Mount "would like to join. I believe that something like that will appear in the database (but it is wrong to know):

  curs.execute ('INSERT data (loan, note amount) value (?,?) ', (LONID, note amount))  

But I am now about a complete loss of how to do this, so I think I have two main issues Are; Getting downloaded data into something so that Python can use to insert specific data into the database; And then how do I insert the data from the database from the object that holds the downloaded data? I'm guessing looping is part of the answer ... but from what? thank you in advanced!

As

says:

supports sqlite3 module There are two types of placeholders: question mark (qmark style) and named placeholders (named style).

Note that you can insert all the rows at once by using executemany . So in your case:

  curs.executemany ('INSERT IN data data (note, note amount)' 'value (: loan id, note amount)', Jason.loads (... ) ['MyNotes'])  

No comments:

Post a Comment