From bf32ca3cb8f4b732eeed564e889847b68a10daf7 Mon Sep 17 00:00:00 2001 From: Karen Zeng Date: Mon, 8 May 2023 18:57:47 -0400 Subject: [PATCH] Create a dataframe to store the zipcode & price --- fp2_11.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/fp2_11.py b/fp2_11.py index f0564e6..24dfd74 100644 --- a/fp2_11.py +++ b/fp2_11.py @@ -6,9 +6,14 @@ import json import time import os from concurrent.futures import TimeoutError +import pandas as pd # os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "C:/Users/Karen/AppData/Roaming/gcloud/application_default_credentials.json" +# Create an empty dataframe to store the prices +df = pd.DataFrame(columns=['Zip Code', 'Price']) +print(f"Created a dataframe: {df}") + # Configure the Selenium driver options options = Options() options.add_argument('--disable-gpu') @@ -121,17 +126,27 @@ def callback(message): price = next_data['offers']['price'] # Print the price print(price) + + # Append the zip code and price to the dataframe + #append_to_df(zip_code, price) + new_row = pd.DataFrame({'Zip Code': [zip_code], 'Price': [price]}) + return pd.concat([df, new_row], ignore_index=True) + #print(f"Recorded the zip code and price: {zip_code},{price}") + #print(f"Updated a dataframe: {df}") + subscriber.acknowledge(ack_ids = [message.ack_id], subscription = subscription_path) # acknowledge receipt of message except Exception as e: print(f"Caught exception: {e}") print(f"Price not found for zip code {zip_code}") price = 'Price not found' + return df # Start receiving messages (sync version) while True: pull_request = pubsub_v1.types.PullRequest(max_messages = 1, subscription = subscription_path) pull_response = subscriber.pull(request = pull_request) - callback(pull_response.received_messages[0]) + df = callback(pull_response.received_messages[0]) + print(f"Updated a dataframe: {df}") # Start receiving messages (async version) #flow_control = pubsub_v1.types.FlowControl(max_messages = 1)