Skip to content

Instantly share code, notes, and snippets.

@shojibMahabub
Last active April 11, 2019 15:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shojibMahabub/dded84358df169e8dcd4f87be597a1a8 to your computer and use it in GitHub Desktop.
Save shojibMahabub/dded84358df169e8dcd4f87be597a1a8 to your computer and use it in GitHub Desktop.
import json
import psycopg2
# I wrote all of DB queries in 'query.py' file
import query as q
# And load json file like this, I renamed the file [data.json]
jsonfile = open('data.json', 'r')
data = json.load(jsonfile)
# establish connection to database
conn = psycopg2.connect(
"host=localhost dbname='bluetechsoft' user=postgres password=password")
cur = conn.cursor()
# By review_object I mean a single review in json file
for review_object in data:
cur.execute(q.review_data_insertion,
(review_object['points'], review_object['title'],
review_object['description'], review_object['taster_name'],
review_object['taster_twitter_handle'],
review_object['price'], review_object['designation'],
review_object['variety'], review_object['region_1'],
review_object['region_2'], review_object['province'],
review_object['country'], review_object['winery']))
conn.commit()
conn.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment