|
|
|
@ -117,6 +117,15 @@ def get_red_forecast(_all_data, _red_data_dict, _red_data, range_num=1): |
|
|
|
|
return _red_forecast_dict, _red_forecast_list |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_last_date_id(): |
|
|
|
|
conn = pymysql.connect(**db) |
|
|
|
|
curser = conn.cursor(DictCursor) |
|
|
|
|
curser.execute("SELECT * FROM history ORDER BY id DESC LIMIT 1") |
|
|
|
|
_data = curser.fetchone() |
|
|
|
|
# print(all_data) |
|
|
|
|
return _data['dateId'] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def update_red_forecast_db(): |
|
|
|
|
all_data = get_all_data() |
|
|
|
|
red_data = get_all_red() |
|
|
|
@ -128,12 +137,17 @@ def update_red_forecast_db(): |
|
|
|
|
red_suggest = json.dumps(sorted(red_forecast_list[0:6])) |
|
|
|
|
conn = pymysql.connect(**db) |
|
|
|
|
curser = conn.cursor(DictCursor) |
|
|
|
|
curser.execute() |
|
|
|
|
last_date_id = get_last_date_id() |
|
|
|
|
curser.execute("SELECT * FROM lottery.red_forecast WHERE dateId = %s", (last_date_id, )) |
|
|
|
|
have_duplicate = False if len(curser.fetchall()) == 0 else True |
|
|
|
|
if not have_duplicate: |
|
|
|
|
curser.execute( |
|
|
|
|
"INSERT INTO lottery.red_forecast (`dateId`, `params`, `red_rate`, `red_suggest`) VALUES (%s, %s, %s, %s)", |
|
|
|
|
(date_id, params, red_rate, red_suggest)) |
|
|
|
|
conn.commit() |
|
|
|
|
curser.close() |
|
|
|
|
else: |
|
|
|
|
print('数据库中有重复记录,无需重复插入') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
|
|