Now it doesn't work in a different way

This commit is contained in:
cheezedoodle2
2023-05-03 17:45:16 -07:00
parent 94123d93f0
commit 77f2214c3f
+13 -7
View File
@@ -8,7 +8,7 @@ from google.cloud import pubsub_v1
# In[2]:
# Set the project ID and topic name
project_id = 'price-extraction-project'
project_id = 'svig-384801'
topic_name = 'nfl-zipcodes'
@@ -63,8 +63,10 @@ nfl_zipcodes = {
# In[6]:
# Publish each zip code to the topic
for team, zipcode in nfl_zipcodes.items():
data = f'{team} - {zipcode}'.encode('utf-8')
publisher.publish(topic_path, data=data)
data = f'{zipcode}'.encode('utf-8')
publisher_future = publisher.publish(topic_path, data=data)
message_id = publisher_future.result()
print(f"message_id = {message_id}")
print('All zip codes published.')
@@ -80,12 +82,12 @@ from selenium.webdriver.support import expected_conditions as EC
from google.cloud import pubsub_v1
# Set the project ID and subscription name
project_id = 'price-extraction-project'
project_id = 'svig-384801'
topic_name = 'nfl-zipcodes'
subscription_name = 'sloetjes'
subscription_name = 'nfl-zipcodes-sub'
# Set the path to your ChromeDriver executable
chrome_driver_path = "/Users/sloetjeswong/Downloads/chromedriver_mac_arm64/chromedriver"
chrome_driver_path = "/usr/local/bin/chromedriver"
# Set up a Google Cloud Pub/Sub subscriber
subscriber = pubsub_v1.SubscriberClient()
@@ -93,7 +95,7 @@ subscription_path = subscriber.subscription_path(project_id, subscription_name)
# Set up a ChromeDriver instance
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--headless") # Run Chrome in headless mode
#chrome_options.add_argument("--headless") # Run Chrome in headless mode
chrome_service = Service(chrome_driver_path)
chrome_service.start()
driver = webdriver.Remote(chrome_service.service_url, options=chrome_options)
@@ -109,6 +111,7 @@ def callback(message):
# Wait for the price to load
price_xpath = "//span[@class='price']"
print(EC.presence_of_element_located((By.XPATH, price_xpath)))
price_element = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, price_xpath)))
# Extract the price and print it
@@ -121,8 +124,11 @@ def callback(message):
# Subscribe to the topic
streaming_pull_future = subscriber.subscribe(subscription_path, callback=callback)
print(f"Listening for messages on {subscription_path}...")
streaming_pull_future.result()
# Keep the script running
while True:
time.sleep(60)
# %%