bugfix: 修改数据库连接错误
This commit is contained in:
parent
d871788891
commit
90ef582f10
|
|
@ -9,6 +9,9 @@ from lottery import Lottery
|
||||||
session = HTMLSession()
|
session = HTMLSession()
|
||||||
|
|
||||||
def get_data_job(lottery_type='pls'):
|
def get_data_job(lottery_type='pls'):
|
||||||
|
"""
|
||||||
|
:param lottery_type
|
||||||
|
"""
|
||||||
print("pls: I'm working...")
|
print("pls: I'm working...")
|
||||||
url = f"https://kaijiang.500.com/{lottery_type}.shtml"
|
url = f"https://kaijiang.500.com/{lottery_type}.shtml"
|
||||||
r = session.get(url)
|
r = session.get(url)
|
||||||
|
|
@ -22,10 +25,12 @@ def get_data_job(lottery_type='pls'):
|
||||||
draw_issue = HTML(html=issue_elem[0]).text
|
draw_issue = HTML(html=issue_elem[0]).text
|
||||||
draw_code = "".join(result)
|
draw_code = "".join(result)
|
||||||
print(f"result:{draw_code}")
|
print(f"result:{draw_code}")
|
||||||
lottery = Lottery(lottery_type=lottery_type)
|
with Lottery(lottery_type=lottery_type) as lottery:
|
||||||
last_id = lottery.insert(draw_issue, draw_date, draw_code)
|
last_id = lottery.insert(draw_issue, draw_date, draw_code)
|
||||||
if last_id:
|
if last_id:
|
||||||
print(f"issue:{draw_issue}数据写入完成。。。")
|
print(f"issue:{draw_issue}数据写入完成。。。")
|
||||||
|
else:
|
||||||
|
print(f'issue:{draw_issue}已经存在')
|
||||||
|
|
||||||
@repeat(every().day.at("00:01"))
|
@repeat(every().day.at("00:01"))
|
||||||
def pls_job():
|
def pls_job():
|
||||||
|
|
|
||||||
14
get_data.py
14
get_data.py
|
|
@ -8,19 +8,17 @@ session = HTMLSession()
|
||||||
|
|
||||||
@retry(stop_max_attempt_number=3)
|
@retry(stop_max_attempt_number=3)
|
||||||
def _get_data(url, lottery_type):
|
def _get_data(url, lottery_type):
|
||||||
lottery = Lottery(lottery_type=lottery_type)
|
|
||||||
r = session.get(url)
|
r = session.get(url)
|
||||||
table_list = r.html.find("table.kj_tablelist02", first=True)
|
table_list = r.html.find("table.kj_tablelist02", first=True)
|
||||||
draw_issue = table_list.find("td.td_title01 span.span_left strong")[0].text
|
draw_issue = table_list.find("td.td_title01 span.span_left strong")[0].text
|
||||||
draw_date = table_list.find("td.td_title01 span.span_right")[0].text
|
draw_date = table_list.find("td.td_title01 span.span_right")[0].text
|
||||||
draw_code = table_list.find("div.ball_box01")[0].text.replace('\n', '')
|
draw_code = table_list.find("div.ball_box01")[0].text.replace('\n', '')
|
||||||
print(draw_code)
|
with Lottery(lottery_type=lottery_type) as lottery:
|
||||||
print(draw_date)
|
last_id = lottery.insert(draw_issue, draw_date, draw_code)
|
||||||
last_id = lottery.insert(draw_issue, draw_date, draw_code)
|
if last_id:
|
||||||
if last_id:
|
print(f"issue:{draw_issue}数据写入完成。。。")
|
||||||
print(f"issue:{draw_issue}数据写入完成。。。")
|
else:
|
||||||
else:
|
print(f'issue:{draw_issue}已经存在')
|
||||||
print(f'issue:{draw_issue}已经存在')
|
|
||||||
|
|
||||||
def get_data(url, lottery_type):
|
def get_data(url, lottery_type):
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,12 @@ class Lottery(object):
|
||||||
_DbSession = sessionmaker(bind=_engine)
|
_DbSession = sessionmaker(bind=_engine)
|
||||||
return _DbSession()
|
return _DbSession()
|
||||||
|
|
||||||
|
def __enter__(self):
|
||||||
|
return self
|
||||||
|
|
||||||
|
def __exit__(self, type, value, trace):
|
||||||
|
self.db.close()
|
||||||
|
|
||||||
def insert(self, draw_issue, draw_date, draw_code, **kwargs):
|
def insert(self, draw_issue, draw_date, draw_code, **kwargs):
|
||||||
result = self.db.query(self._Model).filter_by(draw_issue=draw_issue).first()
|
result = self.db.query(self._Model).filter_by(draw_issue=draw_issue).first()
|
||||||
if result is None:
|
if result is None:
|
||||||
|
|
@ -83,4 +89,4 @@ class Lottery(object):
|
||||||
self.db.commit()
|
self.db.commit()
|
||||||
return record.id
|
return record.id
|
||||||
else:
|
else:
|
||||||
return result.id
|
return None
|
||||||
Loading…
Reference in New Issue