<gh_stars>1-10
# Parse reviews in a Postgres database
# Version 1.0
# Author: <NAME>
# This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.


# Import Psycopg Postgres adapter for Python
import psycopg2

# Import Python's default JSON encoder and decoder
import json

# Open a connection to the database
db_conn = psycopg2.connect("dbname='database_name' host='server_address' user='username' password='password'")

# Initialize an empty list for temporarily holding a JSON object
data = []

# Open a JSON file from the dataset and read data line-by-line iteratively
with open('yelp_academic_dataset_review.json') as fileobject:
	for line in fileobject:
		data = json.loads(line)

		# Parse the JSON object in your database
		cur = db_conn.cursor()
		cur.execute("insert into Review (review_id, user_id, business_id, stars, review_date, review_text, useful, funny, cool, type) values (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", (data['review_id'], data['user_id'], data['business_id'], data['stars'],data['date'],data['text'], data['useful'], data['funny'], data['cool'], data['type']))
		db_conn.commit()
		#print(data['review_id'])

# Close database connection
db_conn.close()

# Parse reviews in a Postgres database
# Version 1.0
# Author: <NAME>
# This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.


# Import Psycopg Postgres adapter for Python
import psycopg2

# Import Python's default JSON encoder and decoder
import json

# Open a connection to the database
db_conn = psycopg2.connect("dbname='database_name' host='server_address' user='username' password='password'")

# Initialize an empty list for temporarily holding a JSON object
data = []

# Open a JSON file from the dataset and read data line-by-line iteratively
with open('yelp_academic_dataset_review.json') as fileobject:
	for line in fileobject:
		data = json.loads(line)

		# Parse the JSON object in your database
		cur = db_conn.cursor()
		cur.execute("insert into Review (review_id, user_id, business_id, stars, review_date, review_text, useful, funny, cool, type) values (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", (data['review_id'], data['user_id'], data['business_id'], data['stars'],data['date'],data['text'], data['useful'], data['funny'], data['cool'], data['type']))
		db_conn.commit()
		#print(data['review_id'])

# Close database connection
db_conn.close()
# Parse reviews in a Postgres database # Version 1.0 # Author: <NAME> # This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. # Import Psycopg Postgres adapter for Python # Import Python's default JSON encoder and decoder # Open a connection to the database # Initialize an empty list for temporarily holding a JSON object # Open a JSON file from the dataset and read data line-by-line iteratively # Parse the JSON object in your database #print(data['review_id']) # Close database connection