docker-compose.yml update

master
joey0629 1 year ago
parent e34fcc1d76
commit 3e68060a6c
  1. 14
      Dockerfile
  2. 31
      main.py

@ -3,6 +3,20 @@ FROM python:3.10
# Install Python and pip # Install Python and pip
RUN apt-get update && apt-get install -y python3 python3-pip && apt install nano RUN apt-get update && apt-get install -y python3 python3-pip && apt install nano
RUN apt-get update && apt-get install -y \
wget unzip \
&& rm -rf /var/lib/apt/lists/* \
&& wget https://chromedriver.storage.googleapis.com/2.41/chromedriver_linux64.zip \
&& unzip chromedriver_linux64.zip \
&& mv chromedriver /usr/local/bin/ \
&& chmod +x /usr/local/bin/chromedriver
# 安裝Google Chrome
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" | tee /etc/apt/sources.list.d/google-chrome.list \
&& apt-get update && apt-get install -y \
google-chrome-stable \
&& rm -rf /var/lib/apt/lists/*
# Set the working directory in the container # Set the working directory in the container
WORKDIR /app WORKDIR /app

@ -32,21 +32,24 @@ def find_indicate_bs4(url):
soup = BeautifulSoup(response.text, 'html.parser') soup = BeautifulSoup(response.text, 'html.parser')
# 使用CSS選擇器找到元素 # 使用CSS選擇器找到元素
element = soup.select("tr",class_ ='item-fact-row' ) # element = soup.select("tr",class_ ='item-fact-row' )
print(soup)
return element[1].text.split('+')[0]+" "+element[1].text.split('+')[1] # return element[1].text.split('+')[0]+" "+element[1].text.split('+')[1]
def find_indicate(url): def find_indicate(url):
from selenium import webdriver from selenium import webdriver
from selenium.webdriver.common.by import By from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time import time
options = Options() options = Options()
# options.add_argument("--headless") # 啟用無頭模式 # options.add_argument("--headless") # 啟用無頭模式
driver =webdriver.Chrome(options=options) driver =webdriver.Chrome(options=options)
driver.get(url) driver.get(url)
# time.sleep(3) # time.sleep(3)
chat = driver.find_element(By.XPATH, '//*[@id="home"]/div[2]/div/div/div[1]/table/tbody/tr[13]/td[6]') date = driver.find_element(By.XPATH, '//*[@id="test"]/div[2]/article/div/div/div[1]/div[2]/div/div[1]/div/table/tbody/tr[1]/td[1]')
return chat.text value = driver.find_element(By.XPATH, '//*[@id="test"]/div[2]/article/div/div/div[1]/div[2]/div/div[1]/div/table/tbody/tr[1]/td[2]')
return date.text , value.text
# 是一個持續運行的迴圈,不斷從Telegram伺服器抓取新的消息 # 是一個持續運行的迴圈,不斷從Telegram伺服器抓取新的消息
# 然後使用上面定義的消息處理器來處理這些消息。 # 然後使用上面定義的消息處理器來處理這些消息。
@ -93,13 +96,21 @@ def broadcast_all(target:str):
broadcast_message( broadcast_message(
f"Now :{datetime.fromtimestamp(time.time())} , Spend time :{str(round(endtimee - startimee, 3))} s", f"Now :{datetime.fromtimestamp(time.time())} , Spend time :{str(round(endtimee - startimee, 3))} s",
"-1002033782195") "-1002033782195")
def broadcast_all_sele(target:str):
startimee = time.time()
date , message = find_indicate("https://www.bea.gov/data/personal-consumption-expenditures-price-index")
while date.split(' ')[0] != target:
message = read_PCE()
broadcast_message(date+message, "-1002033782195")
endtimee = time.time()
broadcast_message(
f"Now :{datetime.fromtimestamp(time.time())} , Spend time :{str(round(endtimee - startimee, 3))} s",
"-1002033782195")
if __name__ == "__main__": if __name__ == "__main__":
#PCE #PCE
print("Start Time:" , datetime.fromtimestamp(time.time())) print("Start Time:" , datetime.fromtimestamp(time.time()))
schedule.every().day.at("20:05").do(broadcast_all) schedule.every().day.at("21:20").do(broadcast_all_sele, "December")
while True: while True:
if datetime.now().strftime("%Y-%m-%d %H:%M") == "2024-02-29 20:05": if datetime.now().strftime("%Y-%m-%d %H:%M") == "2024-02-29 21:20":
schedule.run_pending() schedule.run_pending()
time.sleep(0.1) # Check every 0.1 seconds time.sleep(0.1) # Check every 0.1 seconds
broadcast_all("December")
Loading…
Cancel
Save