更新 date pmi

master
joey0629 10 months ago
parent 19b384c1ab
commit 2fd7100854
  1. 7
      Dockerfile
  2. 35
      main.py

@ -9,7 +9,8 @@ RUN apt-get update && apt-get install -y \
&& wget https://storage.googleapis.com/chrome-for-testing-public/124.0.6367.60/linux64/chromedriver-linux64.zip \
&& unzip chromedriver-linux64.zip \
&& mv chromedriver-linux64/chromedriver /usr/local/bin/ \
&& chmod +x /usr/local/bin/chromedriver
&& chmod +x /usr/local/bin/chromedriver \
&& apt-get install xvfb
# 安裝Google Chrome
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
@ -22,9 +23,9 @@ WORKDIR /app
# Copy the dependencies file to the working directory
COPY requirements.txt .
COPY beaapi-0.0.2-py3-none-any.whl
# Install any dependencies
RUN pip3 install -r requirements.txt
RUN pip install beaapi-0.0.2-py3-none-any.whl
# Copy the content of the local src directory to the working directory in the container
COPY . .

@ -10,11 +10,15 @@ import requests
from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.common.exceptions import WebDriverException
import pytz
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
from datetime import timedelta
from pyvirtualdisplay import Display
import threading
BOT_TOKEN = '6701395239:AAFE30dqvNihDdni9vYoAbWssO-X5yAmwho'
# BOT_TOKEN = "6746720034:AAEMaoV2FwIZ8pz_PF18-bo2a6gFC1eVtVs"
@ -55,7 +59,15 @@ def find_fomc(driver, date:str):
def find_non_farm(driver):
try:
driver.get(nonfarm_url)
for _ in range(100):
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
# print all of the page source that was loaded
print(driver.page_source.encode("utf-8"))
print("Open")
# 等待元素出現
WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.XPATH, '/html/body/div[2]/div[5]/div/div[1]/pre')))
date = driver.find_element(By.XPATH, '/html/body/div[2]/div[5]/div/div[1]/pre').text.split('\n')[6]
value = driver.find_element(By.XPATH, '/html/body/div[2]/div[5]/div/div[1]/pre').text.split('\n')[8:12]
return driver, date, value
@ -95,6 +107,8 @@ def find_pmi(driver, date_target:str):
def broadcast_all_non_farm(target:str):
startimee = time.time()
display = Display(visible=0, size=(1920, 1080))
display.start()
driver = webdriver.Chrome(options=options)
driver, date, message = find_non_farm(driver)
while date != target:
@ -110,10 +124,13 @@ def broadcast_all_non_farm(target:str):
"-1002033782195")
broadcast_message(f"The above is the Non Farm for {target}","-1002033782195")
driver.quit()
display.stop()
return True
def broadcast_all_cpi(target:str):
startimee = time.time()
display = Display(visible=0, size=(1920, 1080))
display.start()
driver = webdriver.Chrome(options=options)
driver, date , message = find_cpi(driver)
while date != target:
@ -129,9 +146,12 @@ def broadcast_all_cpi(target:str):
"-1002033782195")
broadcast_message(f"The above is the CPI for {target}","-1002033782195")
driver.quit()
display.stop()
return True
def broadcast_all_fomc(target:str,date_target:str): #date_target = "20240131a"
startimee = time.time()
display = Display(visible=0, size=(1920, 1080))
display.start()
driver = webdriver.Chrome(options=options)
driver, date , message = find_fomc(driver,date_target)
while date != target:
@ -146,9 +166,12 @@ def broadcast_all_fomc(target:str,date_target:str): #date_target = "20240131a"
"-1002033782195")
broadcast_message(f"The above is the FOMC abstract for {target}","-1002033782195")
driver.quit()
display.stop()
return True
def broadcast_all_pce(target:str,date_target:str):
startimee = time.time()
display = Display(visible=0, size=(1920, 1080))
display.start()
driver = webdriver.Chrome(options=options)
driver, date, message1, message2 = find_pce(driver,date_target)
while date != target:
@ -164,9 +187,12 @@ def broadcast_all_pce(target:str,date_target:str):
"-1002033782195")
broadcast_message(f"The above is the PCE for {target}","-1002033782195")
driver.quit()
display.stop()
return True
def broadcast_pmi(date_target:str):
startimee = time.time()
display = Display(visible=0, size=(1920, 1080))
display.start()
driver = webdriver.Chrome(options=options)
driver, date, value = find_pmi(driver, date_target)
Up_date = date_target.capitalize()
@ -183,6 +209,7 @@ def broadcast_pmi(date_target:str):
"-1002033782195")
broadcast_message(f"The above is the PMI for {Up_date}","-1002033782195")
driver.quit()
display.stop()
return True
has_broadcasted = False
@ -206,6 +233,7 @@ def wrapper_function_fomc(target,date_target):
has_broadcasted = True
def wrapper_function_non_farm(target):
global has_broadcasted
time.sleep(55)
result = broadcast_all_non_farm(target)
if result:
@ -266,7 +294,7 @@ schedules = {
if __name__ == "__main__":
global nonfarm_url, cpi_url, fomc_url, pce_url, options
options = Options()
options.add_argument('--headless')
# options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
options.add_argument("--window-size=1920,1080") # 可以根據需要調整這個大小
@ -293,8 +321,9 @@ if __name__ == "__main__":
has_broadcasted = False
time.sleep(0.1) # Check every 0.1 seconds
#NonFarm
# date , message = find_non_farm(nonfarm_url)
# NonFarm
# driver = webdriver.Chrome(options=options)
# driver, date, message = find_non_farm(driver)
# print(date)
# print(message)
#CPI

Loading…
Cancel
Save