|
@@ -1,4 +1,5 @@
|
|
|
import datetime
|
|
import datetime
|
|
|
|
|
+import json
|
|
|
import time
|
|
import time
|
|
|
import hashlib
|
|
import hashlib
|
|
|
import redis
|
|
import redis
|
|
@@ -1735,3 +1736,598 @@ class BallStatuspipeline(object):
|
|
|
# self.conn.close()
|
|
# self.conn.close()
|
|
|
self.dbpool.close()
|
|
self.dbpool.close()
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+class Roll_Lanqiupipeline(object):
|
|
|
|
|
+ def open_spider(self, spider):
|
|
|
|
|
+ self.dbpool = adbapi.ConnectionPool("psycopg2",host=settings["POST_HOST"], port=settings['POST_PORT'], user=settings["POST_USER"], password=settings["POST_PASSWORD"], database=settings["POST_DATABASE"])
|
|
|
|
|
+ self.pool = redis.ConnectionPool(host=settings["R_HOST"], port=settings["R_POST"], password=settings["R_PASSWORD"])
|
|
|
|
|
+ self.redis_db = redis.StrictRedis(connection_pool=self.pool)
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ def process_item(self, item, spider):
|
|
|
|
|
+ # 使用twisted将mysql插入变成异步执行
|
|
|
|
|
+ query = self.dbpool.runInteraction(self.do_insert, item)
|
|
|
|
|
+ query.addErrback(self.handle_error, item, spider) # 处理异常
|
|
|
|
|
+
|
|
|
|
|
+ def handle_error(self, failure, item, spider):
|
|
|
|
|
+ # 处理异步插入的异常
|
|
|
|
|
+ print(failure)
|
|
|
|
|
+
|
|
|
|
|
+ def do_insert(self, cursor, item):
|
|
|
|
|
+ # 联赛id
|
|
|
|
|
+ league_id = item['league_id']
|
|
|
|
|
+ # 联赛名
|
|
|
|
|
+ league_name = item['league_name']
|
|
|
|
|
+ # result = item['result']
|
|
|
|
|
+ # 比赛id
|
|
|
|
|
+ game_id = item['game_id']
|
|
|
|
|
+ # 球队1 #home_team
|
|
|
|
|
+ team_home = item['team_home']
|
|
|
|
|
+ # 球队2 # guest_team
|
|
|
|
|
+ team_guest = item['team_guest']
|
|
|
|
|
+ # 数量(97>)
|
|
|
|
|
+ number = item['number']
|
|
|
|
|
+ # 比赛状态
|
|
|
|
|
+ zhuangtai = item['zhuangtai']
|
|
|
|
|
+ # 日期
|
|
|
|
|
+ # data_game = item['data_game']
|
|
|
|
|
+ data_game = item['data_game'].split("/")
|
|
|
|
|
+ month = str(data_game[1].strip())
|
|
|
|
|
+ day = str(data_game[0])
|
|
|
|
|
+ # 比赛时间
|
|
|
|
|
+ time_game = str(item['time_game'])
|
|
|
|
|
+ # 比赛时间,时间戳
|
|
|
|
|
+ ctime = "2019" + "-" + month + "-" + day + "" + time_game + ":00"
|
|
|
|
|
+ r_ctime = "2019" + "-" + month + "-" + day
|
|
|
|
|
+ expire_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time() + 60))#过期时间
|
|
|
|
|
+ # 现在时间,时间戳
|
|
|
|
|
+ utime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
|
|
|
|
|
+ # 队1分数
|
|
|
|
|
+ score_home = item['score_home']
|
|
|
|
|
+ # 队2分数
|
|
|
|
|
+ score_guest = item['score_guest']
|
|
|
|
|
+ # 第几节
|
|
|
|
|
+ jijie = item['jijie']
|
|
|
|
|
+ # 球队得分
|
|
|
|
|
+ qiudui = item['qiudui']
|
|
|
|
|
+ pt = item['pt']
|
|
|
|
|
+ match_score = "{}:{}".format(score_home,score_guest)
|
|
|
|
|
+ concedes_dict = item['concede']
|
|
|
|
|
+ concedes_dict_rule = item['concede_rule']
|
|
|
|
|
+ odd_evens_dict = item['odd_even']
|
|
|
|
|
+ odd_evens_dict_rule = item['odd_even_rule']
|
|
|
|
|
+ total_sizes_dict = item['total_size']
|
|
|
|
|
+ total_sizes_dict_rule = item['total_size_rule']
|
|
|
|
|
+ last_numbers_dict = item['last_number']
|
|
|
|
|
+ capots_dict = item['capot']
|
|
|
|
|
+ team_scores_dict = item['team_score']
|
|
|
|
|
+ team_scores_dict_rule = item['team_score_rule']
|
|
|
|
|
+ if concedes_dict:
|
|
|
|
|
+ for key, value in concedes_dict.items():
|
|
|
|
|
+ if value:
|
|
|
|
|
+ for x, y in enumerate(value):
|
|
|
|
|
+ new_hash = hash_func(match_id=game_id, odds_code=key, sort=x, p_id=1)
|
|
|
|
|
+ odds_only = r_func(match_id=game_id, odds_code=key, sort=x, p_id=1,odd=y)
|
|
|
|
|
+ sql1 = "insert into st_lq_odds(lg_id, odds_code, match_id, ctime, utime, odds, p_id, p_code, sort, source, sole,condition,odds_only,is_rollball) values (%s, %s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s, %s,%s) on conflict(sole) do update set utime = %s,odds = %s,odds_only =%s;"
|
|
|
|
|
+ cursor.execute(sql1, (int(league_id), key, int(game_id), utime, utime, y, 1, "concede",x, "hg3535", new_hash, concedes_dict_rule[key][x],odds_only,1,utime, y,odds_only))
|
|
|
|
|
+ # res = cursor.fetchone()
|
|
|
|
|
+ # 更新主队st_zq_odds_record表
|
|
|
|
|
+ sql2 = "insert into st_lq_odds_record(lg_id, odds_code, match_id, ctime, utime, odds, p_id, p_code, sort, source, condition,odds_only,is_rollball) values (%s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s,%s,%s);"
|
|
|
|
|
+ cursor.execute(sql2, (int(league_id), key, int(game_id), utime, utime,y, 1, "concede", x, "hg3535", concedes_dict_rule[key][x],odds_only,1))
|
|
|
|
|
+ #插入结果表
|
|
|
|
|
+ sql3 = "insert into st_lq_result(lg_id, home_team, guest_team, home_score, guest_score, all_goal, first_score, last_score,match_score,match_winer,update_time,match_time,match_process,tag,match_id,u_home_score,u_guest_score,source) values (%s, %s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s, %s,%s,%s,%s,%s,%s) on conflict(match_id) do update set update_time = %s,match_score = %s,match_time =%s,match_process =%s,home_score =%s,guest_score =%s;"
|
|
|
|
|
+ cursor.execute(sql3, (int(league_id), team_home, team_guest,score_home, score_guest, number, '', '',match_score,'',utime,time_game,jijie,number,int(game_id),0,0,'hg3535',utime,match_score,time_game,jijie,score_home,score_guest))
|
|
|
|
|
+ #插入记录表
|
|
|
|
|
+ sql4 = "insert into st_lq_result_record(lg_id, home_team, guest_team, home_score, guest_score, first_score, last_score,match_score,match_winer,update_time,match_time,match_process,tag,match_id,source,status) values (%s, %s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s, %s,%s,%s,%s);"
|
|
|
|
|
+ cursor.execute(sql4, (int(league_id), team_home, team_guest,score_home, score_guest, '', '',match_score,'',utime,time_game,jijie,number,int(game_id),'hg3535',0))
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ if odd_evens_dict:
|
|
|
|
|
+ for key, value in odd_evens_dict.items():
|
|
|
|
|
+ if value:
|
|
|
|
|
+ for x, y in enumerate(value):
|
|
|
|
|
+ new_hash = hash_func(match_id=game_id, odds_code=key, sort=x, p_id=2)
|
|
|
|
|
+ odds_only = r_func(match_id=game_id, odds_code=key, sort=x, p_id=2,odd=y)
|
|
|
|
|
+ sql1 = "insert into st_lq_odds(lg_id, odds_code, match_id, ctime, utime,odds, p_id, p_code, sort, source, sole,condition,odds_only,is_rollball) values (%s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s, %s,%s,%s) on conflict(sole) do update set utime = %s,odds = %s,odds_only =%s;"
|
|
|
|
|
+ cursor.execute(sql1, (int(league_id), key, int(game_id), utime, utime,y, 2, "two_sides",x, "hg3535", new_hash, odd_evens_dict_rule[key][x],odds_only,1,utime, y,odds_only))
|
|
|
|
|
+ # 更新主队st_zq_odds_record表
|
|
|
|
|
+ sql2 = "insert into st_lq_odds_record(lg_id, odds_code, match_id, ctime, utime,odds, p_id, p_code, sort, source, condition,odds_only,is_rollball) values (%s, %s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s,%s);"
|
|
|
|
|
+ cursor.execute(sql2, (int(league_id), key, int(game_id), utime, utime,y, 2, "two_sides", x, "hg3535", odd_evens_dict_rule[key][x],odds_only,1))
|
|
|
|
|
+ sql3 = "insert into st_lq_result(lg_id, home_team, guest_team, home_score, guest_score, all_goal, first_score, last_score,match_score,match_winer,update_time,match_time,match_process,tag,match_id,u_home_score,u_guest_score,source) values (%s, %s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s, %s,%s,%s,%s,%s,%s) on conflict(match_id) do update set update_time = %s,match_score = %s,match_time =%s,match_process =%s,home_score =%s,guest_score =%s;"
|
|
|
|
|
+ cursor.execute(sql3, (int(league_id), team_home, team_guest,score_home, score_guest, number, '', '',match_score,'',utime,time_game,jijie,number,int(game_id),0,0,'hg3535',utime,match_score,time_game,jijie,score_home,score_guest))
|
|
|
|
|
+ #插入记录表
|
|
|
|
|
+ sql4 = "insert into st_lq_result_record(lg_id, home_team, guest_team, home_score, guest_score, first_score, last_score,match_score,match_winer,update_time,match_time,match_process,tag,match_id,source,status) values (%s, %s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s, %s,%s,%s,%s);"
|
|
|
|
|
+ cursor.execute(sql4, (int(league_id), team_home, team_guest,score_home, score_guest, '', '',match_score,'',utime,time_game,jijie,number,int(game_id),'hg3535',0))
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ if total_sizes_dict:
|
|
|
|
|
+ for key, value in total_sizes_dict.items():
|
|
|
|
|
+ if value:
|
|
|
|
|
+ for x, y in enumerate(value):
|
|
|
|
|
+ new_hash = hash_func(match_id=game_id, odds_code=key, sort=x, p_id=3)
|
|
|
|
|
+ odds_only = r_func(match_id=game_id, odds_code=key, sort=x, p_id=3,odd=y)
|
|
|
|
|
+ sql1 = "insert into st_lq_odds(lg_id, odds_code, match_id, ctime, utime,odds, p_id, p_code, sort, source, sole,condition,odds_only,is_rollball) values (%s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s, %s,%s,%s) on conflict(sole) do update set utime = %s,odds = %s,odds_only =%s;"
|
|
|
|
|
+ cursor.execute(sql1, (int(league_id), key, int(game_id), utime, utime,y, 3, "total_size",x, "hg3535", new_hash, total_sizes_dict_rule[key][x],odds_only,1,utime, y,odds_only))
|
|
|
|
|
+ # 更新主队st_zq_odds_record表
|
|
|
|
|
+ sql2 = "insert into st_lq_odds_record(lg_id, odds_code, match_id, ctime, utime,odds, p_id, p_code, sort, source, condition,odds_only,is_rollball) values (%s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s,%s,%s);"
|
|
|
|
|
+ cursor.execute(sql2, (int(league_id), key, int(game_id), utime, utime, y, 3, "total_size", x, "hg3535", total_sizes_dict_rule[key][x],odds_only,1))
|
|
|
|
|
+ sql3 = "insert into st_lq_result(lg_id, home_team, guest_team, home_score, guest_score, all_goal, first_score, last_score,match_score,match_winer,update_time,match_time,match_process,tag,match_id,u_home_score,u_guest_score,source) values (%s, %s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s, %s,%s,%s,%s,%s,%s) on conflict(match_id) do update set update_time = %s,match_score = %s,match_time =%s,match_process =%s,home_score =%s,guest_score =%s;"
|
|
|
|
|
+ cursor.execute(sql3, (int(league_id), team_home, team_guest,score_home, score_guest, number, '', '',match_score,'',utime,time_game,jijie,number,int(game_id),0,0,'hg3535',utime,match_score,time_game,jijie,score_home,score_guest))
|
|
|
|
|
+ #插入记录表
|
|
|
|
|
+ sql4 = "insert into st_lq_result_record(lg_id, home_team, guest_team, home_score, guest_score, first_score, last_score,match_score,match_winer,update_time,match_time,match_process,tag,match_id,source,status) values (%s, %s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s, %s,%s,%s,%s);"
|
|
|
|
|
+ cursor.execute(sql4, (int(league_id), team_home, team_guest,score_home, score_guest, '', '',match_score,'',utime,time_game,jijie,number,int(game_id),'hg3535',0))
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ last_home = last_numbers_dict['last_home']
|
|
|
|
|
+ if last_home:
|
|
|
|
|
+ for key, value in last_home.items():
|
|
|
|
|
+ if value:
|
|
|
|
|
+ new_hash = hash_func(match_id=game_id, odds_code="last_home" + key, sort=0, p_id=4)
|
|
|
|
|
+ odds_only = r_func(match_id=game_id, odds_code="last_home", sort=0, p_id=4,odd=value)
|
|
|
|
|
+ sql1 = "insert into st_lq_odds(lg_id, odds_code, match_id, ctime, utime,odds, p_id, p_code, sort, source, sole,condition,odds_only,is_rollball) values (%s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s, %s,%s,%s) on conflict(sole) do update set utime = %s,odds = %s,odds_only=%s;"
|
|
|
|
|
+ cursor.execute(sql1, (int(league_id), "last_home", int(game_id), utime, utime, value, 4, "last_number",0, "hg3535", new_hash, key,odds_only,1,utime, value,odds_only))
|
|
|
|
|
+ # 更新主队st_zq_odds_record表
|
|
|
|
|
+ sql2 = "insert into st_lq_odds_record(lg_id, odds_code, match_id, ctime, utime,odds, p_id, p_code, sort, source, condition,odds_only,is_rollball) values (%s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s,%s,%s);"
|
|
|
|
|
+ cursor.execute(sql2, (int(league_id), "last_home", int(game_id), utime, utime,value, 4, "last_number", 0, "hg3535", key,odds_only,1))
|
|
|
|
|
+ sql3 = "insert into st_lq_result(lg_id, home_team, guest_team, home_score, guest_score, all_goal, first_score, last_score,match_score,match_winer,update_time,match_time,match_process,tag,match_id,u_home_score,u_guest_score,source) values (%s, %s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s, %s,%s,%s,%s,%s,%s) on conflict(match_id) do update set update_time = %s,match_score = %s,match_time =%s,match_process =%s,home_score =%s,guest_score =%s;"
|
|
|
|
|
+ cursor.execute(sql3, (int(league_id), team_home, team_guest,score_home, score_guest, number, '', '',match_score,'',utime,time_game,jijie,number,int(game_id),0,0,'hg3535',utime,match_score,time_game,jijie,score_home,score_guest))
|
|
|
|
|
+ #插入记录表
|
|
|
|
|
+ sql4 = "insert into st_lq_result_record(lg_id, home_team, guest_team, home_score, guest_score, first_score, last_score,match_score,match_winer,update_time,match_time,match_process,tag,match_id,source,status) values (%s, %s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s, %s,%s,%s,%s);"
|
|
|
|
|
+ cursor.execute(sql4, (int(league_id), team_home, team_guest,score_home, score_guest, '', '',match_score,'',utime,time_game,jijie,number,int(game_id),'hg3535',0))
|
|
|
|
|
+
|
|
|
|
|
+ last_guest = last_numbers_dict['last_guest']
|
|
|
|
|
+ if last_guest:
|
|
|
|
|
+ for key, value in last_guest.items():
|
|
|
|
|
+ if value:
|
|
|
|
|
+ new_hash = hash_func(match_id=game_id, odds_code="last_guest" + key, sort=0, p_id=4)
|
|
|
|
|
+ odds_only = r_func(match_id=game_id, odds_code="last_guest", sort=0, p_id=4,odd=value)
|
|
|
|
|
+ sql1 = "insert into st_lq_odds(lg_id, odds_code, match_id, ctime, utime,odds, p_id, p_code, sort, source, sole,condition,odds_only,is_rollball) values (%s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s, %s,%s,%s) on conflict(sole) do update set utime = %s,odds = %s,odds_only=%s;"
|
|
|
|
|
+ cursor.execute(sql1, (int(league_id), "last_guest", int(game_id), utime, utime, value, 4, "last_number",0, "hg3535", new_hash, key,odds_only,1,utime, value,odds_only))
|
|
|
|
|
+ # 更新主队st_zq_odds_record表
|
|
|
|
|
+ sql2 = "insert into st_lq_odds_record(lg_id, odds_code, match_id, ctime, utime,odds, p_id, p_code, sort, source, condition,odds_only,is_rollball) values (%s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s,%s,%s);"
|
|
|
|
|
+ cursor.execute(sql2, (int(league_id), "last_guest", int(game_id), utime, utime,value, 4, "last_number", 0, "hg3535", key,odds_only,1))
|
|
|
|
|
+ sql3 = "insert into st_lq_result(lg_id, home_team, guest_team, home_score, guest_score, all_goal, first_score, last_score,match_score,match_winer,update_time,match_time,match_process,tag,match_id,u_home_score,u_guest_score,source) values (%s, %s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s, %s,%s,%s,%s,%s,%s) on conflict(match_id) do update set update_time = %s,match_score = %s,match_time =%s,match_process =%s,home_score =%s,guest_score =%s;"
|
|
|
|
|
+ cursor.execute(sql3, (int(league_id), team_home, team_guest,score_home, score_guest, number, '', '',match_score,'',utime,time_game,jijie,number,int(game_id),0,0,'hg3535',utime,match_score,time_game,jijie,score_home,score_guest))
|
|
|
|
|
+ #插入记录表
|
|
|
|
|
+ sql4 = "insert into st_lq_result_record(lg_id, home_team, guest_team, home_score, guest_score, first_score, last_score,match_score,match_winer,update_time,match_time,match_process,tag,match_id,source,status) values (%s, %s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s, %s,%s,%s,%s);"
|
|
|
|
|
+ cursor.execute(sql4, (int(league_id), team_home, team_guest,score_home, score_guest, '', '',match_score,'',utime,time_game,jijie,number,int(game_id),'hg3535',0))
|
|
|
|
|
+
|
|
|
|
|
+ if capots_dict:
|
|
|
|
|
+ for key, value in capots_dict.items():
|
|
|
|
|
+ if value:
|
|
|
|
|
+ new_hash = hash_func(match_id=game_id, odds_code=key, sort=0, p_id=5)
|
|
|
|
|
+ odds_only = r_func(match_id=game_id, odds_code=key, sort=0, p_id=5,odd=value)
|
|
|
|
|
+ sql1 = "insert into st_lq_odds(lg_id, odds_code, match_id, ctime, utime, odds, p_id, p_code, sort, source, sole,odds_only,is_rollball) values (%s, %s, %s, %s, %s,%s, %s, %s, %s, %s, %s,%s,%s) on conflict(sole) do update set utime = %s,odds = %s,odds_only =%s;"
|
|
|
|
|
+ cursor.execute(sql1, (int(league_id), key, int(game_id), utime, utime, value, 5, "capot",0, "hg3535", new_hash, odds_only,1,utime, value,odds_only))
|
|
|
|
|
+ # 更新主队st_zq_odds_record表
|
|
|
|
|
+ sql2 = "insert into st_lq_odds_record(lg_id, odds_code, match_id, ctime, utime,odds, p_id, p_code, sort, source,odds_only,is_rollball) values (%s, %s, %s, %s, %s,%s, %s, %s, %s, %s,%s,%s);"
|
|
|
|
|
+ cursor.execute(sql2, (int(league_id), key, int(game_id), utime, utime, value, 5, "capot", 0, "hg3535",odds_only,1))
|
|
|
|
|
+ sql3 = "insert into st_lq_result(lg_id, home_team, guest_team, home_score, guest_score, all_goal, first_score, last_score,match_score,match_winer,update_time,match_time,match_process,tag,match_id,u_home_score,u_guest_score,source) values (%s, %s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s, %s,%s,%s,%s,%s,%s) on conflict(match_id) do update set update_time = %s,match_score = %s,match_time =%s,match_process =%s,home_score =%s,guest_score =%s;"
|
|
|
|
|
+ cursor.execute(sql3, (int(league_id), team_home, team_guest,score_home, score_guest, number, '', '',match_score,'',utime,time_game,jijie,number,int(game_id),0,0,'hg3535',utime,match_score,time_game,jijie,score_home,score_guest))
|
|
|
|
|
+ #插入记录表
|
|
|
|
|
+ sql4 = "insert into st_lq_result_record(lg_id, home_team, guest_team, home_score, guest_score, first_score, last_score,match_score,match_winer,update_time,match_time,match_process,tag,match_id,source,status) values (%s, %s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s, %s,%s,%s,%s);"
|
|
|
|
|
+ cursor.execute(sql4, (int(league_id), team_home, team_guest,score_home, score_guest, '', '',match_score,'',utime,time_game,jijie,number,int(game_id),'hg3535',0))
|
|
|
|
|
+
|
|
|
|
|
+ if team_scores_dict:
|
|
|
|
|
+ for key, value in team_scores_dict.items():
|
|
|
|
|
+ if value:
|
|
|
|
|
+ for x, y in enumerate(value):
|
|
|
|
|
+ new_hash = hash_func(match_id=game_id, odds_code=key, sort=x, p_id=6)
|
|
|
|
|
+ odds_only = r_func(match_id=game_id, odds_code=key, sort=x, p_id=6,odd=y)
|
|
|
|
|
+ sql1 = "insert into st_lq_odds(lg_id, odds_code, match_id, ctime, utime,odds, p_id, p_code, sort, source, sole,condition,odds_only,is_rollball) values (%s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s, %s,%s,%s) on conflict(sole) do update set utime = %s,odds = %s,odds_only=%s;"
|
|
|
|
|
+ cursor.execute(sql1, (int(league_id), key, int(game_id), utime, utime, y, 6, "team_score", x, "hg3535", new_hash,team_scores_dict_rule[key][x], odds_only,1,utime, y,odds_only))
|
|
|
|
|
+ # 更新主队st_zq_odds_record表
|
|
|
|
|
+ sql2 = "insert into st_lq_odds_record(lg_id, odds_code, match_id, ctime, utime,odds, p_id, p_code, sort, source, condition,odds_only,is_rollball) values (%s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s,%s,%s);"
|
|
|
|
|
+ cursor.execute(sql2, (int(league_id), key, int(game_id), utime, utime,y, 6, "team_score", x, "hg3535",team_scores_dict_rule[key][x],odds_only,1))
|
|
|
|
|
+ sql3 = "insert into st_lq_result(lg_id, home_team, guest_team, home_score, guest_score, all_goal, first_score, last_score,match_score,match_winer,update_time,match_time,match_process,tag,match_id,u_home_score,u_guest_score,source) values (%s, %s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s, %s,%s,%s,%s,%s,%s) on conflict(match_id) do update set update_time = %s,match_score = %s,match_time =%s,match_process =%s,home_score =%s,guest_score =%s;"
|
|
|
|
|
+ cursor.execute(sql3, (int(league_id), team_home, team_guest,score_home, score_guest, number, '', '',match_score,'',utime,time_game,jijie,number,int(game_id),0,0,'hg3535',utime,match_score,time_game,jijie,score_home,score_guest))
|
|
|
|
|
+ #插入记录表
|
|
|
|
|
+ sql4 = "insert into st_lq_result_record(lg_id, home_team, guest_team, home_score, guest_score, first_score, last_score,match_score,match_winer,update_time,match_time,match_process,tag,match_id,source,status) values (%s, %s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s, %s,%s,%s,%s);"
|
|
|
|
|
+ cursor.execute(sql4, (int(league_id), team_home, team_guest,score_home, score_guest, '', '',match_score,'',utime,time_game,jijie,number,int(game_id),'hg3535',0))
|
|
|
|
|
+ # 插入赛事表
|
|
|
|
|
+ Competition_sql = "insert into st_lq_competition(home_team, guest_team, lg_id, match_id, match_date, match_time,ctime, utime, tag,type,source,expire_time,is_rollball) values (%s, %s, %s, %s, %s, %s, %s, %s,%s, %s, %s,%s,%s) on conflict(match_id) do update set tag = %s,expire_time = %s;"
|
|
|
|
|
+ print(Competition_sql)
|
|
|
|
|
+ cursor.execute(Competition_sql, (team_home, team_guest, league_id, game_id, r_ctime, time_game, utime, utime, number, pt, "hg3535",expire_time,1,number,expire_time))
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ def close_spider(self, spider):
|
|
|
|
|
+ self.dbpool.close()
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def new_times(ctime):
|
|
|
|
|
+ time1 = time.mktime(time.strptime(ctime, '%Y-%m-%d %H:%M:%S')) + 43200
|
|
|
|
|
+ time2 = time.localtime(time1)
|
|
|
|
|
+ time3 = time.strftime('%Y-%m-%d %H:%M:%S', time2)
|
|
|
|
|
+ data_time = str(time3).split(" ")
|
|
|
|
|
+ match_date = data_time[0]
|
|
|
|
|
+ match_time = data_time[1]
|
|
|
|
|
+ return match_date,match_time
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+class Roll_Wangqiupipeline(object):
|
|
|
|
|
+ def open_spider(self, spider):
|
|
|
|
|
+ self.dbpool = adbapi.ConnectionPool("psycopg2",host=settings["POST_HOST"], port=settings['POST_PORT'], user=settings["POST_USER"], password=settings["POST_PASSWORD"], database=settings["POST_DATABASE"])
|
|
|
|
|
+ self.pool = redis.ConnectionPool(host=settings["R_HOST"], port=settings["R_POST"], password=settings["R_PASSWORD"])
|
|
|
|
|
+ self.redis_db = redis.StrictRedis(connection_pool=self.pool)
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ def process_item(self, item, spider):
|
|
|
|
|
+ # 使用twisted将mysql插入变成异步执行
|
|
|
|
|
+ query = self.dbpool.runInteraction(self.do_insert, item)
|
|
|
|
|
+ query.addErrback(self.handle_error, item, spider) # 处理异常
|
|
|
|
|
+
|
|
|
|
|
+ def handle_error(self, failure, item, spider):
|
|
|
|
|
+ # 处理异步插入的异常
|
|
|
|
|
+ print(failure)
|
|
|
|
|
+
|
|
|
|
|
+ def do_insert(self, cursor, item):
|
|
|
|
|
+ # 联赛id
|
|
|
|
|
+ league_id = item['league_id']
|
|
|
|
|
+ # 联赛名
|
|
|
|
|
+ league_name = item['league_name']
|
|
|
|
|
+ # result = item['result']
|
|
|
|
|
+ # 比赛id
|
|
|
|
|
+ game_id = item['game_id']
|
|
|
|
|
+ # 球队1
|
|
|
|
|
+ team_home = item['team_home']
|
|
|
|
|
+ # 球队2
|
|
|
|
|
+ team_guest = item['team_guest']
|
|
|
|
|
+ # 数量(97>)
|
|
|
|
|
+ number = item['number']
|
|
|
|
|
+ # 比赛状态
|
|
|
|
|
+ zhuangtai = item['zhuangtai']
|
|
|
|
|
+ # 日期
|
|
|
|
|
+ # data_game = item['data_game']
|
|
|
|
|
+ data_game = item['data_game'].split("/")
|
|
|
|
|
+ month = str(data_game[1].strip())
|
|
|
|
|
+ day = str(data_game[0])
|
|
|
|
|
+ # 比赛时间
|
|
|
|
|
+ time_game = str(item['time_game'])
|
|
|
|
|
+ # 比赛时间,时间戳
|
|
|
|
|
+ ctime = "2019" + "-" + month + "-" + day + "" + time_game + ":00"
|
|
|
|
|
+ r_ctime = "2019" + "-" + month + "-" + day
|
|
|
|
|
+ # 现在时间,时间戳
|
|
|
|
|
+ utime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
|
|
|
|
|
+ # 队1分数
|
|
|
|
|
+ score_home = item['score_home']
|
|
|
|
|
+ # 队2分数
|
|
|
|
|
+ score_guest = item['score_guest']
|
|
|
|
|
+ # 第几节
|
|
|
|
|
+ jijie = item['jijie']
|
|
|
|
|
+ # 球队得分
|
|
|
|
|
+ qiudui = item['qiudui']
|
|
|
|
|
+ pt = item['pt']
|
|
|
|
|
+ #取不到 暂时注掉
|
|
|
|
|
+ match_date, match_time = new_times(ctime)
|
|
|
|
|
+ # 让盘
|
|
|
|
|
+ concedes_dict = item['concedes_dict']
|
|
|
|
|
+ concedes_dict_rule = item['concedes_dict_rule']
|
|
|
|
|
+ # 冠军 独赢
|
|
|
|
|
+ kemps_dict = item['kemps_dict']
|
|
|
|
|
+ # 让局
|
|
|
|
|
+ bureaus_dict = item['bureaus_dict']
|
|
|
|
|
+ bureaus_dict_rule = item['bureaus_dict_rule']
|
|
|
|
|
+ # 总局数大小
|
|
|
|
|
+ total_number_dict = item['total_number_dict']
|
|
|
|
|
+ total_number_dict_rule = item['total_number_dict_rule']
|
|
|
|
|
+ # 总局数单双
|
|
|
|
|
+ odd_evens_dict = item['odd_evens_dict']
|
|
|
|
|
+ odd_evens_dict_rule = item['odd_evens_dict_rule']
|
|
|
|
|
+ if concedes_dict:
|
|
|
|
|
+ for key, value in concedes_dict.items():
|
|
|
|
|
+ if value:
|
|
|
|
|
+ new_hash = hash_func(match_id=game_id, odds_code=key, sort=0, p_id=1)
|
|
|
|
|
+ odds_only = r_func(match_id=game_id, odds_code=key, sort=0, p_id=1,odd=value)
|
|
|
|
|
+ sql1 = "insert into st_wq_odds(lg_id, odds_code, match_id, ctime, utime, odds, p_id, p_code, sort, source, sole,condition,odds_only,is_rollball) values (%s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s, %s,%s,%s) on conflict(sole) do update set utime = %s,odds = %s,odds_only=%s;"
|
|
|
|
|
+ cursor.execute(sql1, (
|
|
|
|
|
+ int(league_id), key, int(game_id), utime, utime,value, 1, "dishes_home", 0, "hg3535", new_hash,
|
|
|
|
|
+ concedes_dict_rule[key],odds_only,1,utime, value,odds_only))
|
|
|
|
|
+ # 更新主队st_zq_odds_record表
|
|
|
|
|
+ sql2 = "insert into st_wq_odds_record(lg_id, odds_code, match_id, ctime, utime, odds, p_id, p_code, sort, source, condition,odds_only,is_rollball) values (%s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s,%s,%s);"
|
|
|
|
|
+ cursor.execute(sql2, (
|
|
|
|
|
+ int(league_id), key, int(game_id), utime, utime, value, 1, "dishes_home", 0, "hg3535",
|
|
|
|
|
+ concedes_dict_rule[key],odds_only,1))
|
|
|
|
|
+ #插入结果表
|
|
|
|
|
+ sql3 = "insert into st_wq_result(lg_id, home_player_name, guest_player_name, home_player_let_plate, guest_player_let_plate, all_inning,home_player_score,guest_player_score,status,first_score_player,last_score_player,first_inning_score,second_inning_score,third_inning_score,match_winer_player,update_time,match_process,tag,match_id,source,match_time) values (%s, %s, %s, %s, %s,%s, %s, %s, %s, %s, %s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s) on conflict(match_id) do update set update_time = %s,match_process =%s,home_player_score =%s,guest_player_score =%s;"
|
|
|
|
|
+ cursor.execute(sql3, (int(league_id), team_home, team_guest,int(score_home), int(score_guest), 0, score_home,score_guest,1,'','','','','','',utime,jijie,number,game_id,'hg3535','00:00',utime,jijie,score_home,score_guest))
|
|
|
|
|
+ # 插入记录表
|
|
|
|
|
+ sql4 = "insert into st_wq_result_record(lg_id, home_player_name, guest_player_name, home_player_let_plate, guest_player_let_plate, all_inning,home_player_score,guest_player_score,status,first_score_player,last_score_player,first_inning_score,second_inning_score,third_inning_score,match_winer_player,update_time,match_process,tag,match_id,source,match_time) values (%s, %s, %s, %s, %s,%s, %s, %s, %s, %s, %s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s);"
|
|
|
|
|
+ cursor.execute(sql4, (int(league_id), team_home, team_guest,int(score_home), int(score_guest), 0, score_home,score_guest,1,'','','','','','',utime,jijie,number,game_id,'hg3535','00:00'))
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ if kemps_dict:
|
|
|
|
|
+ for key, value in kemps_dict.items():
|
|
|
|
|
+ if value:
|
|
|
|
|
+ new_hash = hash_func(match_id=game_id, odds_code=key, sort=0, p_id=2)
|
|
|
|
|
+ odds_only = r_func(match_id=game_id, odds_code=key, sort=0, p_id=2,odd=value)
|
|
|
|
|
+ sql1 = "insert into st_wq_odds(lg_id, odds_code, match_id, ctime, utime, odds, p_id, p_code, sort, source, sole,odds_only,is_rollball) values (%s, %s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s,%s) on conflict(sole) do update set utime = %s,odds = %s,odds_only=%s;"
|
|
|
|
|
+ cursor.execute(sql1, (
|
|
|
|
|
+ int(league_id), key, int(game_id), utime, utime, value, 2, "kemp", 0, "hg3535", new_hash,odds_only,1,utime, value,odds_only))
|
|
|
|
|
+ # 更新主队st_zq_odds_record表
|
|
|
|
|
+ sql2 = "insert into st_wq_odds_record(lg_id, odds_code, match_id, ctime, utime, odds, p_id, p_code, sort, source,odds_only,is_rollball) values (%s, %s, %s, %s, %s, %s,%s, %s, %s, %s,%s,%s);"
|
|
|
|
|
+ cursor.execute(sql2, (
|
|
|
|
|
+ int(league_id), key, int(game_id), utime, utime,value, 2, "kemp", 0, "hg3535",odds_only,1))
|
|
|
|
|
+
|
|
|
|
|
+ sql3 = "insert into st_wq_result(lg_id, home_player_name, guest_player_name, home_player_let_plate, guest_player_let_plate, all_inning,home_player_score,guest_player_score,status,first_score_player,last_score_player,first_inning_score,second_inning_score,third_inning_score,match_winer_player,update_time,match_process,tag,match_id,source,match_time) values (%s, %s, %s, %s, %s,%s, %s, %s, %s, %s, %s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s) on conflict(match_id) do update set update_time = %s,match_process =%s,home_player_score =%s,guest_player_score =%s;"
|
|
|
|
|
+ cursor.execute(sql3, (int(league_id), team_home, team_guest,int(score_home), int(score_guest), 0, score_home,score_guest,1,'','','','','','',utime,jijie,number,game_id,'hg3535','00:00',utime,jijie,score_home,score_guest))
|
|
|
|
|
+
|
|
|
|
|
+ if bureaus_dict:
|
|
|
|
|
+ for key, value in bureaus_dict.items():
|
|
|
|
|
+ if value:
|
|
|
|
|
+ new_hash = hash_func(match_id=game_id, odds_code=key, sort=0, p_id=3)
|
|
|
|
|
+ odds_only = r_func(match_id=game_id, odds_code=key, sort=0, p_id=3,odd=value)
|
|
|
|
|
+ sql1 = "insert into st_wq_odds(lg_id, odds_code, match_id, ctime, utime, odds, p_id, p_code, sort, source, sole,condition,odds_only,is_rollball) values (%s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s, %s,%s,%s) on conflict(sole) do update set utime = %s,odds = %s,odds_only =%s;"
|
|
|
|
|
+ cursor.execute(sql1, (
|
|
|
|
|
+ int(league_id), key, int(game_id), utime, utime, value, 3, "concede", 0, "hg3535", new_hash,
|
|
|
|
|
+ bureaus_dict_rule[key],odds_only,1,utime, value,odds_only))
|
|
|
|
|
+ # 更新主队st_zq_odds_record表
|
|
|
|
|
+ sql2 = "insert into st_wq_odds_record(lg_id, odds_code, match_id, ctime, utime, odds, p_id, p_code, sort, source, condition,odds_only,is_rollball) values (%s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s,%s,%s);"
|
|
|
|
|
+ cursor.execute(sql2, (
|
|
|
|
|
+ int(league_id), key, int(game_id), utime, utime,value, 3, "concede", 0, "hg3535",
|
|
|
|
|
+ bureaus_dict_rule[key],odds_only,1))
|
|
|
|
|
+ sql3 = "insert into st_wq_result(lg_id, home_player_name, guest_player_name, home_player_let_plate, guest_player_let_plate, all_inning,home_player_score,guest_player_score,status,first_score_player,last_score_player,first_inning_score,second_inning_score,third_inning_score,match_winer_player,update_time,match_process,tag,match_id,source,match_time) values (%s, %s, %s, %s, %s,%s, %s, %s, %s, %s, %s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s) on conflict(match_id) do update set update_time = %s,match_process =%s,home_player_score =%s,guest_player_score =%s;"
|
|
|
|
|
+ cursor.execute(sql3, (int(league_id), team_home, team_guest,int(score_home), int(score_guest), 0, score_home,score_guest,1,'','','','','','',utime,jijie,number,game_id,'hg3535','00:00',utime,jijie,score_home,score_guest))
|
|
|
|
|
+
|
|
|
|
|
+ if total_number_dict:
|
|
|
|
|
+ for key, value in total_number_dict.items():
|
|
|
|
|
+ if value:
|
|
|
|
|
+ new_hash = hash_func(match_id=game_id, odds_code=key, sort=0, p_id=4)
|
|
|
|
|
+ odds_only = r_func(match_id=game_id, odds_code=key, sort=0, p_id=4,odd=value)
|
|
|
|
|
+ sql1 = "insert into st_wq_odds(lg_id, odds_code, match_id, ctime, utime, odds, p_id, p_code, sort, source, sole,condition,odds_only,is_rollball) values (%s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s, %s,%s,%s) on conflict(sole) do update set utime = %s,odds = %s,odds_only=%s;"
|
|
|
|
|
+ cursor.execute(sql1, (
|
|
|
|
|
+ int(league_id), key, int(game_id), utime, utime,value, 4, "total_number", 0, "hg3535", new_hash,
|
|
|
|
|
+ total_number_dict_rule[key],odds_only,1,utime, value,odds_only))
|
|
|
|
|
+ # 更新主队st_zq_odds_record表
|
|
|
|
|
+ sql2 = "insert into st_wq_odds_record(lg_id, odds_code, match_id, ctime, utime, odds, p_id, p_code, sort, source, condition,odds_only,is_rollball) values (%s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s,%s,%s);"
|
|
|
|
|
+ cursor.execute(sql2, (
|
|
|
|
|
+ int(league_id), key, int(game_id), utime, utime, value, 4, "total_number", 0, "hg3535",
|
|
|
|
|
+ total_number_dict_rule[key],odds_only,1))
|
|
|
|
|
+ sql3 = "insert into st_wq_result(lg_id, home_player_name, guest_player_name, home_player_let_plate, guest_player_let_plate, all_inning,home_player_score,guest_player_score,status,first_score_player,last_score_player,first_inning_score,second_inning_score,third_inning_score,match_winer_player,update_time,match_process,tag,match_id,source,match_time) values (%s, %s, %s, %s, %s,%s, %s, %s, %s, %s, %s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s) on conflict(match_id) do update set update_time = %s,match_process =%s,home_player_score =%s,guest_player_score =%s;"
|
|
|
|
|
+ cursor.execute(sql3, (int(league_id), team_home, team_guest,int(score_home), int(score_guest), 0, score_home,score_guest,1,'','','','','','',utime,jijie,number,game_id,'hg3535','00:00',utime,jijie,score_home,score_guest))
|
|
|
|
|
+
|
|
|
|
|
+ if odd_evens_dict:
|
|
|
|
|
+ for key, value in odd_evens_dict.items():
|
|
|
|
|
+ if value:
|
|
|
|
|
+ new_hash = hash_func(match_id=game_id, odds_code=key, sort=0, p_id=5)
|
|
|
|
|
+ odds_only = r_func(match_id=game_id, odds_code=key, sort=0, p_id=5,odd=value)
|
|
|
|
|
+ sql1 = "insert into st_wq_odds(lg_id, odds_code, match_id, ctime, utime, odds, p_id, p_code, sort, source, sole,condition,odds_only,is_rollball) values (%s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s, %s,%s,%s) on conflict(sole) do update set utime = %s,odds = %s,odds_only=%s;"
|
|
|
|
|
+ cursor.execute(sql1, (
|
|
|
|
|
+ int(league_id), key, int(game_id), utime, utime,value, 5, "two_sides", 0, "hg3535", new_hash,
|
|
|
|
|
+ odd_evens_dict_rule[key],odds_only,1,utime, value,odds_only))
|
|
|
|
|
+ # 更新主队st_zq_odds_record表
|
|
|
|
|
+ sql2 = "insert into st_wq_odds_record(lg_id, odds_code, match_id, ctime, utime, odds, p_id, p_code, sort, source, condition,odds_only,is_rollball) values (%s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s,%s,%s);"
|
|
|
|
|
+ cursor.execute(sql2, (
|
|
|
|
|
+ int(league_id), key, int(game_id), utime, utime, value, 5, "two_sides", 0, "hg3535",odd_evens_dict_rule[key],odds_only,1))
|
|
|
|
|
+ sql3 = "insert into st_wq_result(lg_id, home_player_name, guest_player_name, home_player_let_plate, guest_player_let_plate, all_inning,home_player_score,guest_player_score,status,first_score_player,last_score_player,first_inning_score,second_inning_score,third_inning_score,match_winer_player,update_time,match_process,tag,match_id,source,match_time) values (%s, %s, %s, %s, %s,%s, %s, %s, %s, %s, %s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s) on conflict(match_id) do update set update_time = %s,match_process =%s,home_player_score =%s,guest_player_score =%s;"
|
|
|
|
|
+ cursor.execute(sql3, (int(league_id), team_home, team_guest,int(score_home), int(score_guest), 0, score_home,score_guest,1,'','','','','','',utime,jijie,number,game_id,'hg3535','00:00',utime,jijie,score_home,score_guest))
|
|
|
|
|
+
|
|
|
|
|
+ # 插入赛事表
|
|
|
|
|
+ Competition_sql = "insert into st_wq_competition(home_team, guest_team, lg_id, match_id, match_date, match_time,ctime, utime, tag,type,source,is_rollball) values (%s, %s, %s, %s, %s, %s, %s, %s,%s, %s, %s,%s) on conflict(match_id) do update set tag = %s;"
|
|
|
|
|
+ cursor.execute(Competition_sql, (team_home, team_guest, league_id, game_id, match_date, match_time, utime, utime, number, pt, "hg3535",1,number))
|
|
|
|
|
+
|
|
|
|
|
+ def close_spider(self, spider):
|
|
|
|
|
+ self.dbpool.close()
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+class Roll_Banqiupipeline(object):
|
|
|
|
|
+
|
|
|
|
|
+ def open_spider(self, spider):
|
|
|
|
|
+ self.dbpool = adbapi.ConnectionPool("psycopg2",host=settings["POST_HOST"], port=settings['POST_PORT'], user=settings["POST_USER"], password=settings["POST_PASSWORD"], database=settings["POST_DATABASE"])
|
|
|
|
|
+ self.pool = redis.ConnectionPool(host=settings["R_HOST"], port=settings["R_POST"], password=settings["R_PASSWORD"])
|
|
|
|
|
+ self.redis_db = redis.StrictRedis(connection_pool=self.pool)
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ def process_item(self, item, spider):
|
|
|
|
|
+ # 使用twisted将mysql插入变成异步执行
|
|
|
|
|
+ query = self.dbpool.runInteraction(self.do_insert, item)
|
|
|
|
|
+ query.addErrback(self.handle_error, item, spider) # 处理异常
|
|
|
|
|
+
|
|
|
|
|
+ def handle_error(self, failure, item, spider):
|
|
|
|
|
+ # 处理异步插入的异常
|
|
|
|
|
+ print(failure)
|
|
|
|
|
+
|
|
|
|
|
+ def do_insert(self, cursor, item):
|
|
|
|
|
+ # 联赛id
|
|
|
|
|
+ league_id = item['league_id']
|
|
|
|
|
+ # 联赛名
|
|
|
|
|
+ league_name = item['league_name']
|
|
|
|
|
+ # result = item['result']
|
|
|
|
|
+ # 比赛id
|
|
|
|
|
+ game_id = item['game_id']
|
|
|
|
|
+ # 球队1
|
|
|
|
|
+ team_home = item['team_home']
|
|
|
|
|
+ # 球队2
|
|
|
|
|
+ team_guest = item['team_guest']
|
|
|
|
|
+ # 数量(97>)
|
|
|
|
|
+ number = item['number']
|
|
|
|
|
+ #新增 match_score_dict
|
|
|
|
|
+ match_score_dict = item['match_score_dict']
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ # 比赛状态
|
|
|
|
|
+ zhuangtai = item['zhuangtai']
|
|
|
|
|
+ # 日期
|
|
|
|
|
+ # data_game = item['data_game']
|
|
|
|
|
+ data_game = item['data_game'].split("/")
|
|
|
|
|
+ month = str(data_game[1].strip())
|
|
|
|
|
+ day = str(data_game[0])
|
|
|
|
|
+ # 比赛时间
|
|
|
|
|
+ # time_game = str(item['time_game'])
|
|
|
|
|
+ # 比赛时间,时间戳
|
|
|
|
|
+ # ctime = "2019" + "-" + month + "-" + day + "" + time_game + ":00".strip()
|
|
|
|
|
+ r_ctime = "2019" + "-" + month + "-" + day
|
|
|
|
|
+ # 现在时间,时间戳
|
|
|
|
|
+ utime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
|
|
|
|
|
+ expire_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time() + 60))
|
|
|
|
|
+ # 队1分数
|
|
|
|
|
+ score_home = item['score_home']
|
|
|
|
|
+ # 队2分数
|
|
|
|
|
+ score_guest = item['score_guest']
|
|
|
|
|
+ # 第几节
|
|
|
|
|
+ jijie = item['jijie']
|
|
|
|
|
+ # 球队得分
|
|
|
|
|
+ qiudui = item['qiudui']
|
|
|
|
|
+ pt = item['pt']
|
|
|
|
|
+ #滚球这个位置获取不到这些字段
|
|
|
|
|
+ # match_date, match_time = new_time(ctime)
|
|
|
|
|
+ # 让球
|
|
|
|
|
+ concedes_dict = item['concedes_dict']
|
|
|
|
|
+ concedes_dict_rule = item['concedes_dict_rule']
|
|
|
|
|
+ # 独赢
|
|
|
|
|
+ capots_dict = item['capots_dict']
|
|
|
|
|
+ # 总得分大小
|
|
|
|
|
+ total_size_dict = item['total_size_dict']
|
|
|
|
|
+ total_size_dict_rule = item['total_size_dict_rule']
|
|
|
|
|
+ # 总得分单双
|
|
|
|
|
+ odd_evens_dict = item['odd_evens_dict']
|
|
|
|
|
+ odd_evens_dict_rule = item['odd_evens_dict_rule']
|
|
|
|
|
+
|
|
|
|
|
+ # 让球
|
|
|
|
|
+ concede = {'league_id': league_id, 'game_id': game_id, 'utime': utime, 'p_id': 1, 'p_code': "concede",
|
|
|
|
|
+ 'source': "hg3535", 'expire_time': expire_time, 'sort': 0}
|
|
|
|
|
+ # bqone_intodb(data1=concedes_dict, data2=concede, data3=concedes_dict_rule, cursor=cursor)
|
|
|
|
|
+ # 总得分:大/小
|
|
|
|
|
+ total_size = {'league_id': league_id, 'game_id': game_id, 'utime': utime, 'p_id': 2, 'p_code': "total_size",
|
|
|
|
|
+ 'source': "hg3535", 'expire_time': expire_time, 'sort': 0}
|
|
|
|
|
+ # bqone_intodb(data1=total_size_dict, data2=total_size, data3=total_size_dict_rule, cursor=cursor)
|
|
|
|
|
+
|
|
|
|
|
+ odd_even = {'league_id': league_id, 'game_id': game_id, 'utime': utime, 'p_id': 3, 'p_code': "two_sides",
|
|
|
|
|
+ 'source': "hg3535", 'expire_time': expire_time, 'sort': 0}
|
|
|
|
|
+ # bqone_intodb(data1=odd_evens_dict, data2=odd_even, data3=odd_evens_dict_rule, cursor=cursor)
|
|
|
|
|
+ # 赛事失效时间
|
|
|
|
|
+ # n_time = out_time(ctime, 3.5)
|
|
|
|
|
+ # 插入独赢
|
|
|
|
|
+ if capots_dict:
|
|
|
|
|
+ for key, value in capots_dict.items():
|
|
|
|
|
+ if value:
|
|
|
|
|
+ new_hash = hash_func(match_id=game_id, odds_code=key, sort=0, p_id=2)
|
|
|
|
|
+ odds_only = r_func(match_id=game_id, odds_code=key, sort=0, p_id=2,odd=value)
|
|
|
|
|
+ sql1 = "insert into st_bq_odds(lg_id, odds_code, match_id, ctime, utime, odds, p_id, p_code, sort, source, sole,odds_only,expire_time,is_rollball) values (%s, %s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s,%s,%s) on conflict(sole) do update set utime = %s,odds = %s,odds_only=%s,expire_time=%s;"
|
|
|
|
|
+ cursor.execute(sql1, (
|
|
|
|
|
+ int(league_id), key, int(game_id), utime, utime, value, 4, "capot", 0, "hg3535", new_hash,
|
|
|
|
|
+ odds_only, expire_time,1,utime, value, odds_only,expire_time))
|
|
|
|
|
+ # 更新主队st_zq_odds_record表
|
|
|
|
|
+ sql2 = "insert into st_bq_odds_record(lg_id, odds_code, match_id, ctime, utime,odds, p_id, p_code, sort, source,odds_only,is_rollball) values (%s, %s, %s, %s, %s, %s, %s,%s, %s, %s, %s,%s);"
|
|
|
|
|
+ cursor.execute(sql2, (
|
|
|
|
|
+ int(league_id), key, int(game_id), utime, utime, value, 4, "capot", 0, "hg3535", odds_only,1))
|
|
|
|
|
+ res = json.dumps(match_score_dict)
|
|
|
|
|
+ sql3 = "insert into st_bq_result(lg_id, home_team, guest_team, home_score, guest_score, all_goal, status,first_score, last_score,match_score,match_winer,update_time,match_time,match_process,tag,match_id,u_home_score,u_guest_score,source,match_score_t) values (%s,%s, %s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s, %s,%s,%s,%s,%s,%s,%s) on conflict(match_id) do update set update_time = %s,match_score = %s,match_time =%s,match_process =%s,home_score =%s,guest_score =%s;"
|
|
|
|
|
+ cursor.execute(sql3, (int(league_id), team_home, team_guest,score_home, score_guest, number, 1,'','',qiudui,'',utime,r_ctime,jijie,number,int(game_id),0,0,'hg3535',res,utime,qiudui,r_ctime,jijie,score_home,score_guest))
|
|
|
|
|
+ # 插入赛事表
|
|
|
|
|
+ Competition_sql = "insert into st_bq_competition(home_team,guest_team,lg_id,status,match_id,ctime,utime,tag,source,type,is_rollball) values(%s, %s, %s, %s, %s, %s, %s,%s, %s,%s,%s) on conflict(match_id) do update set tag=%s,is_rollball=%s,utime=%s;"
|
|
|
|
|
+ cursor.execute(Competition_sql, (team_home, team_guest, league_id, 1,game_id,utime, utime, number,"hg3535",1,1,number,1,utime))
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ # if concedes_dict:
|
|
|
|
|
+ # for key, value in concedes_dict.items():
|
|
|
|
|
+ # if value:
|
|
|
|
|
+ # new_hash = hash_func(match_id=game_id, odds_code=key, sort=0, p_id=2,pt=4)
|
|
|
|
|
+ # odds_only = r_func(match_id=game_id, odds_code=key, sort=0, p_id=2,pt=4,odd=value)
|
|
|
|
|
+ # sql1 = "insert into st_bq_odds(lg_id, odds_code, match_id, ctime, utime, odds, p_id, p_code, sort, source, sole,odds_only,expire_time,is_rollball) values (%s, %s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s,%s,%s) on conflict(sole) do update set utime = %s,odds = %s,odds_only=%s,expire_time=%s;"
|
|
|
|
|
+ # cursor.execute(sql1, (
|
|
|
|
|
+ # int(league_id), key, int(game_id), utime, utime, value, 4, "bq_capot", 0, "hg3535", new_hash,
|
|
|
|
|
+ # odds_only, expire_time,1,utime, value, odds_only,expire_time))
|
|
|
|
|
+ # # 更新主队st_zq_odds_record表
|
|
|
|
|
+ # sql2 = "insert into st_bq_odds_record(lg_id, odds_code, match_id, ctime, utime,odds, p_id, p_code, sort, source,odds_only,is_rollball) values (%s, %s, %s, %s, %s, %s, %s,%s, %s, %s, %s,%s);"
|
|
|
|
|
+ # cursor.execute(sql2, (
|
|
|
|
|
+ # int(league_id), key, int(game_id), utime, utime, value, 4, "bq_capot", 0, "hg3535", odds_only,1))
|
|
|
|
|
+ #
|
|
|
|
|
+ # sql3 = "insert into st_bq_result(lg_id, home_team, guest_team, home_score, guest_score, all_goal, status,first_score, last_score,match_score,match_winer,update_time,match_time,match_process,tag,match_id,u_home_score,u_guest_score,source) values (%s,%s, %s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s, %s,%s,%s,%s,%s,%s) on conflict(match_id) do update set update_time = %s,match_score = %s,match_time =%s,match_process =%s,home_score =%s,guest_score =%s;"
|
|
|
|
|
+ # cursor.execute(sql3, (int(league_id), team_home, team_guest,score_home, score_guest, number, 1,'','',qiudui,'',utime,r_ctime,jijie,number,int(game_id),0,0,'hg3535',utime,qiudui,r_ctime,jijie,score_home,score_guest))
|
|
|
|
|
+ # # 插入赛事表
|
|
|
|
|
+ # Competition_sql = "insert into st_bq_competition(home_team,guest_team,lg_id,status,match_id,ctime,utime,tag,source,type,is_rollball,is_today) values(%s, %s, %s, %s, %s, %s, %s, %s,%s, %s,%s,%s) on conflict(match_id) do update set tag=%s,is_today=%s,utime=%s;"
|
|
|
|
|
+ # cursor.execute(Competition_sql, (team_home, team_guest, league_id, 1,game_id,utime, utime, number,"hg3535",1,1,1,number,1,utime))
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ #让球
|
|
|
|
|
+ if concedes_dict:
|
|
|
|
|
+ for key, value in concedes_dict.items():
|
|
|
|
|
+ if value:
|
|
|
|
|
+ new_hash = hash_func(match_id=game_id, odds_code=key, sort=0, p_id=1)
|
|
|
|
|
+ odds_only = r_func(match_id=game_id, odds_code=key, sort=0, p_id=1,odd=value)
|
|
|
|
|
+ sql1 = "insert into st_bq_odds(lg_id, odds_code, match_id, ctime, utime, odds, p_id, p_code, sort, source, sole,condition,odds_only,is_rollball) values (%s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s, %s,%s,%s) on conflict(sole) do update set utime = %s,odds = %s,odds_only=%s;"
|
|
|
|
|
+ cursor.execute(sql1, (
|
|
|
|
|
+ int(league_id), key, int(game_id), utime, utime,value, 1, "concede", 0, "hg3535", new_hash,
|
|
|
|
|
+ concedes_dict_rule[key],odds_only,1,utime, value,odds_only))
|
|
|
|
|
+ # 更新主队st_zq_odds_record表
|
|
|
|
|
+ sql2 = "insert into st_bq_odds_record(lg_id, odds_code, match_id, ctime, utime, odds, p_id, p_code, sort, source, condition,odds_only,is_rollball) values (%s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s,%s,%s);"
|
|
|
|
|
+ cursor.execute(sql2, (
|
|
|
|
|
+ int(league_id), key, int(game_id), utime, utime, value, 1, "concede", 0, "hg3535",
|
|
|
|
|
+ concedes_dict_rule[key],odds_only,1))
|
|
|
|
|
+ #插入结果表
|
|
|
|
|
+ res = json.dumps(match_score_dict)
|
|
|
|
|
+ # r = pymysql.escape_string(res)
|
|
|
|
|
+ sql3 = "insert into st_bq_result(lg_id, home_team, guest_team, home_score, guest_score, all_goal, status,first_score, last_score,match_score,match_winer,update_time,match_time,match_process,tag,match_id,u_home_score,u_guest_score,source,match_score_t) values (%s,%s,%s, %s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s, %s,%s,%s,%s,%s,%s) on conflict(match_id) do update set update_time = %s,match_score_t = %s,match_time =%s,match_process =%s,home_score =%s,guest_score =%s;"
|
|
|
|
|
+ cursor.execute(sql3, (int(league_id), team_home, team_guest,score_home, score_guest, number, 1,'','','','',utime,r_ctime,jijie,number,int(game_id),0,0,'hg3535',res,utime,res,r_ctime,jijie,score_home,score_guest))
|
|
|
|
|
+ # 插入记录表
|
|
|
|
|
+ sql4 = "insert into st_bq_result_record(lg_id, home_team, guest_team, home_score, guest_score,first_score, last_score,match_score,match_winer,update_time,match_time,match_process,tag,match_id,source,status) values (%s, %s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s, %s,%s,%s,%s);"
|
|
|
|
|
+ cursor.execute(sql4, (int(league_id), team_home, team_guest,score_home, score_guest, '', '','','',utime,r_ctime,jijie,number,int(game_id),'hg3535',0))
|
|
|
|
|
+
|
|
|
|
|
+ if total_size_dict:
|
|
|
|
|
+ for key, value in total_size_dict.items():
|
|
|
|
|
+ if value:
|
|
|
|
|
+ new_hash = hash_func(match_id=game_id, odds_code=key, sort=0, p_id=2)
|
|
|
|
|
+ odds_only = r_func(match_id=game_id, odds_code=key, sort=0, p_id=2,odd=value)
|
|
|
|
|
+ sql1 = "insert into st_bq_odds(lg_id, odds_code, match_id, ctime, utime, odds, p_id, p_code, sort, source, sole,condition,odds_only,is_rollball) values (%s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s, %s,%s,%s) on conflict(sole) do update set utime = %s,odds = %s,odds_only=%s;"
|
|
|
|
|
+ cursor.execute(sql1, (
|
|
|
|
|
+ int(league_id), key, int(game_id), utime, utime,value, 2, "total_size", 0, "hg3535", new_hash,
|
|
|
|
|
+ total_size_dict_rule[key],odds_only,1,utime, value,odds_only))
|
|
|
|
|
+ # 更新主队st_zq_odds_record表
|
|
|
|
|
+ sql2 = "insert into st_bq_odds_record(lg_id, odds_code, match_id, ctime, utime, odds, p_id, p_code, sort, source, condition,odds_only,is_rollball) values (%s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s,%s,%s);"
|
|
|
|
|
+ cursor.execute(sql2, (
|
|
|
|
|
+ int(league_id), key, int(game_id), utime, utime, value, 2, "total_size", 0, "hg3535",
|
|
|
|
|
+ total_size_dict_rule[key],odds_only,1))
|
|
|
|
|
+ #插入结果表
|
|
|
|
|
+ res = json.dumps(match_score_dict)
|
|
|
|
|
+ # r = pymysql.escape_string(res)
|
|
|
|
|
+ sql3 = "insert into st_bq_result(lg_id, home_team, guest_team, home_score, guest_score, all_goal, status,first_score, last_score,match_score,match_winer,update_time,match_time,match_process,tag,match_id,u_home_score,u_guest_score,source,match_score_t) values (%s,%s,%s, %s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s, %s,%s,%s,%s,%s,%s) on conflict(match_id) do update set update_time = %s,match_score_t = %s,match_time =%s,match_process =%s,home_score =%s,guest_score =%s;"
|
|
|
|
|
+ cursor.execute(sql3, (int(league_id), team_home, team_guest,score_home, score_guest, number, 1,'','','','',utime,r_ctime,jijie,number,int(game_id),0,0,'hg3535',res,utime,res,r_ctime,jijie,score_home,score_guest))
|
|
|
|
|
+ # 插入记录表
|
|
|
|
|
+ sql4 = "insert into st_bq_result_record(lg_id, home_team, guest_team, home_score, guest_score,first_score, last_score,match_score,match_winer,update_time,match_time,match_process,tag,match_id,source,status) values (%s, %s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s, %s,%s,%s,%s);"
|
|
|
|
|
+ cursor.execute(sql4, (int(league_id), team_home, team_guest,score_home, score_guest, '', '','','',utime,r_ctime,jijie,number,int(game_id),'hg3535',0))
|
|
|
|
|
+
|
|
|
|
|
+ if odd_evens_dict:
|
|
|
|
|
+ for key, value in odd_evens_dict.items():
|
|
|
|
|
+ if value:
|
|
|
|
|
+ new_hash = hash_func(match_id=game_id, odds_code=key, sort=0, p_id=3)
|
|
|
|
|
+ odds_only = r_func(match_id=game_id, odds_code=key, sort=0, p_id=3,odd=value)
|
|
|
|
|
+ sql1 = "insert into st_bq_odds(lg_id, odds_code, match_id, ctime, utime, odds, p_id, p_code, sort, source, sole,condition,odds_only,is_rollball) values (%s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s, %s,%s,%s) on conflict(sole) do update set utime = %s,odds = %s,odds_only=%s;"
|
|
|
|
|
+ cursor.execute(sql1, (
|
|
|
|
|
+ int(league_id), key, int(game_id), utime, utime,value, 3, "two_sides", 0, "hg3535", new_hash,
|
|
|
|
|
+ odd_evens_dict_rule[key],odds_only,1,utime, value,odds_only))
|
|
|
|
|
+ # 更新主队st_zq_odds_record表
|
|
|
|
|
+ sql2 = "insert into st_bq_odds_record(lg_id, odds_code, match_id, ctime, utime, odds, p_id, p_code, sort, source, condition,odds_only,is_rollball) values (%s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s,%s,%s);"
|
|
|
|
|
+ cursor.execute(sql2, (
|
|
|
|
|
+ int(league_id), key, int(game_id), utime, utime, value, 3, "two_sides", 0, "hg3535",
|
|
|
|
|
+ odd_evens_dict_rule[key],odds_only,1))
|
|
|
|
|
+ #插入结果表
|
|
|
|
|
+ res = json.dumps(match_score_dict)
|
|
|
|
|
+ # r = pymysql.escape_string(res)
|
|
|
|
|
+ sql3 = "insert into st_bq_result(lg_id, home_team, guest_team, home_score, guest_score, all_goal, status,first_score, last_score,match_score,match_winer,update_time,match_time,match_process,tag,match_id,u_home_score,u_guest_score,source,match_score_t) values (%s,%s,%s, %s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s, %s,%s,%s,%s,%s,%s) on conflict(match_id) do update set update_time = %s,match_score_t = %s,match_time =%s,match_process =%s,home_score =%s,guest_score =%s;"
|
|
|
|
|
+ cursor.execute(sql3, (int(league_id), team_home, team_guest,score_home, score_guest, number, 1,'','','','',utime,r_ctime,jijie,number,int(game_id),0,0,'hg3535',res,utime,res,r_ctime,jijie,score_home,score_guest))
|
|
|
|
|
+ # 插入记录表
|
|
|
|
|
+ sql4 = "insert into st_bq_result_record(lg_id, home_team, guest_team, home_score, guest_score,first_score, last_score,match_score,match_winer,update_time,match_time,match_process,tag,match_id,source,status) values (%s, %s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s, %s,%s,%s,%s);"
|
|
|
|
|
+ cursor.execute(sql4, (int(league_id), team_home, team_guest,score_home, score_guest, '', '','','',utime,r_ctime,jijie,number,int(game_id),'hg3535',0))
|
|
|
|
|
+
|
|
|
|
|
+ # Competition_sql = "insert into st_bq_competition(home_team, guest_team, lg_id,'2', match_id,ctime, utime, tag,type,source,is_today,is_rollball) values (%s, %s, %s, %s, %s, %s, %s, %s,%s, %s) on conflict(match_id) do update set tag = %s,expire_time=%s,is_today=%s,is_morningplate=%s,is_stringscene=%s;"
|
|
|
|
|
+ # cursor.execute(Competition_sql, (team_home, team_guest, league_id, game_id,utime, utime, number, pt,"hg3535",1,1,number,1,0,0))
|
|
|
|
|
+ # Competition_sql = "insert into st_bq_competition(home_team, guest_team, lg_id, match_id, match_date, match_time,ctime, utime, tag,type,source,expire_time,is_today,is_morningplate,is_stringscene) values (%s, %s, %s, %s, %s, %s, %s, %s,%s, %s, %s, %s,%s, %s, %s) on conflict(match_id) do update set tag = %s,expire_time=%s,is_today=%s,is_morningplate=%s,is_stringscene=%s;"
|
|
|
|
|
+ # cursor.execute(Competition_sql, (team_home, team_guest, league_id, game_id, match_date, match_time, utime, utime, number, pt,"hg3535",n_time,0,1,0,number, n_time,0,1,0))
|
|
|
|
|
+ # Competition_sql = "insert into st_bq_competition(home_team, guest_team, lg_id, match_id, match_date, match_time,ctime, utime, tag,type,source,expire_time,is_today,is_morningplate,is_stringscene) values (%s, %s, %s, %s, %s, %s, %s, %s,%s, %s, %s, %s,%s, %s, %s) on conflict(match_id) do update set tag = %s,expire_time=%s,is_today=%s,is_morningplate=%s,is_stringscene=%s;"
|
|
|
|
|
+ # cursor.execute(Competition_sql, (team_home, team_guest, league_id, game_id, match_date, match_time, utime, utime, number, pt,"hg3535",n_time,0,0,1,number, n_time,0,0,1))
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ def close_spider(self, spider):
|
|
|
|
|
+ # self.conn.close()
|
|
|
|
|
+ self.dbpool.close()
|