diff --git a/combined.py b/combined.py index 68d7ebf..1c8a4c7 100644 --- a/combined.py +++ b/combined.py @@ -40,7 +40,7 @@ prompt = ( f"recommend the top {cate} " - f"in {cy}: (combined)." + f"in {cy}: {combined}." "based on these, recommend the better one and why" "two to three sentences" ) diff --git a/json_parsing.py b/json_parsing.py index 6d6ea3e..238b315 100644 --- a/json_parsing.py +++ b/json_parsing.py @@ -7,7 +7,7 @@ class Parser: - + def __init__(self, json): load_dotenv() if 'data' in json: @@ -31,47 +31,15 @@ def write_to_database(self, tb_name): GROUP BY Name );""" connection.execute(db.text(remove_dupes)) - # self.get_ratings() - - # def get_ratings(self): - # if not isinstance(self.json, type([])): - # return - # rows = [] - # for location in self.json: - # location_id = int(location['location_id']) - # url = (f"https://api.content.tripadvisor.com/api/v1/location/" - # f"{location_id}/details") - # headers = {"accept": "application/json"} - # data = { - # 'key': self.key - # } - # r = requests.get(url, headers=headers, params=data) - # if r.status_code == 200: - # flattened = pd.json_normalize(r.json()) - # rows.append(flattened) - # df = pd.concat(rows, ignore_index=True) - # for col in df.columns: - # if df[col].apply(lambda x: isinstance(x, (dict, list))).any(): - # df[col] = df[col].apply(json.dumps) - # df = df.infer_objects() - # print(df) - # print(df.dtypes) - # # df.to_sql("temp", con=self.engine, if_exists='append', index=False) + def pull_list(self, table_name, city): + query = (f"SELECT * FROM {table_name} " + f"WHERE \"address_obj.city\" = '{city}' LIMIT 10;") + with self.engine.connect() as connection: + result = connection.execute(db.text(query)).fetchall() + print(pd.DataFrame(result)) - # join_command = """CREATE TABLE recommendations AS - # SELECT * FROM locations - # JOIN temp ON locations.location_id = temp.location_id;""" - # with self.engine.connect() as connection: - # connection.execute(db.text(join_command)) - # self.drop("temp") - def drop(self, table_name): command = f"DROP TABLE IF EXISTS {table_name}" with self.engine.connect() as connection: connection.execute(db.text(command)) - -with open('sampleJSON.txt', 'r') as file: - location = file.read() -test = Parser(json.loads(location)) -test.write_to_database("locations")