Create a dataframe to store the zipcode & price
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user