fix: 增加重试机制

This commit is contained in:
chenwj113 2023-07-09 22:19:02 +08:00
parent 2d77f3ff51
commit bd5580ee4b
1 changed files with 8 additions and 3 deletions

11
main.py
View File

@ -1,5 +1,5 @@
import time import time
from retrying import retry
from schedule import every, repeat, run_pending from schedule import every, repeat, run_pending
from requests_html import HTML, HTMLSession from requests_html import HTML, HTMLSession
@ -8,11 +8,16 @@ from lottery import Lottery
session = HTMLSession() session = HTMLSession()
def get_data_job(lottery_type='pls'):
@retry(stop_max_attempt_number=5)
def get_data_job(lottery_type='pls', issue=None):
""" """
:param lottery_type :param lottery_type
""" """
url = f"https://kaijiang.500.com/{lottery_type}.shtml" if issue is None:
url = f"https://kaijiang.500.com/{lottery_type}.shtml"
else:
url = f"http://kaijiang.500.com/shtml/{lottery_type}/{issue}.shtml"
r = session.get(url) r = session.get(url)
if lottery_type == 'pls': if lottery_type == 'pls':
issue_elem = r.html.search('排列3 第 {}') issue_elem = r.html.search('排列3 第 {}')