From 926c63fc7cae75e4460425bbc6088d6aaf73700e Mon Sep 17 00:00:00 2001 From: chenwj113 Date: Sun, 30 Apr 2023 12:21:07 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E5=AE=9A=E6=97=B6?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cron_tasks.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 cron_tasks.py diff --git a/cron_tasks.py b/cron_tasks.py new file mode 100644 index 0000000..b2f9197 --- /dev/null +++ b/cron_tasks.py @@ -0,0 +1,40 @@ +import time + +from schedule import every, repeat, run_pending +from requests_html import HTML, HTMLSession + +from lottery import Lottery + + +session = HTMLSession() + +def get_data_job(lottery_type='pls'): + print("pls: I'm working...") + url = f"https://kaijiang.500.com/{lottery_type}.shtml" + r = session.get(url) + if lottery_type == 'pls': + issue_elem = r.html.search('排列3 第 {}期') + else: + issue_elem = r.html.search('排列5 第 {}期') + draw_date = r.html.xpath('//td[@class="td_title01"]/span[@class="span_right"]/text()', first=True) + result = r.html.xpath('//li[@class="ball_orange"]/text()') + if issue_elem is not None and draw_date is not None and result is not None and len(result) != 0 : + draw_issue = HTML(html=issue_elem[0]).text + draw_code = "".join(result) + print(f"result:{draw_code}") + lottery = Lottery(lottery_type=lottery_type) + last_id = lottery.insert(draw_issue, draw_date, draw_code) + if last_id: + print(f"issue:{draw_issue}数据写入完成。。。") + +@repeat(every().day.at("00:01")) +def pls_job(): + get_data_job(lottery_type='pls') + +@repeat(every().day.at("00:02")) +def plw_job(): + get_data_job(lottery_type='plw') + +while True: + run_pending() + time.sleep(1) \ No newline at end of file