Hi im creating a DB using Python and want to extract the info from this json dict i dont know if it better to extract the info directly from the file:
data =
{
"b_sales": [{
"position_r": 1,
"position": 1,
"title": "Noda Dorado",
"sales": "A088R7S66W",
"link": "https://www.url.com/nonda-Adapter"
"image": "https://image.jpg",
"price_lower": {
"value": 7.99,
},
"price_upper": {
"value": 10.99,
},
"price": {
"value": 7.99,
}
}, {
"position_r": 2,
"title": "WHOOSH! Kit de limpieza de pantalla",
"sales": "A07ZMFQB2S",
"link": "https://www.url.com/WHOOSH-Screen-",
"image": "https://images.jpg",
"price_lower": {
"value": 15.49,
},
"price_upper": {
"value": 29.99,
},
"price": {
"value": 15.49,
}
}],
"pagination": {
"current_page": 1,
"total_pages": 2
}
}
i already started with the code:
import psycopg2
conn = psycopg2.connect(
database="postgres", user='postgres', password='password', host='127.0.0.1', port= '5432'
)
conn.autocommit = True
cursor = conn.cursor()
sql ='''CREATE TABLE b_sales (
TITLE CHAR(30) NOT NULL,
SALES CHAR(20),
LINK CHAR(40),
IMAGE CHAR(30),
PRICE_L INT,
PRICE_U INT
PRICE INT
)'''
cursor.execute(sql)
conn.close()
And i dont know how to add the info in the table quite good i tried but without success
