|
@@ -43,6 +43,9 @@ import psycopg2.extras
|
|
|
|
|
|
|
|
|
|
|
|
|
# 生成哈希索引 sole
|
|
# 生成哈希索引 sole
|
|
|
|
|
+from items import Zuqiustatus
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
def hash_func(match_id, odds_code, sort, p_id):
|
|
def hash_func(match_id, odds_code, sort, p_id):
|
|
|
m = hashlib.md5()
|
|
m = hashlib.md5()
|
|
|
a = str(match_id) + str(odds_code) + str(sort) + str(p_id)
|
|
a = str(match_id) + str(odds_code) + str(sort) + str(p_id)
|
|
@@ -191,7 +194,7 @@ def zqtwo_competition(data, cursor):
|
|
|
data['team_home'], data['team_guest'], data['league_id'], data['game_id'], data['match_date'],
|
|
data['team_home'], data['team_guest'], data['league_id'], data['game_id'], data['match_date'],
|
|
|
data['match_time'],
|
|
data['match_time'],
|
|
|
data['utime'], data['utime'], data['number'], data["source"], data['expire_time'], data['is_morningplate'],
|
|
data['utime'], data['utime'], data['number'], data["source"], data['expire_time'], data['is_morningplate'],
|
|
|
- data['us_time'], data['number'], data['expire_time'], data['is_morningplate'],data['us_time']))
|
|
|
|
|
|
|
+ data['us_time'], data['number'], data['expire_time'], data['is_morningplate'], data['us_time']))
|
|
|
|
|
|
|
|
|
|
|
|
|
def zqthree_competition(data, cursor):
|
|
def zqthree_competition(data, cursor):
|
|
@@ -200,7 +203,7 @@ def zqthree_competition(data, cursor):
|
|
|
data['team_home'], data['team_guest'], data['league_id'], data['game_id'], data['match_date'],
|
|
data['team_home'], data['team_guest'], data['league_id'], data['game_id'], data['match_date'],
|
|
|
data['match_time'],
|
|
data['match_time'],
|
|
|
data['utime'], data['utime'], data['number'], data["source"], data['expire_time'], data['is_stringscene'],
|
|
data['utime'], data['utime'], data['number'], data["source"], data['expire_time'], data['is_stringscene'],
|
|
|
- data['us_time'], data['number'], data['expire_time'], data['is_stringscene'],data['us_time']))
|
|
|
|
|
|
|
+ data['us_time'], data['number'], data['expire_time'], data['is_stringscene'], data['us_time']))
|
|
|
|
|
|
|
|
|
|
|
|
|
# 足球 插入赔率 让球 大小-------------------------------------------------------------------------------------------------
|
|
# 足球 插入赔率 让球 大小-------------------------------------------------------------------------------------------------
|
|
@@ -1463,4 +1466,428 @@ class Liansaipipeline(object):
|
|
|
def close_spider(self, spider):
|
|
def close_spider(self, spider):
|
|
|
self.conn.close()
|
|
self.conn.close()
|
|
|
self.dbpool.close()
|
|
self.dbpool.close()
|
|
|
- # self.redis_db.disconnect()
|
|
|
|
|
|
|
+ # self.redis_db.disconnect()
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+#************************************滚球-------------------------------------------------------------------------------
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+#滚球方法都加了s
|
|
|
|
|
+
|
|
|
|
|
+def zqone_intodbs(data1, data2, data3, data4, cursor, redis_db):
|
|
|
|
|
+ if data1:
|
|
|
|
|
+ for index, value in enumerate(data1):
|
|
|
|
|
+ if value:
|
|
|
|
|
+ new_hash = hash_func(match_id=data2['game_id'], odds_code=data3, sort=index, p_id=data2['p_id'])
|
|
|
|
|
+ r_hash = r_func(match_id=data2['game_id'], odds_code=data3, sort=index, p_id=data2['p_id'], odd=value)
|
|
|
|
|
+ odds_only = r_hash
|
|
|
|
|
+ if redis_db.hexists("hg3535_zuqiu", r_hash):
|
|
|
|
|
+ pass
|
|
|
|
|
+ else:
|
|
|
|
|
+ redis_db.hset("hg3535_zuqiu", r_hash, 0)
|
|
|
|
|
+ # if data2['pt'] == 0:
|
|
|
|
|
+ sql1 = "insert into st_zq_odds(lg_id, odds_code, match_id, ctime, utime, odds, p_id, p_code, sort, source, sole, condition, expire_time,odds_only,is_rollball) values (%s,%s,%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s) on conflict(sole) do update set utime=%s,odds=%s,expire_time=%s,odds_only=%s,condition=%s;"
|
|
|
|
|
+ cursor.execute(sql1, (
|
|
|
|
|
+ int(data2['league_id']), data3, int(data2['game_id']), data2['utime'], data2['utime'], float(value),
|
|
|
|
|
+ data2['p_id'], data2["p_code"], index, data2["source"], new_hash,
|
|
|
|
|
+ data4[index], data2['expire_time'], odds_only, 1, data2['utime'], value, data2['expire_time'],
|
|
|
|
|
+ odds_only,data4[index]))
|
|
|
|
|
+
|
|
|
|
|
+ # 更新主队st_zq_odds_record表
|
|
|
|
|
+ sql2 = "insert into st_zq_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(data2['league_id']), data3, int(data2['game_id']), data2['utime'], data2['utime'], float(value),
|
|
|
|
|
+ data2['p_id'], data2["p_code"], index, data2["source"], data4[index], odds_only,1))
|
|
|
|
|
+ #写入数据设置默认值竟然不生效 待看
|
|
|
|
|
+ sql3 = "insert into st_zq_result(match_id, match_score, home_team, guest_team, home_score, guest_score, all_goal, status, first_score, last_score, match_winer, update_time, match_time,match_process,tag,lg_id,u_home_score,u_guest_score,source,p_code) 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(data2['game_id']), data2['match_score'],data2['team_home'],data2['team_guest'],data2['score_home'],data2['score_guest'],data2['number'],1,'','','',data2['utime'],data2['time_game'],data2['half_way'],data2['number'],int(data2['league_id']),0,0,'hg3535',data2["p_code"],data2['utime'],data2['match_score'],data2['time_game'],data2['half_way'],data2['score_home'],data2['score_guest']
|
|
|
|
|
+ ))
|
|
|
|
|
+
|
|
|
|
|
+ sql4 = "insert into st_zq_result_record(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,source,p_code) values (%s,%s,%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s,%s,%s,%s);"
|
|
|
|
|
+ cursor.execute(sql4, (
|
|
|
|
|
+ int(data2['league_id']), data2['team_home'],data2['team_guest'],data2['score_home'],data2['score_guest'],data2['number'],1,'','',data2['match_score'],'',data2['utime'],data2['time_game'],data2['half_way'],data2['number'],int(data2['game_id']),'hg3535',data2["p_code"]
|
|
|
|
|
+ ))
|
|
|
|
|
+
|
|
|
|
|
+def zqtwo_intodbs(data1, data2, data3, data4, cursor, redis_db):
|
|
|
|
|
+ if data1:
|
|
|
|
|
+ new_hash = hash_func(match_id=data2['game_id'], odds_code=data3, sort=data2['sort'], p_id=data2['p_id'])
|
|
|
|
|
+ r_hash = r_func(match_id=data2['game_id'], odds_code=data3, sort=data2['sort'], p_id=data2['p_id'],
|
|
|
|
|
+ odd=data1)
|
|
|
|
|
+ odds_only = r_hash
|
|
|
|
|
+ if redis_db.hexists("hg3535_zuqiu", r_hash):
|
|
|
|
|
+ pass
|
|
|
|
|
+ else:
|
|
|
|
|
+ redis_db.hset("hg3535_zuqiu", r_hash, 0)
|
|
|
|
|
+ # if data2['pt'] == 1:
|
|
|
|
|
+ sql1 = "insert into st_zq_odds(lg_id, odds_code, match_id, ctime, utime, odds, p_id, p_code, sort, source, sole, condition, expire_time, odds_only,is_today) values (%s,%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s) on conflict(sole) do update set utime=%s,odds=%s,expire_time=%s,odds_only=%s,condition=%s;"
|
|
|
|
|
+ cursor.execute(sql1, (
|
|
|
|
|
+ int(data2['league_id']), data3, int(data2['game_id']), data2['utime'], data2['utime'], data1,
|
|
|
|
|
+ data2['p_id'], data2["p_code"], data2['sort'], data2["source"], new_hash,
|
|
|
|
|
+ data4, data2['expire_time'], odds_only, 1, data2['utime'], data1, data2['expire_time'], odds_only,data4))
|
|
|
|
|
+ # 更新主队st_zq_odds_record表
|
|
|
|
|
+ sql2 = "insert into st_zq_odds_record(lg_id, odds_code, match_id, ctime, utime, odds, p_id, p_code, sort, source, condition,odds_only, is_today) values (%s,%s,%s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s);"
|
|
|
|
|
+ cursor.execute(sql2, (
|
|
|
|
|
+ int(data2['league_id']), data3, int(data2['game_id']), data2['utime'], data2['utime'], data1,
|
|
|
|
|
+ data2['p_id'], data2["p_code"], data2['sort'], data2["source"], data4, odds_only, 1))
|
|
|
|
|
+
|
|
|
|
|
+ sql3 = "insert into st_zq_result(match_id, match_score, home_team, guest_team, home_score, guest_score, all_goal, status, first_score, last_score, match_winer, update_time, match_time,match_process,tag,lg_id,u_home_score,u_guest_score,source,p_code) 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(data2['game_id']), data2['match_score'],data2['team_home'],data2['team_guest'],data2['score_home'],data2['score_guest'],data2['number'],1,'','','',data2['utime'],data2['time_game'],data2['half_way'],data2['number'],int(data2['league_id']),0,0,'hg3535',data2["p_code"],data2['utime'],data2['match_score'],data2['time_game'],data2['half_way'],data2['score_home'],data2['score_guest']
|
|
|
|
|
+ ))
|
|
|
|
|
+
|
|
|
|
|
+ sql4 = "insert into st_zq_result_record(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,source,p_code) values (%s,%s,%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s,%s,%s,%s);"
|
|
|
|
|
+ cursor.execute(sql4, (
|
|
|
|
|
+ int(data2['league_id']), data2['team_home'],data2['team_guest'],data2['score_home'],data2['score_guest'],data2['number'],1,'','',data2['match_score'],'',data2['utime'],data2['time_game'],data2['half_way'],data2['number'],int(data2['game_id']),'hg3535',data2["p_code"]
|
|
|
|
|
+ ))
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def zqone_competitions(data, cursor):
|
|
|
|
|
+ Competition_sql = "insert into st_zq_competition(home_team, guest_team, lg_id, status, match_id, match_date, match_time, ctime, utime,tag, source,type,expire_time,us_time,is_rollball) values (%s, %s, %s, %s, %s, %s, %s,%s, %s, %s,%s,%s,%s,%s,%s) on conflict(match_id) do update set utime = %s,status=%s,tag=%s,expire_time=%s;"
|
|
|
|
|
+ cursor.execute(Competition_sql, (
|
|
|
|
|
+ data['team_home'], data['team_guest'], data['league_id'],1,data['game_id'], data['match_date'],
|
|
|
|
|
+ data['match_time'],
|
|
|
|
|
+ data['utime'], data['utime'], data['number'], data["source"], 4,data['expire_time'], data['us_time'],data['is_rollball'],
|
|
|
|
|
+ data['utime'], 1, data['number'], data['expire_time']))
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def get_pcodes(corner_ball, code):
|
|
|
|
|
+ code_dict = {'concede_size': 1, 'capot': 2, 'two_sides': 3, 'total_goal': 4, 'half_full': 5, 'bodan': 6,
|
|
|
|
|
+ 'first_last_ball': 7, 'temaball': 11}
|
|
|
|
|
+ if corner_ball == "角球":
|
|
|
|
|
+ p_code = "corner_ball"
|
|
|
|
|
+ p_id = 9
|
|
|
|
|
+ elif corner_ball == "会晋级":
|
|
|
|
|
+ p_code = "promotion"
|
|
|
|
|
+ p_id = 10
|
|
|
|
|
+ elif corner_ball == "罚牌数":
|
|
|
|
|
+ p_code = "Penalty_card"
|
|
|
|
|
+ p_id = 12
|
|
|
|
|
+ else:
|
|
|
|
|
+ p_code = code
|
|
|
|
|
+ p_id = code_dict[code]
|
|
|
|
|
+ return p_code, p_id
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def news_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)
|
|
|
|
|
+ time4 = time3
|
|
|
|
|
+ data_time = str(time4).split(" ")
|
|
|
|
|
+ match_date = data_time[0]
|
|
|
|
|
+ match_time = data_time[1]
|
|
|
|
|
+ return match_date, match_time, time3
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+class Roll_Zuqiupipeline(object):
|
|
|
|
|
+ def __init__(self, dbpool, conn, cursor, redis_db):
|
|
|
|
|
+ self.dbpool = dbpool
|
|
|
|
|
+ self.conn = conn
|
|
|
|
|
+ self.cursor = cursor
|
|
|
|
|
+ self.redis_db = redis_db
|
|
|
|
|
+
|
|
|
|
|
+ @classmethod
|
|
|
|
|
+ def from_settings(cls, settings):
|
|
|
|
|
+ dbparms = dict(
|
|
|
|
|
+ host=settings["POST_HOST"],
|
|
|
|
|
+ user=settings["POST_USER"],
|
|
|
|
|
+ password=settings["POST_PASSWORD"],
|
|
|
|
|
+ port=settings['POST_PORT'],
|
|
|
|
|
+ )
|
|
|
|
|
+ dbpool = adbapi.ConnectionPool("psycopg2", **dbparms)
|
|
|
|
|
+ conn = psycopg2.connect(host=settings["POST_HOST"], port=settings['POST_PORT'], user=settings["POST_USER"], password=settings["POST_PASSWORD"], database=settings["POST_DATABASE"])
|
|
|
|
|
+ cursor = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
|
|
|
|
|
+ pool = redis.ConnectionPool(host=settings["R_HOST"], port=settings["R_POST"], password=settings["R_PASSWORD"])
|
|
|
|
|
+ redis_db = redis.StrictRedis(connection_pool=pool)
|
|
|
|
|
+ return cls(dbpool, conn, cursor, redis_db)
|
|
|
|
|
+
|
|
|
|
|
+ def process_item(self, item, spider):
|
|
|
|
|
+ # 使用twisted将mysql插入变成异步执行
|
|
|
|
|
+ query = self.dbpool.runInteraction(self.do_insert, item)
|
|
|
|
|
+ query.addErrback(self.handle_error, item, spider) # 处理异常
|
|
|
|
|
+ # return item
|
|
|
|
|
+
|
|
|
|
|
+ def handle_error(self, failure, item, spider):
|
|
|
|
|
+ # 处理异步插入的异常
|
|
|
|
|
+ print(failure)
|
|
|
|
|
+
|
|
|
|
|
+ def do_insert(self, cursor, item):
|
|
|
|
|
+ # 比赛日期
|
|
|
|
|
+ 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())
|
|
|
|
|
+ expire_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time() + 60))
|
|
|
|
|
+ # 比赛id
|
|
|
|
|
+ competition_id = item['game_id']
|
|
|
|
|
+ # 联赛id
|
|
|
|
|
+ league_id = item['league_id']
|
|
|
|
|
+ # 联赛name
|
|
|
|
|
+ league_name = item['league_name']
|
|
|
|
|
+ # 主队
|
|
|
|
|
+ team_home = item['team_home']
|
|
|
|
|
+ # 客队
|
|
|
|
|
+ team_guest = item['team_guest']
|
|
|
|
|
+ # number
|
|
|
|
|
+ number = item['number']
|
|
|
|
|
+ score_home = item['score_home']
|
|
|
|
|
+ score_guest = item['score_guest']
|
|
|
|
|
+ half_way = item['half_way']
|
|
|
|
|
+ pt = item['pt']
|
|
|
|
|
+ match_score = "{}:{}".format(score_home,score_guest)
|
|
|
|
|
+ corner_ball = item['corner_ball']
|
|
|
|
|
+ p_code, p_id = get_pcode(corner_ball, 'concede_size')
|
|
|
|
|
+ # 构建唯一索引
|
|
|
|
|
+ half_size_guest = item["half_size_guest"]
|
|
|
|
|
+ half_size_guest_rule = item["half_size_guest_rule"]
|
|
|
|
|
+ half_size_home = item["half_size_home"]
|
|
|
|
|
+ half_size_home_rule = item["half_size_home_rule"]
|
|
|
|
|
+
|
|
|
|
|
+ size_data = {'league_id': league_id, 'game_id': competition_id, 'utime': utime, 'p_id': p_id, 'p_code': p_code,
|
|
|
|
|
+ 'source': "hg3535", 'expire_time': expire_time, 'pt': pt,'match_score':match_score,'team_home':team_home,'team_guest':team_guest,'score_home':score_home,'score_guest':score_guest,'number':number,'time_game':time_game,'half_way':half_way}
|
|
|
|
|
+ # 让球 数据插入数据库
|
|
|
|
|
+ zqone_intodbs(data1=half_size_home, data2=size_data, data3="half_size_home", data4=half_size_home_rule,
|
|
|
|
|
+ cursor=cursor, redis_db=self.redis_db)
|
|
|
|
|
+ # 让球 数据插入数据库
|
|
|
|
|
+ zqone_intodbs(data1=half_size_guest, data2=size_data, data3="half_size_guest", data4=half_size_guest_rule,
|
|
|
|
|
+ cursor=cursor, redis_db=self.redis_db)
|
|
|
|
|
+ # 全场场大小
|
|
|
|
|
+ size_guest = item["size_guest"]
|
|
|
|
|
+ size_guest_rule = item["size_guest_rule"]
|
|
|
|
|
+ size_home = item["size_home"]
|
|
|
|
|
+ size_home_rule = item["size_home_rule"]
|
|
|
|
|
+ zqone_intodbs(data1=size_guest, data2=size_data, data3="size_guest", data4=size_guest_rule,
|
|
|
|
|
+ cursor=cursor, redis_db=self.redis_db)
|
|
|
|
|
+ zqone_intodbs(data1=size_home, data2=size_data, data3="size_home", data4=size_home_rule,
|
|
|
|
|
+ cursor=cursor, redis_db=self.redis_db)
|
|
|
|
|
+ # 上半场大小
|
|
|
|
|
+ half_concede_home_rule = item["half_concede_home_rule"]
|
|
|
|
|
+ half_concede_home = item["half_concede_home"]
|
|
|
|
|
+ half_concede_guest_rule = item["half_concede_guest_rule"]
|
|
|
|
|
+ half_concede_guest = item["half_concede_guest"]
|
|
|
|
|
+ # 上半场让球
|
|
|
|
|
+ zqone_intodbs(data1=half_concede_home, data2=size_data, data3="half_concede_home", data4=half_concede_home_rule,
|
|
|
|
|
+ cursor=cursor, redis_db=self.redis_db)
|
|
|
|
|
+ zqone_intodbs(data1=half_concede_guest, data2=size_data, data3="half_concede_guest", data4=half_concede_guest_rule, cursor=cursor, redis_db=self.redis_db)
|
|
|
|
|
+
|
|
|
|
|
+ concede_guest = item["concede_guest"]
|
|
|
|
|
+ concede_guest_rule = item["concede_guest_rule"]
|
|
|
|
|
+ concede_home = item["concede_home"]
|
|
|
|
|
+ concede_home_rule = item["concede_home_rule"]
|
|
|
|
|
+ # 全场让球
|
|
|
|
|
+ zqone_intodbs(data1=concede_guest, data2=size_data, data3="concede_guest", data4=concede_guest_rule,
|
|
|
|
|
+ cursor=cursor, redis_db=self.redis_db)
|
|
|
|
|
+ zqone_intodbs(data1=concede_home, data2=size_data, data3="concede_home", data4=concede_home_rule,
|
|
|
|
|
+ cursor=cursor,redis_db=self.redis_db)
|
|
|
|
|
+ #
|
|
|
|
|
+ p_code, p_id = get_pcode(corner_ball, 'capot')
|
|
|
|
|
+ # 独赢----------------------------------------------------------------------------------------------------------
|
|
|
|
|
+ half_capot_home = item["half_capot_home"]
|
|
|
|
|
+ half_capot_guest = item["half_capot_guest"]
|
|
|
|
|
+ half_capot_dogfall = item["half_capot_dogfall"]
|
|
|
|
|
+
|
|
|
|
|
+ capot_home = item["capot_home"]
|
|
|
|
|
+ capot_guest = item["capot_guest"]
|
|
|
|
|
+ capot_dogfall = item["capot_dogfall"]
|
|
|
|
|
+ capot_data = {'league_id': league_id, 'game_id': competition_id, 'utime': utime, 'p_id': p_id, 'p_code': p_code,
|
|
|
|
|
+ 'source': "hg3535", 'expire_time': expire_time, 'sort': 0, 'pt': pt,'match_score':match_score,'team_home':team_home,'team_guest':team_guest,'score_home':score_home,'score_guest':score_guest,'number':number,'time_game':time_game,'half_way':half_way}
|
|
|
|
|
+ # 上半场独赢 主队
|
|
|
|
|
+ zqtwo_intodbs(data1=half_capot_home, data2=capot_data, data3="half_capot_home", data4='1', cursor=cursor,redis_db=self.redis_db)
|
|
|
|
|
+ # 上半场独赢 客队
|
|
|
|
|
+ zqtwo_intodbs(data1=half_capot_guest, data2=capot_data, data3="half_capot_guest", data4='2', cursor=cursor,redis_db=self.redis_db)
|
|
|
|
|
+ # 上半场独赢 和
|
|
|
|
|
+ zqtwo_intodbs(data1=half_capot_dogfall, data2=capot_data, data3="half_capot_dogfall", data4='x', cursor=cursor,redis_db=self.redis_db)
|
|
|
|
|
+ #
|
|
|
|
|
+ # 全场独赢 主队
|
|
|
|
|
+ zqtwo_intodbs(data1=capot_home, data2=capot_data, data3="capot_home", data4='1', cursor=cursor,redis_db=self.redis_db)
|
|
|
|
|
+ # 全场独赢 客队
|
|
|
|
|
+ zqtwo_intodbs(data1=capot_guest, data2=capot_data, data3="capot_guest", data4='2', cursor=cursor,redis_db=self.redis_db)
|
|
|
|
|
+ # 全场独赢 和
|
|
|
|
|
+ zqtwo_intodbs(data1=capot_dogfall, data2=capot_data, data3="capot_dogfall", data4='x', cursor=cursor,redis_db=self.redis_db)
|
|
|
|
|
+ #
|
|
|
|
|
+# 入球数单双-------------------------------------------------------------------------------------------------------------
|
|
|
|
|
+ p_code, p_id = get_pcode(corner_ball, 'two_sides')
|
|
|
|
|
+ odd_even_odd = item["odd_even_odd"]
|
|
|
|
|
+ odd_even_even = item["odd_even_even"]
|
|
|
|
|
+ half_odd_even_odd = item["half_odd_even_odd"]
|
|
|
|
|
+ half_odd_even_even = item["half_odd_even_even"]
|
|
|
|
|
+ # 全场入球数 单双
|
|
|
|
|
+ two_sides_data = {'league_id': league_id, 'game_id': competition_id, 'utime': utime, 'p_id': p_id,
|
|
|
|
|
+ 'p_code': p_code,
|
|
|
|
|
+ 'source': "hg3535", 'expire_time': expire_time, 'sort': 0, 'pt': pt,'match_score':match_score,'team_home':team_home,'team_guest':team_guest,'score_home':score_home,'score_guest':score_guest,'number':number,'time_game':time_game,'half_way':half_way}
|
|
|
|
|
+ # 上半场入球数 单双
|
|
|
|
|
+ zqtwo_intodbs(data1=odd_even_odd, data2=two_sides_data, data3="two_sides_single", data4='单', cursor=cursor,redis_db=self.redis_db)
|
|
|
|
|
+ zqtwo_intodbs(data1=odd_even_even, data2=two_sides_data, data3="two_sides_double", data4='双', cursor=cursor,redis_db=self.redis_db)
|
|
|
|
|
+ # 全场入球数 单双
|
|
|
|
|
+ zqtwo_intodbs(data1=half_odd_even_odd, data2=two_sides_data, data3="half_two_sides_single", data4='单',
|
|
|
|
|
+ cursor=cursor, redis_db=self.redis_db)
|
|
|
|
|
+ zqtwo_intodbs(data1=half_odd_even_even, data2=two_sides_data, data3="half_two_sides_double", data4='双',
|
|
|
|
|
+ cursor=cursor, redis_db=self.redis_db)
|
|
|
|
|
+
|
|
|
|
|
+# 总入球数 --------------------------------------------------------------------------------------------------------------
|
|
|
|
|
+ p_code, p_id = get_pcode(corner_ball, 'total_goal')
|
|
|
|
|
+ total_goals = item['total_goal']
|
|
|
|
|
+ total_dict = {'total_goal_zero': '0-1', 'total_goal_two': '2-3', 'total_goal_four': '4-6',
|
|
|
|
|
+ 'total_goal_seven': '7或以上', 'half_total_goal_zero': '0', "half_total_goal_one": '1',
|
|
|
|
|
+ "half_total_goal_two": '2', "half_total_goal_three": '3或以上'}
|
|
|
|
|
+ # 全场入球数 单双
|
|
|
|
|
+ total_goal_data = {'league_id': league_id, 'game_id': competition_id, 'utime': utime, 'p_id': p_id,
|
|
|
|
|
+ 'p_code': p_code,
|
|
|
|
|
+ 'source': "hg3535", 'expire_time': expire_time, 'sort': 0, 'pt': pt,'match_score':match_score,'team_home':team_home,'team_guest':team_guest,'score_home':score_home,'score_guest':score_guest,'number':number,'time_game':time_game,'half_way':half_way}
|
|
|
|
|
+ # 上半场入球数 单双
|
|
|
|
|
+ for key, value in total_goals.items():
|
|
|
|
|
+ if value:
|
|
|
|
|
+ zqtwo_intodbs(data1=value, data2=total_goal_data, data3=key, data4=total_dict[key], cursor=cursor, redis_db=self.redis_db)
|
|
|
|
|
+
|
|
|
|
|
+# 全场半场 --------------------------------------------------------------------------------------------------------------
|
|
|
|
|
+ half_fulls = item['half_full']
|
|
|
|
|
+ p_code, p_id = get_pcode(corner_ball, 'half_full')
|
|
|
|
|
+ full_dict = {"half_full_home_home": "主主", "half_full_home_dogfall": "主和",
|
|
|
|
|
+ "half_full_home_guest": "主客", "half_full_dogfall_home": "和主",
|
|
|
|
|
+ "half_full_dogfall_dogfall": "和和", "half_full_dogfall_guest": "和客",
|
|
|
|
|
+ "half_full_guest_home": "客主", "half_full_guest_dogfall": "客和",
|
|
|
|
|
+ "half_full_guest_guest": "客客"}
|
|
|
|
|
+ half_full_data = {'league_id': league_id, 'game_id': competition_id, 'utime': utime, 'p_id': p_id,
|
|
|
|
|
+ 'p_code': p_code,
|
|
|
|
|
+ 'source': "hg3535", 'expire_time': expire_time, 'sort': 0, 'pt': pt,'match_score':match_score,'team_home':team_home,'team_guest':team_guest,'score_home':score_home,'score_guest':score_guest,'number':number,'time_game':time_game,'half_way':half_way}
|
|
|
|
|
+ if half_fulls:
|
|
|
|
|
+ for key, value in half_fulls.items():
|
|
|
|
|
+ if value:
|
|
|
|
|
+ zqtwo_intodbs(data1=value, data2=half_full_data, data3=key, data4=full_dict[key], cursor=cursor, redis_db=self.redis_db)
|
|
|
|
|
+# 波胆------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
+ bodan_datas = item['bodan_data']
|
|
|
|
|
+ p_code, p_id = get_pcode(corner_ball, 'bodan')
|
|
|
|
|
+ bodan_dict = {"bodanhome_one_zero": "1-0", "bodanhome_two_zero": "2-0",
|
|
|
|
|
+ "bodanhome_two_one": "2-1", "bodanhome_three_zero": "3-0",
|
|
|
|
|
+ "bodanhome_three_one": "3-1", "bodanhome_three_two": "3-2",
|
|
|
|
|
+ "bodanhome_four_zero": "4-0", "bodanhome_four_one": "4-1",
|
|
|
|
|
+ "bodanhome_four_two": "4-2", "bodanhome_four_three": "4-3",
|
|
|
|
|
+ "bodanguest_one_zero": "0-1", "bodanguest_two_zero": "0-2",
|
|
|
|
|
+ "bodanguest_two_one": "1-2", "bodanguest_three_zero": "0-3",
|
|
|
|
|
+ "bodanguest_three_one": "1-3", "bodanguest_three_two": "2-3",
|
|
|
|
|
+ "bodanguest_four_zero": "0-4", "bodanguest_four_one": "1-4",
|
|
|
|
|
+ "bodanguest_four_two": "2-4", "bodanguest_four_three": "3-4",
|
|
|
|
|
+ "bodandogfall_zero_zero": "0-0", "bodandogfall_one_one": "1-1",
|
|
|
|
|
+ "bodandogfall_two_two": "2-2", "bodandogfall_three_three": "3-3",
|
|
|
|
|
+ "bodandogfall_four_four": "4-4", "bodanother": "其他",
|
|
|
|
|
+ "halfbodanhome_one_zero": "1-0", "halfbodanhome_two_zero": "2-0",
|
|
|
|
|
+ "halfbodanhome_two_one": "2-1", "halfbodanhome_three_zero": "3-0",
|
|
|
|
|
+ "halfbodanhome_three_one": "3-1", "halfbodanhome_three_two": "3-2",
|
|
|
|
|
+ "halfbodanguest_one_zero": "0-1", "halfbodanguest_two_zero": "0-2",
|
|
|
|
|
+ "halfbodanguest_two_one": "1-2", "halfbodanguest_three_zero": "0-3",
|
|
|
|
|
+ "halfbodanguest_three_one": "1-3", "halfbodanguest_three_two": "2-3",
|
|
|
|
|
+ "halfbodandogfall_zero_zero": "0-0", "halfbodandogfall_one_one": "1-1",
|
|
|
|
|
+ "halfbodandogfall_two_two": "2-2", "halfbodandogfall_three_three": "3-3",
|
|
|
|
|
+ "halfbodanother": "其他"}
|
|
|
|
|
+ bodan_data = {'league_id': league_id, 'game_id': competition_id, 'utime': utime, 'p_id': p_id, 'p_code': p_code,
|
|
|
|
|
+ 'source': "hg3535", 'expire_time': expire_time, 'sort': 0, 'pt': pt,'match_score':match_score,'team_home':team_home,'team_guest':team_guest,'score_home':score_home,'score_guest':score_guest,'number':number,'time_game':time_game,'half_way':half_way}
|
|
|
|
|
+ if bodan_datas:
|
|
|
|
|
+ for key, value in bodan_datas.items():
|
|
|
|
|
+ zqtwo_intodbs(data1=value, data2=bodan_data, data3=key, data4=bodan_dict[key], cursor=cursor, redis_db=self.redis_db)
|
|
|
|
|
+
|
|
|
|
|
+# 最先进球/最后进球 ------------------------------------------------------------------------------------------------------
|
|
|
|
|
+ first_last_balls = item['first_last_ball']
|
|
|
|
|
+ p_code, p_id = get_pcode(corner_ball, 'first_last_ball')
|
|
|
|
|
+ first_last_dict = {"first_last_ball": "最先进球", "first_ball_home": "最先进球", "first_ball_guest": "最先进球",
|
|
|
|
|
+ "last_ball_home": "最后进球", "last_ball_guest": "最后进球", "not_ball": "没有进球"}
|
|
|
|
|
+ first_last_data = {'league_id': league_id, 'game_id': competition_id, 'utime': utime, 'p_id': p_id,
|
|
|
|
|
+ 'p_code': p_code,
|
|
|
|
|
+ 'source': "hg3535", 'expire_time': expire_time, 'sort': 0, 'pt': pt,'match_score':match_score,'team_home':team_home,'team_guest':team_guest,'score_home':score_home,'score_guest':score_guest,'number':number,'time_game':time_game,'half_way':half_way}
|
|
|
|
|
+ if first_last_balls:
|
|
|
|
|
+ for key, value in first_last_balls.items():
|
|
|
|
|
+ # 构建唯一索引
|
|
|
|
|
+ zqtwo_intodbs(data1=value, data2=first_last_data, data3=key, data4=first_last_dict[key], cursor=cursor, redis_db=self.redis_db)
|
|
|
|
|
+
|
|
|
|
|
+ p_code, p_id = get_pcode(corner_ball, 'temaball')
|
|
|
|
|
+ full_dicts = item['full_data']
|
|
|
|
|
+ half_dicts = item['half_data']
|
|
|
|
|
+ full_dict_rules = item['full_data_rule']
|
|
|
|
|
+ half_dict_rules = item['half_data_rule']
|
|
|
|
|
+ data = {'league_id': league_id, 'game_id': competition_id, 'utime': utime, 'p_id': p_id, 'p_code': p_code,
|
|
|
|
|
+ 'source': "hg3535", 'expire_time': expire_time, 'sort': 0, 'pt': pt,'match_score':match_score,'team_home':team_home,'team_guest':team_guest,'score_home':score_home,'score_guest':score_guest,'number':number,'time_game':time_game,'half_way':half_way}
|
|
|
|
|
+ if full_dicts:
|
|
|
|
|
+ for key, value in full_dicts.items():
|
|
|
|
|
+ zqtwo_intodbs(data1=value, data2=data, data3=key, data4=full_dict_rules[key], cursor=cursor, redis_db=self.redis_db)
|
|
|
|
|
+
|
|
|
|
|
+ if half_dicts:
|
|
|
|
|
+ for key, value in half_dicts.items():
|
|
|
|
|
+ zqtwo_intodbs(data1=value, data2=data, data3=key, data4=half_dict_rules[key], cursor=cursor, redis_db=self.redis_db)
|
|
|
|
|
+ #这日期在这里有问题 先行注释
|
|
|
|
|
+ # match_date, match_time, time3 = news_time(ctime)
|
|
|
|
|
+ # n_time = out_time(time3, 1.5)
|
|
|
|
|
+ # 插入st_zq_competition表
|
|
|
|
|
+ # if pt == 0:
|
|
|
|
|
+ data_competition = {'team_home': team_home, 'team_guest': team_guest, 'league_id': league_id,
|
|
|
|
|
+ 'game_id': competition_id,
|
|
|
|
|
+ 'match_date': r_ctime, 'match_time': '00:00:00', 'utime': utime, 'number': number,
|
|
|
|
|
+ 'source': "hg3535", "expire_time": expire_time, 'is_rollball': 1, "us_time":'2019-01-01 00:00:00','time_game':time_game}
|
|
|
|
|
+ zqone_competitions(data=data_competition, cursor=cursor)
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+class BallStatuspipeline(object):
|
|
|
|
|
+ def __init__(self, dbpool, conn, cursor):
|
|
|
|
|
+ self.dbpool = dbpool
|
|
|
|
|
+ self.conn = conn
|
|
|
|
|
+ self.cursor = cursor
|
|
|
|
|
+
|
|
|
|
|
+ @classmethod
|
|
|
|
|
+ def from_settings(cls, settings):
|
|
|
|
|
+ dbparms = dict(
|
|
|
|
|
+ host=settings["POST_HOST"],
|
|
|
|
|
+ # db = settings["POST_DATABASE"],
|
|
|
|
|
+ user=settings["POST_USER"],
|
|
|
|
|
+ password=settings["POST_PASSWORD"],
|
|
|
|
|
+ port=settings['POST_PORT'],
|
|
|
|
|
+ )
|
|
|
|
|
+ dbpool = adbapi.ConnectionPool("psycopg2", **dbparms)
|
|
|
|
|
+ conn = psycopg2.connect(host=settings["POST_HOST"], port=settings['POST_PORT'], user=settings["POST_USER"],password=settings["POST_PASSWORD"],database=settings["POST_DATABASE"])
|
|
|
|
|
+ cursor = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
|
|
|
|
|
+ return cls(dbpool,conn,cursor)
|
|
|
|
|
+
|
|
|
|
|
+ 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
|
|
|
|
|
+ if isinstance(item, Zuqiustatus):
|
|
|
|
|
+ zuqiu_toal = item['zuqiu_total']
|
|
|
|
|
+ for i in zuqiu_toal:
|
|
|
|
|
+ print(i)
|
|
|
|
|
+ match_id = i['match_id']
|
|
|
|
|
+ create_time = i['create_time']
|
|
|
|
|
+ staus = i['status']
|
|
|
|
|
+ update_time = i['create_time']
|
|
|
|
|
+ ball_type = i['ball_type']
|
|
|
|
|
+ sql1 = "insert into st_ball_status(match_id, create_time, status,update_time, ball_type) values (%s,%s, %s, %s, %s) on conflict(match_id) do update set update_time = %s;"
|
|
|
|
|
+ cursor.execute(sql1, (match_id, create_time,staus,update_time, ball_type,update_time))
|
|
|
|
|
+ sql2 = "update st_zq_result set status=1 where match_id={}".format(match_id)
|
|
|
|
|
+ sql3 = "update st_zq_result_record set status=1 where match_id={}".format(match_id)
|
|
|
|
|
+ sql4 = "update st_zq_competition set status=1 where match_id={}".format(match_id)
|
|
|
|
|
+ cursor.execute(sql2)
|
|
|
|
|
+ cursor.execute(sql3)
|
|
|
|
|
+ cursor.execute(sql4)
|
|
|
|
|
+
|
|
|
|
|
+ # 现在时间,时间戳
|
|
|
|
|
+ utime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
|
|
|
|
|
+ def close_spider(self, spider):
|
|
|
|
|
+ self.conn.close()
|
|
|
|
|
+ self.dbpool.close()
|