From 16c7b2405d4ec2148370b28a40bff52f9bebae12 Mon Sep 17 00:00:00 2001 From: chenwj113 Date: Sun, 28 Apr 2024 22:52:09 +0800 Subject: [PATCH] =?UTF-8?q?bugfix:=20=E4=BF=AE=E6=94=B9=E5=AE=9A=E6=97=B6?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 2 +- docker-compose.yml | 2 ++ lottery/__init__.py | 2 +- main.py | 7 +++++++ requirements.txt | 4 +++- 5 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6f3afc3..442091a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -27,4 +27,4 @@ COPY . /app WORKDIR /app -CMD ["python", "main.py"] +CMD ["python", "-u", "main.py"] diff --git a/docker-compose.yml b/docker-compose.yml index be41175..06e1db9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,5 +5,7 @@ services: image: "schedule_tasks" container_name: "schedule_tasks" restart: always + extra_hosts: + - "host.docker.internal:172.17.0.1" # ports: # - "18000:8000" diff --git a/lottery/__init__.py b/lottery/__init__.py index 87466bf..4a59571 100644 --- a/lottery/__init__.py +++ b/lottery/__init__.py @@ -32,7 +32,7 @@ class Lottery(object): raise Exception("未知的lottery_type") def _get_db_session(self): - _engine = create_engine("mysql+pymysql://root:Chenweijia113!@172.17.0.1/lottery?charset=utf8", pool_pre_ping=True, pool_recycle=3600) + _engine = create_engine("mysql+pymysql://root:Chenweijia113!@host.docker.internal/lottery?charset=utf8", pool_pre_ping=True, pool_recycle=3600) _DbSession = sessionmaker(bind=_engine) return _DbSession() diff --git a/main.py b/main.py index d33e520..71a5054 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,5 @@ import time +from datetime import datetime from retrying import retry from schedule import every, repeat, run_pending from requests_html import HTML, HTMLSession @@ -41,14 +42,20 @@ def get_data_job(lottery_type='pls', issue=None): @repeat(every().day.at("00:01")) def pls_job(): + time_now = datetime.now() + print(f"当前任务运行时间为: {time_now.strftime('%H:%M:%S')}") get_data_job(lottery_type='pls') @repeat(every().day.at("00:02")) def plw_job(): + time_now = datetime.now() + print(f"当前任务运行时间为: {time_now.strftime('%H:%M:%S')}") get_data_job(lottery_type='plw') @repeat(every().day.at("00:03")) def sd_job(): + time_now = datetime.now() + print(f"当前任务运行时间为: {time_now.strftime('%H:%M:%S')}") get_data_job(lottery_type='sd') while True: diff --git a/requirements.txt b/requirements.txt index e9ab714..39dbcf9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,4 +5,6 @@ requests-html==0.10.0 retry==0.9.2 retrying==1.3.4 schedule==1.2.0 -SQLAlchemy==2.0.11 \ No newline at end of file +SQLAlchemy==2.0.11 +lxml==4.9.2 +cryptography==42.0.5 \ No newline at end of file