|
|
@@ -1,3569 +0,0 @@
|
|
|
-# -*- coding: utf-8 -*-
|
|
|
-
|
|
|
-# Define your item pipelines here
|
|
|
-#
|
|
|
-# Don't forget to add your pipeline to the ITEM_PIPELINES setting
|
|
|
-# See: http://doc.scrapy.org/en/latest/topics/item-pipeline.html
|
|
|
-# from psycopg2._psycopg import IntegrityError
|
|
|
-# from peewee import IntegrityError
|
|
|
-from twisted.enterprise import adbapi
|
|
|
-import datetime
|
|
|
-from models import database, StZqOdds,StZqResultRecord,StZqResult,StZqCompetition,StZqOddsRecord
|
|
|
-import time
|
|
|
-import hashlib
|
|
|
-import json
|
|
|
-# StZqResult
|
|
|
-
|
|
|
-import psycopg2
|
|
|
-
|
|
|
-import psycopg2.extras
|
|
|
-
|
|
|
-# conn = psycopg2.connect(host='192.168.2.200', port=10432, user='kaiyou', password='123456', database='kaiyou')
|
|
|
-# database = PostgresqlDatabase('postgres', **{'host': '127.0.0.1', 'port': 5432, 'user': 'postgres', 'password': '9998877'})
|
|
|
-
|
|
|
-# conn = psycopg2.connect(host='127.0.0.1', port=5432, user='postgres', password='9998877', database='postgres')
|
|
|
-from scrapy_yzd.items import Bangqiustatus, Lanqiustatus, Wanqiustatus,Zuqiustatus
|
|
|
-
|
|
|
-
|
|
|
-#生成odds_only哈希 pt不需要
|
|
|
-def r_func(match_id, odds_code, sort, p_id, odd):
|
|
|
- m = hashlib.md5()
|
|
|
- a = str(match_id) + str(odds_code) + str(sort) + str(p_id) + str(odd)
|
|
|
- m.update(a.encode('utf-8'))
|
|
|
- c = m.hexdigest()
|
|
|
- return c
|
|
|
-
|
|
|
-
|
|
|
-def inset_odd(match_id,value,utime,ctime,condition,p_id,wanfa):
|
|
|
- if StZqOdds.filter(match_id=match_id):
|
|
|
- for k, v in value.items():
|
|
|
- st_zq_odd = StZqOdds.filter(match_id=match_id, odds_code=k,p_code=wanfa)
|
|
|
- if st_zq_odd:
|
|
|
- if v:
|
|
|
- StZqOdds.update(utime=utime, odds=v).where(StZqOdds.match_id == match_id,
|
|
|
- StZqOdds.odds_code == k).execute()
|
|
|
- else:
|
|
|
- if v:
|
|
|
- StZqOdds.create(match_id=match_id, ctime=ctime, utime=utime, max=v,
|
|
|
- condition=condition[k], odds=v, p_id=p_id, p_code=wanfa,odds_code=k)
|
|
|
- else:
|
|
|
- for k, v in value.items():
|
|
|
- if v:
|
|
|
- StZqOdds.create(match_id=match_id, ctime=ctime, utime=utime, max=v,
|
|
|
- condition=condition[k], odds=v, p_id=p_id, p_code=wanfa,
|
|
|
- odds_code=k)
|
|
|
- # for k, v in value.items():
|
|
|
- # if v:
|
|
|
- # StZqOddsRecord.create(match_id=match_id, ctime=ctime, utime=utime, max=v,
|
|
|
- # condition=condition[k], odds=v, p_id=p_id, p_code=wanfa,
|
|
|
- # odds_code=k)
|
|
|
-
|
|
|
-
|
|
|
-# pt=4
|
|
|
-def hash_func(match_id, odds_code, sort, p_id):
|
|
|
- m = hashlib.md5()
|
|
|
- a = str(match_id) + str(odds_code) + str(sort) + str(p_id)
|
|
|
- m.update(a.encode('utf-8'))
|
|
|
- c = m.hexdigest()
|
|
|
- return c
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-def new_time(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 ScrapyYzdPipeline(object):
|
|
|
- #采用同步的机制写入pg
|
|
|
- def __init__(self):
|
|
|
- self.conn = psycopg2.connect(host='192.168.2.200', port=10432, user='kaiyou', password='123456', database='kaiyou')
|
|
|
- self.cursor = self.conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
|
|
|
- # self.conn = database
|
|
|
- # self.cursor = self.conn.cursor()
|
|
|
-
|
|
|
- def process_item(self, item, spider):
|
|
|
- # print(item)
|
|
|
- a = (dict(item))
|
|
|
- # a = (dict(item))
|
|
|
- # print(a)
|
|
|
- #大小
|
|
|
- concede_sizes = item.get('concede_size', "")
|
|
|
- # print(concede_sizes)
|
|
|
- if concede_sizes:
|
|
|
- with database.atomic():
|
|
|
- #key 联赛id
|
|
|
- for key, value in concede_sizes.items():
|
|
|
- # 比赛日期
|
|
|
- data_game = value.pop('data_game').split("/")
|
|
|
- month = str(data_game[1].strip())
|
|
|
- day = str(data_game[0])
|
|
|
- # 比赛时间
|
|
|
- time_game = str(value.pop('time_game'))
|
|
|
- # 比赛时间,时间戳
|
|
|
- ctime = "2019" + "-" + month + "-" + day + "" + time_game + ":00" #创建时间
|
|
|
- # match_date,match_time = new_time(ctime)
|
|
|
- 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))#过期时间
|
|
|
- print(type(expire_time))
|
|
|
- # 比赛id
|
|
|
- competition_id = value.pop('game_id')
|
|
|
- # 联赛id
|
|
|
- league_id = value.pop('league_id')
|
|
|
- # 联赛name
|
|
|
- league_name = value.pop('league_name')
|
|
|
- # 主队
|
|
|
- team_home = value.pop('team_home')
|
|
|
- # 客队
|
|
|
- team_guest = value.pop('team_guest')
|
|
|
- # 主队得分
|
|
|
- score_home = value.pop('score_home') # match_score
|
|
|
- # 客队得分
|
|
|
- score_guest = value.pop('score_guest') # match_score 这两个字段要按数据库定义格式存入对应字段
|
|
|
- score_status = value.get('status','')#比赛状态
|
|
|
- if score_status == "True":
|
|
|
- score_status = 1
|
|
|
- else:
|
|
|
- score_status = 0
|
|
|
-
|
|
|
- # 全场让球
|
|
|
- # number
|
|
|
- number = value.pop('number')
|
|
|
- corner_ball = value.pop('corner_ball')#角球
|
|
|
- half_way = value.get('half_way',"")
|
|
|
- concede_home = value.get('concede_home', "")
|
|
|
- concede_home_rule = value.get('concede_home_rule', "")
|
|
|
- concede_guest = value.get("concede_guest", "")
|
|
|
- concede_guest_rule = value.get("concede_guest_rule", "")
|
|
|
- # 上半场让球
|
|
|
- half_concede_home = value.get("half_concede_home", "")
|
|
|
- half_concede_home_rule = value.get("half_concede_home_rule", "")
|
|
|
- half_concede_guest = value.get("half_concede_guest", "")
|
|
|
- half_concede_guest_rule = value.get("half_concede_guest_rule", "")
|
|
|
- # 全场大小
|
|
|
- size_home = value.get('size_home')
|
|
|
- size_home_rule = value.get('size_home')
|
|
|
- size_guest = value.get('size_guest')
|
|
|
- size_guest_rule = value.get('size_guest_rule', "")
|
|
|
- # 上半场大小
|
|
|
- half_size_home = value.get('half_size_home', "")
|
|
|
- half_size_home_rule = value.get('half_size_home_rule', "")
|
|
|
- half_size_guest = value.get('half_size_guset', "")
|
|
|
- half_size_guest_rule = value.get('half_size_guest_rule', "")
|
|
|
- match_score = "{}:{}".format(score_home,score_guest)
|
|
|
-
|
|
|
- # 如果角球存在
|
|
|
- # if corner_ball:
|
|
|
- # wanfa = corner_ball
|
|
|
- # p_id = 9
|
|
|
- # else:
|
|
|
- # wanfa = "concede_size"
|
|
|
- # p_id = 1
|
|
|
-
|
|
|
- #如果角球存在
|
|
|
- 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 = "concede_size"
|
|
|
- p_id = 1
|
|
|
-
|
|
|
- if StZqResult.filter(match_id=key):
|
|
|
- StZqResult.update(update_time=utime,match_score=match_score,match_time=time_game,match_process=half_way,home_score=score_home,guest_score=score_guest).where(StZqResult.match_id == key).execute()
|
|
|
- else:
|
|
|
- StZqResult.create(match_id=key,match_score=match_score,home_team=team_home, guest_team=team_guest,home_score=score_home,guest_score=score_guest,all_goal=number,status=1,first_score='',last_score='',match_winer='',update_time=utime,match_time=time_game,match_process=half_way,tag=number,lg_id=league_id,u_home_score=0,u_guest_score=0,source='hg3535',p_code=p_code)
|
|
|
-
|
|
|
- #全场让球条件
|
|
|
- if concede_home:
|
|
|
- for index, result in enumerate(concede_home):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="concede_home", sort=index, p_id=p_id)
|
|
|
- # odds_only = new_hash + str(time.time()) # 赔率更新记录
|
|
|
- odds_only = r_func(match_id=key, odds_code="concede_home", sort=index, p_id=p_id,odd=result)
|
|
|
- st_zq_odd = StZqOdds.filter(sole=new_hash)
|
|
|
- if st_zq_odd:
|
|
|
- StZqOdds.update(utime=utime, odds=result,expire_time=expire_time,odds_only=odds_only,condition=concede_home_rule[index]).where(StZqOdds.sole == new_hash).execute()
|
|
|
- else:
|
|
|
- StZqOdds.create(match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,odds_only=odds_only,is_rollball=1,
|
|
|
- condition=concede_home_rule[index], odds=result, p_id=p_id,expire_time=expire_time,
|
|
|
- p_code=p_code, sort=index, odds_code="concede_home",sole=new_hash)
|
|
|
-
|
|
|
-
|
|
|
- if concede_guest:
|
|
|
- for index, result in enumerate(concede_guest):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="concede_guest", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="concede_guest", sort=index, p_id=p_id,odd=result)
|
|
|
- st_zq_odd = StZqOdds.filter(sole=new_hash)
|
|
|
- if st_zq_odd:
|
|
|
- StZqOdds.update(utime=utime, odds=result,expire_time=expire_time,odds_only=odds_only,condition=concede_guest_rule[index]).where(StZqOdds.sole == new_hash).execute()
|
|
|
- else:
|
|
|
- StZqOdds.create(match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,odds_only=odds_only,
|
|
|
- condition=concede_guest_rule[index], odds=result, p_id=p_id,expire_time=expire_time,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="concede_guest",sole=new_hash)
|
|
|
-
|
|
|
- if half_concede_home:
|
|
|
- for index, result in enumerate(half_concede_home):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="half_concede_home", sort=index, p_id=p_id)
|
|
|
- # odds_only = new_hash + str(time.time()) # 赔率更新记录
|
|
|
- odds_only = r_func(match_id=key, odds_code="half_concede_home", sort=index, p_id=p_id,odd=result)
|
|
|
-
|
|
|
- st_zq_odd = StZqOdds.filter(sole=new_hash)
|
|
|
- if st_zq_odd:
|
|
|
- StZqOdds.update(utime=utime, odds=result,expire_time=expire_time,odds_only=odds_only,condition=half_concede_home_rule[index]).where(StZqOdds.sole == new_hash).execute()
|
|
|
- else:
|
|
|
- StZqOdds.create(match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,odds_only=odds_only,
|
|
|
- condition=half_concede_home_rule[index], odds=result, p_id=p_id,expire_time=expire_time,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="half_concede_home", sole=new_hash)
|
|
|
-
|
|
|
-
|
|
|
- if half_concede_guest:
|
|
|
- for index, result in enumerate(half_concede_guest):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="half_concede_guest", sort=index, p_id=p_id)
|
|
|
- # odds_only = new_hash + str(time.time()) # 赔率更新记录
|
|
|
- odds_only = r_func(match_id=key, odds_code="half_concede_guest", sort=index, p_id=p_id,odd=result)
|
|
|
- st_zq_odd = StZqOdds.filter(sole=new_hash)
|
|
|
- if st_zq_odd:
|
|
|
- StZqOdds.update(utime=utime, odds=result,expire_time=expire_time,odds_only=odds_only,condition=half_concede_guest_rule[index]).where(StZqOdds.sole == new_hash).execute()
|
|
|
- else:
|
|
|
- StZqOdds.create(match_id=key, ctime=utime, utime=utime,lg_id=league_id,odds_only=odds_only,
|
|
|
- source='hg3535',expire_time=expire_time,is_rollball=1,
|
|
|
- max=half_concede_guest[index],
|
|
|
- condition=half_concede_guest_rule[index],
|
|
|
- odds=half_concede_guest[index], p_id=p_id, p_code=p_code,
|
|
|
- sort=index, odds_code="half_concede_guest", sole=new_hash)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- if size_home:
|
|
|
- for index, result in enumerate(size_home):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="size_home", sort=index, p_id=p_id)
|
|
|
- # odds_only = new_hash + str(time.time()) # 赔率更新记录
|
|
|
- odds_only = r_func(match_id=key, odds_code="size_home", sort=index, p_id=p_id,odd=result)
|
|
|
- st_zq_odd = StZqOdds.filter(sole=new_hash)
|
|
|
- if st_zq_odd:
|
|
|
- StZqOdds.update(utime=utime, odds=result,expire_time=expire_time,odds_only=odds_only,condition=size_home_rule[index]).where(StZqOdds.sole == new_hash).execute()
|
|
|
- else:
|
|
|
- StZqOdds.create(match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,odds_only=odds_only,is_rollball=1,
|
|
|
- condition=size_home_rule[index], odds=result, p_id=p_id,expire_time=expire_time,
|
|
|
- p_code=p_code, sort=index, odds_code="size_home", sole=new_hash)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- if size_guest:
|
|
|
- for index, result in enumerate(size_guest):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="size_guest", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="size_guest", sort=index, p_id=p_id,odd=result)
|
|
|
- st_zq_odd = StZqOdds.filter(sole=new_hash)
|
|
|
- if st_zq_odd:
|
|
|
- StZqOdds.update(utime=utime, odds=result,expire_time=expire_time,odds_only=odds_only,condition=size_guest_rule[index]).where(StZqOdds.sole == new_hash).execute()
|
|
|
- else:
|
|
|
- StZqOdds.create(match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,odds_only=odds_only,
|
|
|
- condition=size_guest_rule[index], odds=result, p_id=p_id,expire_time=expire_time,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="size_guest",sole=new_hash)
|
|
|
-
|
|
|
-
|
|
|
- if half_size_home:
|
|
|
- for index, result in enumerate(half_size_home):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="half_size_home", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="half_size_home", sort=index, p_id=p_id,odd=result)
|
|
|
- st_zq_odd = StZqOdds.filter(sole=new_hash)
|
|
|
- if st_zq_odd:
|
|
|
- StZqOdds.update(utime=utime, odds=result,expire_time=expire_time,odds_only=odds_only,condition=half_size_home_rule[index]).where(StZqOdds.sole == new_hash).execute()
|
|
|
- else:
|
|
|
- StZqOdds.create(match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,odds_only=odds_only,
|
|
|
- condition=half_size_home_rule[index], odds=result, p_id=p_id,expire_time=expire_time,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="half_size_home",sole=new_hash)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- if half_size_guest:
|
|
|
- for index, result in enumerate(half_size_guest):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="half_size_guest", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="half_size_guest", sort=index, p_id=p_id,odd=result)
|
|
|
- st_zq_odd = StZqOdds.filter(sole=new_hash)
|
|
|
- if st_zq_odd:
|
|
|
- StZqOdds.update(utime=utime, odds=result,expire_time=expire_time,odds_only=odds_only,condition=half_size_guest_rule[index]).where(StZqOdds.sole==new_hash).execute()
|
|
|
- else:
|
|
|
- StZqOdds.create(match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,odds_only=odds_only,
|
|
|
- condition=half_size_guest_rule[index], odds=result, p_id=p_id,expire_time=expire_time,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="half_size_guest",sole=new_hash)
|
|
|
-
|
|
|
- #赔率插入记录表
|
|
|
-
|
|
|
- if concede_home:
|
|
|
- for index, result in enumerate(concede_home):
|
|
|
- new_hash1 = hash_func(match_id=key, odds_code="concede_home", sort=index, p_id=p_id)
|
|
|
- odds_only1 = r_func(match_id=key, odds_code="concede_home", sort=index, p_id=p_id,odd=result)
|
|
|
- new_hash2 = hash_func(match_id=key, odds_code="concede_guest", sort=index, p_id=p_id)
|
|
|
- odds_only2 = r_func(match_id=key, odds_code="concede_guest", sort=index, p_id=p_id,odd=result)
|
|
|
- StZqOddsRecord.create(match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,
|
|
|
- condition=concede_home_rule[index], odds=result, p_id=p_id,odds_only=odds_only1,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="concede_home",sole=new_hash1)
|
|
|
- StZqOddsRecord.create(match_id=key, ctime=utime, utime=utime, max=concede_guest[index],lg_id=league_id,
|
|
|
- condition=concede_guest_rule[index], odds=concede_guest[index],odds_only= odds_only2,
|
|
|
- p_id=p_id, p_code=p_code, sort=index,source='hg3535',is_rollball=1,
|
|
|
- odds_code="concede_guest",sole=new_hash2)
|
|
|
-
|
|
|
-
|
|
|
- if half_concede_home:
|
|
|
- for index, result in enumerate(half_concede_home):
|
|
|
- new_hash1 = hash_func(match_id=key, odds_code="half_concede_home", sort=index, p_id=p_id)
|
|
|
- odds_only1 = r_func(match_id=key, odds_code="half_concede_home", sort=index, p_id=p_id,odd=result)
|
|
|
- new_hash2 = hash_func(match_id=key, odds_code="half_concede_guest", sort=index, p_id=p_id)
|
|
|
- odds_only2 = r_func(match_id=key, odds_code="half_concede_guest", sort=index, p_id=p_id,odd=result)
|
|
|
- StZqOddsRecord.create(match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,is_rollball=1,
|
|
|
- condition=half_concede_home_rule[index], odds=result, p_id=p_id,odds_only= odds_only1,
|
|
|
- p_code=p_code, sort=index, odds_code="half_concede_home",sole=new_hash1)
|
|
|
- StZqOddsRecord.create(match_id=key, ctime=utime, utime=utime,lg_id=league_id,
|
|
|
- max=half_concede_guest[index],source='hg3535',odds_only = odds_only2,
|
|
|
- condition=half_concede_guest_rule[index],
|
|
|
- odds=half_concede_guest[index], p_id=p_id, p_code=p_code,is_rollball=1,
|
|
|
- sort=index, odds_code="half_concede_guest",sole=new_hash2)
|
|
|
-
|
|
|
-
|
|
|
- if size_home:
|
|
|
- for index, result in enumerate(size_home):
|
|
|
- new_hash1 = hash_func(match_id=key, odds_code="size_home", sort=index, p_id=p_id)
|
|
|
- odds_only1 = r_func(match_id=key, odds_code="size_home", sort=index, p_id=p_id,odd=result)
|
|
|
- new_hash2 = hash_func(match_id=key, odds_code="size_guest", sort=index, p_id=p_id)
|
|
|
- odds_only2 = r_func(match_id=key, odds_code="size_guest", sort=index, p_id=p_id,odd=result)
|
|
|
- StZqOddsRecord.create(match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,is_rollball=1,
|
|
|
- condition=size_home_rule[index], odds=result, p_id=p_id,odds_only= odds_only1,
|
|
|
- p_code=p_code, sort=index, odds_code="size_home",sole=new_hash1)
|
|
|
- StZqOddsRecord.create(match_id=key, ctime=utime, utime=utime, max=size_guest[index],source='hg3535',lg_id=league_id,is_rollball=1,
|
|
|
- condition=size_guest_rule[index], odds=size_guest[index], p_id=p_id,odds_only = odds_only2,
|
|
|
- p_code=p_code, sort=index, odds_code="size_guest",sole=new_hash2)
|
|
|
-
|
|
|
-
|
|
|
- if half_size_home:
|
|
|
- for index, result in enumerate(half_size_home):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="half_size_home", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="half_size_home", sort=index, p_id=p_id,odd=result)
|
|
|
- StZqOddsRecord.create(match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',odds_only=odds_only,is_rollball=1,
|
|
|
- condition=half_size_home_rule[index], odds=result, p_id=p_id,lg_id=league_id,
|
|
|
- p_code=p_code, sort=index, odds_code="half_size_home",sole=new_hash)
|
|
|
- if half_size_guest:
|
|
|
- for index, result in enumerate(half_size_guest):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="half_size_guest", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="half_size_guest", sort=index, p_id=p_id,odd=result)
|
|
|
- StZqOddsRecord.create(match_id=key, ctime=utime, utime=utime, max=half_size_guest[index],source='hg3535',lg_id=league_id,
|
|
|
- condition=half_size_guest_rule[index], odds=half_size_guest[index],odds_only=odds_only,is_rollball=1,
|
|
|
- p_id=p_id, p_code=p_code, sort=index,
|
|
|
- odds_code="half_size_guest",sole=new_hash)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- #赛事表
|
|
|
- if StZqCompetition.filter(match_id=key):
|
|
|
- StZqCompetition.update(utime=utime,status=score_status,tag=number,expire_time=expire_time).where(StZqCompetition.match_id == key).execute()
|
|
|
- else:
|
|
|
- StZqCompetition.create(home_team=team_home,guest_team=team_guest,lg_id=league_id,status=score_status,match_id=key,match_date=r_ctime,match_time='00:00:00',ctime=utime,utime=utime,tag=number,source='hg3535',type=4,ptime=time_game,expire_time=expire_time,us_time='2019-01-01 00:00:00')
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- #更新记录表 具体更新哪些值目前随便写未知
|
|
|
- # if StZqResultRecord.filter(match_id=key):
|
|
|
- # StZqResultRecord.update(update_time=utime, status=score_status,match_score=match_score,match_process=half_way).where(StZqResultRecord.match_id == key).execute()
|
|
|
- # else:
|
|
|
- StZqResultRecord.create(lg_id=league_id,home_team=team_home,guest_team=team_guest,home_score=score_home,guest_score=score_guest,all_goal=number,status=1,first_score='',last_score='',match_score=match_score,match_winer='',update_time=utime,match_time=time_game,match_process=half_way,tag=number,match_id=key,source='hg3535',p_code=p_code)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- # for k, v in value.items():
|
|
|
- # if v:
|
|
|
- # for index, result in enumerate(v):
|
|
|
- # st_zq_odd = StZqResult.filter(match_id=key, sort=index, odds_code=k,p_code="concede_size")
|
|
|
- # if st_zq_odd:
|
|
|
- # if result:
|
|
|
- # StZqResult.update(utime=utime, odds=result).where(StZqResult.match_id == key,StZqResult.sort == index,StZqResult.odds_code == k).execute()
|
|
|
- # else:
|
|
|
- # if result:
|
|
|
- # StZqResult.create(match_id=key, ctime=ctime, utime=utime, max=result,condition=concede_home_rule[index], odds=result, p_id=1,p_code="concede_size", sort=index, odds_code=k)
|
|
|
- # else:
|
|
|
- # for k, v in value.items():
|
|
|
- # if v:
|
|
|
- # for index, result in enumerate(v):
|
|
|
- # if result:
|
|
|
- # StZqResult.create(match_id=key, cp_id=competition_id, host_name=team_home, guest_name=team_guest,home_rate=score_home, guest_rate=score_guest,all_goal=1,status=1,first_score='1',last_score='1',match_score='1',match_winer='1',update_time=utime,match_time='1',match_process='1',tag=1)
|
|
|
-
|
|
|
-
|
|
|
- capot = item.get('capot', "")
|
|
|
- # print(capot)
|
|
|
- if capot:
|
|
|
- with database.atomic():
|
|
|
- #key 联赛id
|
|
|
- for key, value in capot.items():
|
|
|
- data_game = value.pop('data_game')
|
|
|
- month = str(data_game[1].strip())
|
|
|
- day = str(data_game[0])
|
|
|
- # 比赛时间
|
|
|
- time_game = str(value.pop('time_game'))
|
|
|
- # 比赛时间,时间戳
|
|
|
- ctime = "2019" + "-" + month + "-" + day + "" + time_game + ":00" #创建时间
|
|
|
- # match_date,match_time = new_time(ctime)
|
|
|
- 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 = value.pop('game_id')
|
|
|
- # 联赛id
|
|
|
- league_id = value.pop('league_id')
|
|
|
- # 联赛name
|
|
|
- league_name = value.pop('league_name')
|
|
|
- # 主队
|
|
|
- team_home = value.pop('team_home')
|
|
|
- # 客队
|
|
|
- team_guest = value.pop('team_guest')
|
|
|
- # 主队得分
|
|
|
- score_home = value.pop('score_home')
|
|
|
- # 客队得分
|
|
|
- score_guest = value.pop('score_guest')
|
|
|
- # 全场让球
|
|
|
- # number
|
|
|
- number = value.pop('number')
|
|
|
- corner_ball = value.pop('corner_ball')
|
|
|
- half_way = value.pop('half_way')
|
|
|
- concede_home = value.get('concede_home', "")
|
|
|
- concede_home_rule = value.get('concede_home_rule', "")
|
|
|
- concede_guest = value.get("concede_guest", "")
|
|
|
- concede_guest_rule = value.get("concede_guest_rule", "")
|
|
|
- # 上半场让球
|
|
|
- half_concede_home = value.get("half_concede_home", "")
|
|
|
- half_concede_home_rule = value.get("half_concede_home_rule", "")
|
|
|
- half_concede_guest = value.get("half_concede_guest", "")
|
|
|
- half_concede_guest_rule = value.get("half_concede_guest_rule", "")
|
|
|
- # 全场大小
|
|
|
- size_home = value.get('size_home')
|
|
|
- size_home_rule = value.get('size_home')
|
|
|
- size_guest = value.get('size_guest')
|
|
|
- size_guest_rule = value.get('size_guest_rule', "")
|
|
|
- # 上半场大小
|
|
|
- half_size_home = value.get('half_size_home', "")
|
|
|
- half_size_home_rule = value.get('half_size_home_rule', "")
|
|
|
- half_size_guest = value.get('half_size_guset', "")
|
|
|
- half_size_guest_rule = value.get('half_size_guest_rule', "")
|
|
|
- score_status = value.get('status','')
|
|
|
- if score_status == "True":
|
|
|
- score_status = 1
|
|
|
- else:
|
|
|
- score_status = 0
|
|
|
-
|
|
|
- match_score = "{}:{}".format(score_home,score_guest)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- #如果角球存在
|
|
|
- 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 = "capot"
|
|
|
- p_id = 2
|
|
|
-
|
|
|
- if StZqResult.filter(match_id=key):
|
|
|
- StZqResult.update(match_score=match_score,update_time=utime,match_time=time_game,match_process=half_way,home_score=score_home,guest_score=score_guest).where(StZqResult.match_id == key).execute()
|
|
|
- else:
|
|
|
- StZqResult.create(match_id=key,match_score=match_score,home_team=team_home, guest_team=team_guest,home_score=score_home,guest_score=score_guest,all_goal=number,status=1,first_score='',last_score='',match_winer='',update_time=utime,match_time=time_game,match_process=half_way,tag=number,lg_id=league_id,u_home_score=0,u_guest_score=0,source='hg3535',p_code=p_code)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- #全场让球条件
|
|
|
- if concede_home:
|
|
|
- for index, result in enumerate(concede_home):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="concede_home", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="concede_home", sort=index, p_id=p_id,odd=result)
|
|
|
- st_zq_odd = StZqOdds.filter(sole=new_hash)
|
|
|
- if st_zq_odd:
|
|
|
- StZqOdds.update(utime=utime, odds=result,expire_time=expire_time,odds_only=odds_only,condition=concede_home_rule[index]).where(StZqOdds.sole == new_hash).execute()
|
|
|
- else:
|
|
|
- StZqOdds.create(match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,odds_only=odds_only,
|
|
|
- condition=concede_home_rule[index], odds=result, p_id=p_id,expire_time=expire_time,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="concede_home",sole=new_hash)
|
|
|
-
|
|
|
-
|
|
|
- if concede_guest:
|
|
|
- for index, result in enumerate(concede_guest):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="concede_guest", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="concede_guest", sort=index, p_id=p_id,odd=result)
|
|
|
- st_zq_odd = StZqOdds.filter(sole=new_hash)
|
|
|
- if st_zq_odd:
|
|
|
- StZqOdds.update(utime=utime, odds=result,expire_time=expire_time,odds_only=odds_only,condition=concede_guest_rule[index]).where(StZqOdds.sole == new_hash).execute()
|
|
|
- else:
|
|
|
- StZqOdds.create(match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,odds_only=odds_only,
|
|
|
- condition=concede_guest_rule[index], odds=result, p_id=p_id,expire_time=expire_time,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="concede_guest",sole=new_hash)
|
|
|
-
|
|
|
- if half_concede_home:
|
|
|
- for index, result in enumerate(half_concede_home):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="half_concede_home", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="half_concede_home", sort=index, p_id=p_id,odd=result)
|
|
|
- st_zq_odd = StZqOdds.filter(sole=new_hash)
|
|
|
- if st_zq_odd:
|
|
|
- StZqOdds.update(utime=utime, odds=result,expire_time=expire_time,odds_only=odds_only,condition=half_concede_home_rule[index]).where(StZqOdds.sole == new_hash).execute()
|
|
|
- else:
|
|
|
- StZqOdds.create(match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,odds_only=odds_only,
|
|
|
- condition=half_concede_home_rule[index], odds=result, p_id=p_id,expire_time=expire_time,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="half_concede_home", sole=new_hash)
|
|
|
-
|
|
|
-
|
|
|
- if half_concede_guest:
|
|
|
- for index, result in enumerate(half_concede_guest):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="half_concede_guest", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="half_concede_guest", sort=index, p_id=p_id,odd=result)
|
|
|
- st_zq_odd = StZqOdds.filter(sole=new_hash)
|
|
|
- if st_zq_odd:
|
|
|
- StZqOdds.update(utime=utime, odds=result,expire_time=expire_time,odds_only=odds_only,condition=half_concede_guest_rule[index]).where(StZqOdds.sole == new_hash).execute()
|
|
|
- else:
|
|
|
- StZqOdds.create(match_id=key, ctime=utime, utime=utime,source='hg3535',lg_id=league_id,odds_only=odds_only,
|
|
|
- max=half_concede_guest[index],expire_time=expire_time,is_rollball=1,
|
|
|
- condition=half_concede_guest_rule[index],
|
|
|
- odds=half_concede_guest[index], p_id=p_id, p_code=p_code,
|
|
|
- sort=index, odds_code="half_concede_guest", sole=new_hash)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- if size_home:
|
|
|
- for index, result in enumerate(size_home):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="size_home", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="size_home", sort=index, p_id=p_id,odd=result)
|
|
|
- st_zq_odd = StZqOdds.filter(sole=new_hash)
|
|
|
- if st_zq_odd:
|
|
|
- StZqOdds.update(utime=utime, odds=result,expire_time=expire_time,odds_only=odds_only,condition=size_home_rule[index]).where(StZqOdds.sole == new_hash).execute()
|
|
|
- else:
|
|
|
- StZqOdds.create(match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,odds_only=odds_only,
|
|
|
- condition=size_home_rule[index], odds=result, p_id=p_id,expire_time=expire_time,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="size_home", sole=new_hash)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- if size_guest:
|
|
|
- for index, result in enumerate(size_guest):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="size_guest", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="size_guest", sort=index, p_id=p_id,odd=result)
|
|
|
- st_zq_odd = StZqOdds.filter(sole=new_hash)
|
|
|
- if st_zq_odd:
|
|
|
- StZqOdds.update(utime=utime, odds=result,expire_time=expire_time,odds_only=odds_only,condition=size_guest_rule[index]).where(StZqOdds.sole == new_hash).execute()
|
|
|
- else:
|
|
|
- StZqOdds.create(match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,odds_only=odds_only,
|
|
|
- condition=size_guest_rule[index], odds=result, p_id=p_id,expire_time=expire_time,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="size_guest",sole=new_hash)
|
|
|
-
|
|
|
-
|
|
|
- if half_size_home:
|
|
|
- for index, result in enumerate(half_size_home):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="half_size_home", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="half_size_home", sort=index, p_id=p_id,odd=result)
|
|
|
- st_zq_odd = StZqOdds.filter(sole=new_hash)
|
|
|
- if st_zq_odd:
|
|
|
- StZqOdds.update(utime=utime, odds=result,expire_time=expire_time,odds_only=odds_only,condition=half_size_home_rule[index]).where(StZqOdds.sole == new_hash).execute()
|
|
|
- else:
|
|
|
- StZqOdds.create(match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,odds_only=odds_only,
|
|
|
- condition=half_size_home_rule[index], odds=result, p_id=p_id,expire_time=expire_time,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="half_size_home",sole=new_hash)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- if half_size_guest:
|
|
|
- for index, result in enumerate(half_size_guest):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="half_size_guest", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="half_size_guest", sort=index, p_id=p_id,odd=result)
|
|
|
- st_zq_odd = StZqOdds.filter(sole=new_hash)
|
|
|
- if st_zq_odd:
|
|
|
- StZqOdds.update(utime=utime, odds=result,expire_time=expire_time,odds_only=odds_only,condition=half_size_guest_rule[index]).where(StZqOdds.sole==new_hash).execute()
|
|
|
- else:
|
|
|
- StZqOdds.create(match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,odds_only=odds_only,
|
|
|
- condition=half_size_guest_rule[index], odds=result, p_id=p_id,expire_time=expire_time,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="half_size_guest",sole=new_hash)
|
|
|
-
|
|
|
- #赔率插入记录表
|
|
|
-
|
|
|
- if concede_home:
|
|
|
- for index, result in enumerate(concede_home):
|
|
|
- new_hash1 = hash_func(match_id=key, odds_code="concede_home", sort=index, p_id=p_id)
|
|
|
- odds_only1 = r_func(match_id=key, odds_code="concede_home", sort=index, p_id=p_id,odd=result)
|
|
|
- new_hash2 = hash_func(match_id=key, odds_code="concede_guest", sort=index, p_id=p_id)
|
|
|
- odds_only2 = r_func(match_id=key, odds_code="concede_guest", sort=index, p_id=p_id,odd=result)
|
|
|
- StZqOddsRecord.create(match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,
|
|
|
- condition=concede_home_rule[index], odds=result, p_id=p_id,odds_only=odds_only1,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="concede_home",sole=new_hash1)
|
|
|
- StZqOddsRecord.create(match_id=key, ctime=utime, utime=utime, max=concede_guest[index],source='hg3535',lg_id=league_id,
|
|
|
- condition=concede_guest_rule[index], odds=concede_guest[index],is_rollball=1,
|
|
|
- p_id=p_id, p_code=p_code, sort=index,odds_only=odds_only2,
|
|
|
- odds_code="concede_guest",sole=new_hash2)
|
|
|
-
|
|
|
-
|
|
|
- if half_concede_home:
|
|
|
- for index, result in enumerate(half_concede_home):
|
|
|
- new_hash1 = hash_func(match_id=key, odds_code="half_concede_home", sort=index, p_id=p_id)
|
|
|
- odds_only1 = r_func(match_id=key, odds_code="half_concede_home", sort=index, p_id=p_id,odd=result)
|
|
|
- new_hash2 = hash_func(match_id=key, odds_code="half_concede_guest", sort=index, p_id=p_id)
|
|
|
- odds_only2 = r_func(match_id=key, odds_code="half_concede_guest", sort=index, p_id=p_id,odd=result)
|
|
|
- StZqOddsRecord.create(match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,is_rollball=1,
|
|
|
- condition=half_concede_home_rule[index], odds=result, p_id=p_id,odds_only=odds_only1,
|
|
|
- p_code=p_code, sort=index, odds_code="half_concede_home",sole=new_hash1)
|
|
|
- StZqOddsRecord.create(match_id=key, ctime=utime, utime=utime,source='hg3535',lg_id=league_id,
|
|
|
- max=half_concede_guest[index],odds_only=odds_only2,
|
|
|
- condition=half_concede_guest_rule[index],is_rollball=1,
|
|
|
- odds=half_concede_guest[index], p_id=p_id, p_code=p_code,
|
|
|
- sort=index, odds_code="half_concede_guest",sole=new_hash2)
|
|
|
-
|
|
|
-
|
|
|
- if size_home:
|
|
|
- for index, result in enumerate(size_home):
|
|
|
- new_hash1 = hash_func(match_id=key, odds_code="size_home", sort=index, p_id=p_id)
|
|
|
- odds_only1 = r_func(match_id=key, odds_code="size_home", sort=index, p_id=p_id,odd=result)
|
|
|
- new_hash2 = hash_func(match_id=key, odds_code="size_guest", sort=index, p_id=p_id)
|
|
|
- odds_only2 = r_func(match_id=key, odds_code="size_guest", sort=index, p_id=p_id,odd=result)
|
|
|
- StZqOddsRecord.create(match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,
|
|
|
- condition=size_home_rule[index], odds=result, p_id=p_id,odds_only=odds_only1,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="size_home",sole=new_hash1)
|
|
|
- StZqOddsRecord.create(match_id=key, ctime=utime, utime=utime, max=size_guest[index],source='hg3535',lg_id=league_id,
|
|
|
- condition=size_guest_rule[index], odds=size_guest[index], p_id=p_id,odds_only=odds_only2,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="size_guest",sole=new_hash2)
|
|
|
-
|
|
|
-
|
|
|
- if half_size_home:
|
|
|
- for index, result in enumerate(half_size_home):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="half_size_home", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="half_size_home", sort=index, p_id=p_id,odd=result)
|
|
|
- StZqOddsRecord.create(match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,
|
|
|
- condition=half_size_home_rule[index], odds=result, p_id=p_id,odds_only=odds_only,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="half_size_home",sole=new_hash)
|
|
|
- if half_size_guest:
|
|
|
- for index, result in enumerate(half_size_guest):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="half_size_guest", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="half_size_guest", sort=index, p_id=p_id,odd=result)
|
|
|
- StZqOddsRecord.create(match_id=key, ctime=utime, utime=utime, max=half_size_guest[index],source='hg3535',odds_only=odds_only,
|
|
|
- condition=half_size_guest_rule[index], odds=half_size_guest[index],lg_id=league_id,is_rollball=1,
|
|
|
- p_id=p_id, p_code=p_code, sort=index,
|
|
|
- odds_code="half_size_guest",sole=new_hash)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- #赛事表
|
|
|
- if StZqCompetition.filter(match_id=key):
|
|
|
- StZqCompetition.update(utime=utime,status=score_status,tag=number,expire_time=expire_time).where(StZqCompetition.match_id == key).execute()
|
|
|
- else:
|
|
|
- StZqCompetition.create(home_team=team_home,guest_team=team_guest,lg_id=league_id,status=score_status,match_id=key,match_date=r_ctime,match_time='00:00:00',ctime=utime,utime=utime,tag=number,source='hg3535',type=4,ptime=time_game,expire_time=expire_time,us_time='2019-01-01 00:00:00')
|
|
|
-
|
|
|
-
|
|
|
- #更新记录表 具体更新哪些值目前随便写未知
|
|
|
- # if StZqResultRecord.filter(match_id=key):
|
|
|
- # StZqResultRecord.update(update_time=utime, status=score_status,match_score=match_score,match_time=time_game).where(StZqResultRecord.match_id == key).execute()
|
|
|
- # else:
|
|
|
- StZqResultRecord.create(lg_id=league_id,home_team=team_home,guest_team=team_guest,home_score=score_home,guest_score=score_guest,all_goal=number,status=1,first_score='',last_score='',match_score=match_score,match_winer='',update_time=utime,match_time=time_game,match_process=half_way,tag=number,match_id=key,source='hg3535',p_code=p_code)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- # for k, v in value.items():
|
|
|
- # if v:
|
|
|
- # for index, result in enumerate(v):
|
|
|
- # st_zq_odd = StZqResult.filter(match_id=key, sort=index, odds_code=k,p_code="concede_size")
|
|
|
- # if st_zq_odd:
|
|
|
- # if result:
|
|
|
- # StZqResult.update(utime=utime, odds=result).where(StZqResult.match_id == key,StZqResult.sort == index,StZqResult.odds_code == k).execute()
|
|
|
- # else:
|
|
|
- # if result:
|
|
|
- # StZqResult.create(match_id=key, ctime=ctime, utime=utime, max=result,condition=concede_home_rule[index], odds=result, p_id=1,p_code="concede_size", sort=index, odds_code=k)
|
|
|
- # else:
|
|
|
- # for k, v in value.items():
|
|
|
- # if v:
|
|
|
- # for index, result in enumerate(v):
|
|
|
- # if result:
|
|
|
- # StZqResult.create(match_id=key, cp_id=competition_id, host_name=team_home, guest_name=team_guest,home_rate=score_home, guest_rate=score_guest,all_goal=1,status=1,first_score='1',last_score='1',match_score='1',match_winer='1',update_time=utime,match_time='1',match_process='1',tag=1)
|
|
|
-
|
|
|
- #入球数
|
|
|
- odd_even = item.get('odd_even', "")
|
|
|
- if odd_even:
|
|
|
- with database.atomic():
|
|
|
- #key 联赛id
|
|
|
- for key, value in odd_even.items():
|
|
|
- # 比赛日期
|
|
|
- data_game = value.pop('data_game').split("/")
|
|
|
- month = str(data_game[1].strip())
|
|
|
- day = str(data_game[0])
|
|
|
- # 比赛时间
|
|
|
- time_game = str(value.pop('time_game'))
|
|
|
- # 比赛时间,时间戳
|
|
|
- ctime = "2019" + "-" + month + "-" + day + "" + time_game + ":00" #创建时间
|
|
|
- # match_date,match_time = new_time(ctime)
|
|
|
- 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 = value.pop('game_id')
|
|
|
- # 联赛id
|
|
|
- league_id = value.pop('league_id')
|
|
|
-
|
|
|
- #全场单
|
|
|
- odd_even_odd = value.get("odd_even_odd", "")
|
|
|
- #全场双
|
|
|
- odd_even_even = value.get("odd_even_even", "")
|
|
|
-
|
|
|
- #上半场单
|
|
|
- half_odd_even_odd = value.get("half_odd_even_odd","")
|
|
|
-
|
|
|
- #上半场双
|
|
|
- half_odd_even_even = value.get("half_odd_even_even", "")
|
|
|
-
|
|
|
-
|
|
|
- # 联赛name
|
|
|
- league_name = value.pop('league_name')
|
|
|
- # 主队
|
|
|
- team_home = value.pop('team_home')
|
|
|
- # 客队
|
|
|
- team_guest = value.pop('team_guest')
|
|
|
- # 主队得分
|
|
|
- score_home = value.pop('score_home')
|
|
|
- # 客队得分
|
|
|
- score_guest = value.pop('score_guest')
|
|
|
- # 全场让球
|
|
|
- # number
|
|
|
- number = value.pop('number')
|
|
|
- corner_ball = value.pop('corner_ball')
|
|
|
- half_way = value.pop('half_way')
|
|
|
- concede_home = value.get('concede_home', "")
|
|
|
- concede_home_rule = value.get('concede_home_rule', "")
|
|
|
- concede_guest = value.get("concede_guest", "")
|
|
|
- concede_guest_rule = value.get("concede_guest_rule", "")
|
|
|
- # 上半场让球
|
|
|
- half_concede_home = value.get("half_concede_home", "")
|
|
|
- half_concede_home_rule = value.get("half_concede_home_rule", "")
|
|
|
- half_concede_guest = value.get("half_concede_guest", "")
|
|
|
- half_concede_guest_rule = value.get("half_concede_guest_rule", "")
|
|
|
- # 全场大小
|
|
|
- size_home = value.get('size_home')
|
|
|
- size_home_rule = value.get('size_home')
|
|
|
- size_guest = value.get('size_guest')
|
|
|
- size_guest_rule = value.get('size_guest_rule', "")
|
|
|
- # 上半场大小
|
|
|
- half_size_home = value.get('half_size_home', "")
|
|
|
- half_size_home_rule = value.get('half_size_home_rule', "")
|
|
|
- half_size_guest = value.get('half_size_guset', "")
|
|
|
- half_size_guest_rule = value.get('half_size_guest_rule', "")
|
|
|
- score_status = value.pop('status')#比赛状态
|
|
|
- if score_status == "True":
|
|
|
- score_status = 1
|
|
|
- else:
|
|
|
- score_status = 0
|
|
|
-
|
|
|
- match_score = "{}:{}".format(score_home,score_guest)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- #如果角球存在
|
|
|
- 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 = "two_sides"
|
|
|
- p_id = 3
|
|
|
-
|
|
|
- if StZqResult.filter(match_id=key):
|
|
|
- StZqResult.update(update_time=utime,match_score=match_score,match_time=time_game,match_process=half_way,home_score=score_home,guest_score=score_guest).where(StZqResult.match_id == key).execute()
|
|
|
- else:
|
|
|
- StZqResult.create(match_id=key,match_score=match_score,home_team=team_home, guest_team=team_guest,home_score=score_home,guest_score=score_guest,all_goal=number,status=1,first_score='',last_score='',match_winer='',update_time=utime,match_time=time_game,match_process=half_way,tag=number,lg_id=league_id,u_home_score=0,u_guest_score=0,source='hg3535',p_code=p_code)
|
|
|
-
|
|
|
-
|
|
|
- #odd even 单 另外的是刷过 改condition 条件为 double
|
|
|
- if odd_even_odd:
|
|
|
- for index, result in enumerate(odd_even_odd):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="one_sides_single", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="one_sides_single", sort=index, p_id=p_id,odd=result)
|
|
|
- #更新赔率记录表
|
|
|
- if result == '.':
|
|
|
- result = 0
|
|
|
- StZqOddsRecord.create(odds_only=odds_only,lg_id=league_id,odds_code="one_sides_single",match_id=key,ctime=utime,utime=utime,odds=result,p_id=p_id,p_code=p_code,sort=index,source="hg3535",condition="单",is_rollball=1)
|
|
|
- st_zq_odd = StZqOdds.filter(sole=new_hash)
|
|
|
- if st_zq_odd: #sort的值?
|
|
|
- StZqOdds.update(utime=utime, odds=result,expire_time=expire_time,odds_only=odds_only,condition="单").where(StZqOdds.sole == new_hash).execute()
|
|
|
- else:
|
|
|
- StZqOdds.create(match_id=key, ctime=utime, utime=utime,source='hg3535',expire_time=expire_time,odds_only=odds_only,
|
|
|
- condition="单", odds=result, p_id=p_id,lg_id=league_id,odds_code="two_sides_single",
|
|
|
- p_code=p_code, sort=index,sole=new_hash,is_rollball=1)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- #双
|
|
|
- if odd_even_even:
|
|
|
- for index,result in enumerate(odd_even_even):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="two_sides_double", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="two_sides_double", sort=index, p_id=p_id,odd=result)
|
|
|
- #更新赔率记录表
|
|
|
- if result == '.':
|
|
|
- result = 0
|
|
|
- StZqOddsRecord.create(odds_only=odds_only,lg_id=league_id,odds_code="two_sides_double",match_id=key,ctime=utime,utime=utime,max=result,odds=result,p_id=p_id,p_code=p_code,sort=index,source="hg3535",condition="双",is_rollball=1)
|
|
|
- st_zq_odd = StZqOdds.filter(sole=new_hash)
|
|
|
- if st_zq_odd:
|
|
|
- StZqOdds.update(odds_only=odds_only,utime=utime, odds=result,expire_time=expire_time,condition="双").where(StZqOdds.sole == new_hash).execute()
|
|
|
- else:
|
|
|
- StZqOdds.create(match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',expire_time=expire_time,
|
|
|
- condition="双", odds=result, p_id=p_id,lg_id=league_id,odds_code="two_sides_double",
|
|
|
- p_code=p_code, sort=index,sole=new_hash,odds_only=odds_only,is_rollball=1)
|
|
|
-
|
|
|
-
|
|
|
- #上半场单
|
|
|
- if half_odd_even_odd:
|
|
|
- for index,result in enumerate(half_odd_even_odd):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="half_two_sides_single", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="half_two_sides_single", sort=index, p_id=p_id,odd=result)
|
|
|
- if result == '.':
|
|
|
- result = 0
|
|
|
- #更新赔率记录表
|
|
|
- StZqOddsRecord.create(odds_only=odds_only,lg_id=league_id,odds_code="half_two_sides_single",match_id=key,ctime=utime,utime=utime,max=result,odds=result,p_id=p_id,p_code=p_code,sort=index,source="hg3535",condition="单",is_rollball=1)
|
|
|
- st_zq_odd = StZqOdds.filter(sole=new_hash)
|
|
|
- if st_zq_odd:
|
|
|
- StZqOdds.update(odds_only=odds_only,utime=utime, odds=result, expire_time=expire_time,condition="单").where(StZqOdds.sole == new_hash).execute()
|
|
|
- else:
|
|
|
- StZqOdds.create(odds_only=odds_only,match_id=key,ctime=utime, utime=utime,max=result,source='hg3535',expire_time=expire_time,
|
|
|
- condition="单", odds=result, p_id=p_id,lg_id=league_id,odds_code="half_two_sides_single",
|
|
|
- p_code=p_code, sort=index,sole=new_hash,is_rollball=1)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- #上半场双
|
|
|
- if half_odd_even_even:
|
|
|
- for index,result in enumerate(half_odd_even_even):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="half_two_sides_double", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="half_two_sides_double", sort=index, p_id=p_id,odd=result)
|
|
|
- #更新赔率记录表
|
|
|
- if result == '.':
|
|
|
- result = 0
|
|
|
- StZqOddsRecord.create(odds_only=odds_only,lg_id=league_id,odds_code="half_two_sides_double",match_id=key,ctime=utime,utime=utime,max=result,odds=result,p_id=p_id,p_code=p_code,sort=index,source="hg3535",condition="双",is_rollball=1)
|
|
|
- st_zq_odd = StZqOdds.filter(sole=new_hash)
|
|
|
- if st_zq_odd:
|
|
|
- StZqOdds.update(odds_only=odds_only,utime=utime, odds=result, expire_time=expire_time,condition="双").where(StZqOdds.sole == new_hash).execute()
|
|
|
- else:
|
|
|
- StZqOdds.create(odds_only=odds_only,match_id=key,ctime=utime, utime=utime,max=result,source='hg3535',expire_time=expire_time,
|
|
|
- condition="双", odds=result, p_id=p_id,lg_id=league_id,odds_code="half_two_sides_double",
|
|
|
- p_code=p_code, sort=index,sole=new_hash,is_rollball=1)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- # 全场入球数 单双
|
|
|
- # if odd_even_odd:
|
|
|
- # # 构建唯一索引
|
|
|
- # new_hash = hash_func(match_id=competition_id, odds_code="two_sides_single", sort=0, p_id=p_id)
|
|
|
- # # 更新主队st_zq_odds表
|
|
|
- # odd_even_odd_sql1 = "insert into st_zq_odds(lg_id, odds_code, match_id, ctime, utime, max, odds, p_id, p_code, sort, source, sole,condition) values ( %s, %s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s,%s)on conflict(sole) do update set utime = %s,odds = %s;"
|
|
|
- # cursor.execute(odd_even_odd_sql1, (
|
|
|
- # int(league_id), "two_sides_single", int(competition_id), utime, utime, odd_even_odd, odd_even_odd, p_id,
|
|
|
- # p_code, 0, "hg3535", new_hash, "single", utime, odd_even_odd))
|
|
|
- # # 更新主队st_zq_odds_record表
|
|
|
- # odd_even_odd_sql2 = "insert into st_zq_odds_record(lg_id, odds_code, match_id, ctime, utime, max, odds, p_id, p_code, sort, source, condition) values (%s, %s, %s, %s, %s, %s, %s, %s,%s, %s, %s, %s);"
|
|
|
- # cursor.execute(odd_even_odd_sql2, (
|
|
|
- # int(league_id), "two_sides_single", int(competition_id), utime, utime, odd_even_odd, odd_even_odd, p_id,
|
|
|
- # p_code, 0, "hg3535", "single"))
|
|
|
- #
|
|
|
- # new_hash1 = hash_func(match_id=competition_id, odds_code="two_sides_double", sort=0, p_id=p_id)
|
|
|
- # # 更新主队st_zq_odds表
|
|
|
- # odd_even_even_sql1 = "insert into st_zq_odds(lg_id, odds_code, match_id, ctime, utime, max, odds, p_id, p_code, sort, source, sole,condition) values (%s, %s, %s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s)on conflict(sole) do update set utime = %s,odds = %s;"
|
|
|
- # cursor.execute(odd_even_odd_sql1, (
|
|
|
- # int(league_id), "two_sides_double", int(competition_id), utime, utime, odd_even_even, odd_even_even, p_id,
|
|
|
- # p_code, 0, "hg3535", new_hash1, "double", utime, odd_even_even))
|
|
|
- # # 更新主队st_zq_odds_record表
|
|
|
- # odd_even_even_sql2 = "insert into st_zq_odds_record(lg_id, odds_code, match_id, ctime, utime, max, odds, p_id, p_code, sort, source, condition) values (%s, %s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s);"
|
|
|
- # cursor.execute(odd_even_odd_sql2, (
|
|
|
- # int(league_id), "two_sides_double", int(competition_id), utime, utime, odd_even_even, odd_even_even, p_id,
|
|
|
- # p_code, 0, "hg3535", "double"))
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- #全场让球条件
|
|
|
- if concede_home:
|
|
|
- for index, result in enumerate(concede_home):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="concede_home", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="concede_home", sort=index, p_id=p_id,odd=result)
|
|
|
- st_zq_odd = StZqOdds.filter(sole=new_hash)
|
|
|
- if st_zq_odd:
|
|
|
- StZqOdds.update(odds_only=odds_only,utime=utime, odds=result,expire_time=expire_time,condition=concede_home_rule[index]).where(StZqOdds.sole == new_hash).execute()
|
|
|
- else:
|
|
|
- StZqOdds.create(odds_only=odds_only,match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',expire_time=expire_time,
|
|
|
- condition=concede_home_rule[index], odds=result, p_id=p_id,lg_id=league_id,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="concede_home",sole=new_hash)
|
|
|
-
|
|
|
-
|
|
|
- if concede_guest:
|
|
|
- for index, result in enumerate(concede_guest):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="concede_guest", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="concede_guest", sort=index, p_id=p_id,odd=result)
|
|
|
- st_zq_odd = StZqOdds.filter(sole=new_hash)
|
|
|
- if st_zq_odd:
|
|
|
- StZqOdds.update(odds_only=odds_only,utime=utime, odds=result,expire_time=expire_time,condition=concede_guest_rule[index]).where(StZqOdds.sole == new_hash).execute()
|
|
|
- else:
|
|
|
- StZqOdds.create(odds_only=odds_only,match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,
|
|
|
- condition=concede_guest_rule[index], odds=result, p_id=p_id,expire_time=expire_time,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="concede_guest",sole=new_hash)
|
|
|
-
|
|
|
- if half_concede_home:
|
|
|
- for index, result in enumerate(half_concede_home):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="half_concede_home", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="half_concede_home", sort=index, p_id=p_id,odd=result)
|
|
|
- st_zq_odd = StZqOdds.filter(sole=new_hash)
|
|
|
- if st_zq_odd:
|
|
|
- StZqOdds.update(odds_only=odds_only,utime=utime, odds=result,expire_time=expire_time,condition=half_concede_home_rule[index]).where(StZqOdds.sole == new_hash).execute()
|
|
|
- else:
|
|
|
- StZqOdds.create(odds_only=odds_only,match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,
|
|
|
- condition=half_concede_home_rule[index], odds=result, p_id=p_id,expire_time=expire_time,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="half_concede_home", sole=new_hash)
|
|
|
-
|
|
|
-
|
|
|
- if half_concede_guest:
|
|
|
- for index, result in enumerate(half_concede_guest):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="half_concede_guest", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="half_concede_guest", sort=index, p_id=p_id,odd=result)
|
|
|
- st_zq_odd = StZqOdds.filter(sole=new_hash)
|
|
|
- if st_zq_odd:
|
|
|
- StZqOdds.update(utime=utime, odds=result,expire_time=expire_time,odds_only=odds_only,condition=half_concede_guest_rule[index]).where(StZqOdds.sole == new_hash).execute()
|
|
|
- else:
|
|
|
- StZqOdds.create(match_id=key, ctime=utime, utime=utime,source='hg3535',lg_id=league_id,
|
|
|
- max=half_concede_guest[index],expire_time=expire_time,odds_only=odds_only,
|
|
|
- condition=half_concede_guest_rule[index],is_rollball=1,
|
|
|
- odds=half_concede_guest[index], p_id=p_id, p_code=p_code,
|
|
|
- sort=index, odds_code="half_concede_guest", sole=new_hash)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- if size_home:
|
|
|
- for index, result in enumerate(size_home):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="size_home", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="size_home", sort=index, p_id=p_id,odd=result)
|
|
|
- st_zq_odd = StZqOdds.filter(sole=new_hash)
|
|
|
- if st_zq_odd:
|
|
|
- StZqOdds.update(odds_only=odds_only,utime=utime, odds=result,expire_time=expire_time,condition=size_home_rule[index]).where(StZqOdds.sole == new_hash).execute()
|
|
|
- else:
|
|
|
- StZqOdds.create(odds_only=odds_only,match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,
|
|
|
- condition=size_home_rule[index], odds=result, p_id=p_id,expire_time=expire_time,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="size_home", sole=new_hash)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- if size_guest:
|
|
|
- for index, result in enumerate(size_guest):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="size_guest", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="size_guest", sort=index, p_id=p_id,odd=result)
|
|
|
- st_zq_odd = StZqOdds.filter(sole=new_hash)
|
|
|
- if st_zq_odd:
|
|
|
- StZqOdds.update(odds_only=odds_only,utime=utime, odds=result,expire_time=expire_time,condition=size_guest_rule[index]).where(StZqOdds.sole == new_hash).execute()
|
|
|
- else:
|
|
|
- StZqOdds.create(odds_only=odds_only,match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,
|
|
|
- condition=size_guest_rule[index], odds=result, p_id=p_id,expire_time=expire_time,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="size_guest",sole=new_hash)
|
|
|
-
|
|
|
-
|
|
|
- if half_size_home:
|
|
|
- for index, result in enumerate(half_size_home):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="half_size_home", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="half_size_home", sort=index, p_id=p_id,odd=result)
|
|
|
- st_zq_odd = StZqOdds.filter(sole=new_hash)
|
|
|
- if st_zq_odd:
|
|
|
- StZqOdds.update(odds_only=odds_only,utime=utime, odds=result,expire_time=expire_time,condition=half_size_home_rule[index]).where(StZqOdds.sole == new_hash).execute()
|
|
|
- else:
|
|
|
- StZqOdds.create(odds_only=odds_only,match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,
|
|
|
- condition=half_size_home_rule[index], odds=result, p_id=p_id,expire_time=expire_time,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="half_size_home",sole=new_hash)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- if half_size_guest:
|
|
|
- for index, result in enumerate(half_size_guest):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="half_size_guest", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="half_size_guest", sort=index, p_id=p_id,odd=result)
|
|
|
- st_zq_odd = StZqOdds.filter(sole=new_hash)
|
|
|
- if st_zq_odd:
|
|
|
- StZqOdds.update(utime=utime, odds=result,expire_time=expire_time,odds_only=odds_only,condition=half_size_guest_rule[index]).where(StZqOdds.sole==new_hash).execute()
|
|
|
- else:
|
|
|
- StZqOdds.create(odds_only=odds_only,match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,
|
|
|
- condition=half_size_guest_rule[index], odds=result, p_id=p_id,expire_time=expire_time,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="half_size_guest",sole=new_hash)
|
|
|
-
|
|
|
- #赔率插入记录表
|
|
|
-
|
|
|
- if concede_home:
|
|
|
- for index, result in enumerate(concede_home):
|
|
|
- new_hash1 = hash_func(match_id=key, odds_code="concede_home", sort=index, p_id=p_id)
|
|
|
- odds_only1 = r_func(match_id=key, odds_code="concede_home", sort=index, p_id=p_id,odd=result)
|
|
|
- new_hash2 = hash_func(match_id=key, odds_code="concede_guest", sort=index, p_id=p_id)
|
|
|
- odds_only2 = r_func(match_id=key, odds_code="concede_guest", sort=index, p_id=p_id,odd=result)
|
|
|
- StZqOddsRecord.create(odds_only=odds_only1,match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',
|
|
|
- condition=concede_home_rule[index], odds=result, p_id=p_id,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="concede_home",sole=new_hash1)
|
|
|
- StZqOddsRecord.create(odds_only= odds_only2,match_id=key, ctime=utime, utime=utime, max=concede_guest[index],source='hg3535',lg_id=league_id,
|
|
|
- condition=concede_guest_rule[index], odds=concede_guest[index],
|
|
|
- p_id=p_id, p_code=p_code, sort=index,is_rollball=1,
|
|
|
- odds_code="concede_guest",sole=new_hash2)
|
|
|
-
|
|
|
-
|
|
|
- if half_concede_home:
|
|
|
- for index, result in enumerate(half_concede_home):
|
|
|
- new_hash1 = hash_func(match_id=key, odds_code="half_concede_home", sort=index, p_id=p_id)
|
|
|
- odds_only1 = r_func(match_id=key, odds_code="half_concede_home", sort=index, p_id=p_id,odd=result)
|
|
|
- new_hash2 = hash_func(match_id=key, odds_code="half_concede_guest", sort=index, p_id=p_id)
|
|
|
- odds_only2 = r_func(match_id=key, odds_code="half_concede_guest", sort=index, p_id=p_id,odd=result)
|
|
|
- StZqOddsRecord.create(odds_only=odds_only1,match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,
|
|
|
- condition=half_concede_home_rule[index], odds=result, p_id=p_id,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="half_concede_home",sole=new_hash1)
|
|
|
- StZqOddsRecord.create(odds_only=odds_only2,match_id=key, ctime=utime, utime=utime,lg_id=league_id,
|
|
|
- max=half_concede_guest[index],is_rollball=1,
|
|
|
- source='hg3535',
|
|
|
- condition=half_concede_guest_rule[index],
|
|
|
- odds=half_concede_guest[index], p_id=p_id, p_code=p_code,
|
|
|
- sort=index, odds_code="half_concede_guest",sole=new_hash2)
|
|
|
-
|
|
|
-
|
|
|
- if size_home:
|
|
|
- for index, result in enumerate(size_home):
|
|
|
- new_hash1 = hash_func(match_id=key, odds_code="size_home", sort=index, p_id=p_id)
|
|
|
- odds_only1 = r_func(match_id=key, odds_code="size_home", sort=index, p_id=p_id,odd=result)
|
|
|
-
|
|
|
- new_hash2 = hash_func(match_id=key, odds_code="size_guest", sort=index, p_id=p_id)
|
|
|
- odds_only2 = r_func(match_id=key, odds_code="size_guest", sort=index, p_id=p_id,odd=result)
|
|
|
-
|
|
|
- StZqOddsRecord.create(odds_only=odds_only1,match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,
|
|
|
- condition=size_home_rule[index], odds=result, p_id=p_id,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="size_home",sole=new_hash1)
|
|
|
- StZqOddsRecord.create(odds_only=odds_only2,match_id=key, ctime=utime, utime=utime, max=size_guest[index],source='hg3535',lg_id=league_id,
|
|
|
- condition=size_guest_rule[index], odds=size_guest[index], p_id=p_id,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="size_guest",sole=new_hash2)
|
|
|
-
|
|
|
-
|
|
|
- if half_size_home:
|
|
|
- for index, result in enumerate(half_size_home):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="half_size_home", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="half_size_home", sort=index, p_id=p_id,odd=result)
|
|
|
- StZqOddsRecord.create(odds_only=odds_only,match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,
|
|
|
- condition=half_size_home_rule[index], odds=result, p_id=p_id,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="half_size_home",sole=new_hash)
|
|
|
- if half_size_guest:
|
|
|
- for index, result in enumerate(half_size_guest):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="half_size_guest", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="half_size_guest", sort=index, p_id=p_id,odd=result)
|
|
|
- StZqOddsRecord.create(odds_only=odds_only,match_id=key, ctime=utime, utime=utime, max=half_size_guest[index],lg_id=league_id,
|
|
|
- condition=half_size_guest_rule[index], odds=half_size_guest[index],
|
|
|
- p_id=p_id, p_code=p_code, sort=index,source='hg3535',is_rollball=1,
|
|
|
- odds_code="half_size_guest",sole=new_hash)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- #赛事表
|
|
|
- if StZqCompetition.filter(match_id=key):
|
|
|
- StZqCompetition.update(expire_time= expire_time,utime=utime,status=score_status,tag=number).where(StZqCompetition.match_id == key).execute()
|
|
|
- else:
|
|
|
- StZqCompetition.create(expire_time= expire_time,home_team=team_home,guest_team=team_guest,lg_id=league_id,status=score_status,match_id=key,match_date=r_ctime,match_time='00:00:00',ctime=utime,utime=utime,tag=number,source='hg3535',type=4,ptime=time_game,us_time='2019-01-01 00:00:00')
|
|
|
-
|
|
|
-
|
|
|
- # #更新记录表 具体更新哪些值目前随便写未知
|
|
|
- # if StZqResultRecord.filter(match_id=key):
|
|
|
- # StZqResultRecord.update(update_time=utime, status=score_status,match_score=match_score,match_time=time_game).where(StZqResultRecord.match_id == key).execute()
|
|
|
- # else:
|
|
|
- StZqResultRecord.create(lg_id=league_id,home_team=team_home,guest_team=team_guest,home_score=score_home,guest_score=score_guest,all_goal=number,status=1,first_score='',last_score='',match_score=match_score,match_winer='',update_time=utime,match_time=time_game,match_process=half_way,tag=number,match_id=key,source='hg3535',p_code=p_code)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- # for k, v in value.items():
|
|
|
- # if v:
|
|
|
- # for index, result in enumerate(v):
|
|
|
- # st_zq_odd = StZqResult.filter(match_id=key, sort=index, odds_code=k,p_code="concede_size")
|
|
|
- # if st_zq_odd:
|
|
|
- # if result:
|
|
|
- # StZqResult.update(utime=utime, odds=result).where(StZqResult.match_id == key,StZqResult.sort == index,StZqResult.odds_code == k).execute()
|
|
|
- # else:
|
|
|
- # if result:
|
|
|
- # StZqResult.create(match_id=key, ctime=ctime, utime=utime, max=result,condition=concede_home_rule[index], odds=result, p_id=1,p_code="concede_size", sort=index, odds_code=k)
|
|
|
- # else:
|
|
|
- # for k, v in value.items():
|
|
|
- # if v:
|
|
|
- # for index, result in enumerate(v):
|
|
|
- # if result:
|
|
|
- # StZqResult.create(match_id=key, cp_id=competition_id, host_name=team_home, guest_name=team_guest,home_rate=score_home, guest_rate=score_guest,all_goal=1,status=1,first_score='1',last_score='1',match_score='1',match_winer='1',update_time=utime,match_time='1',match_process='1',tag=1)
|
|
|
-
|
|
|
- total_goal = item.get('total_goal', "")
|
|
|
- if total_goal:
|
|
|
- with database.atomic():
|
|
|
- #key 联赛id
|
|
|
- for key, value in total_goal.items():
|
|
|
- # 比赛日期
|
|
|
- data_game = value.pop('data_game').split("/")
|
|
|
- month = str(data_game[1].strip())
|
|
|
- day = str(data_game[0])
|
|
|
- # 比赛时间
|
|
|
- time_game = str(value.pop('time_game'))
|
|
|
- # 比赛时间,时间戳
|
|
|
- ctime = "2019" + "-" + month + "-" + day + "" + time_game + ":00" #创建时间
|
|
|
- # match_date,match_time = new_time(ctime)
|
|
|
- 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 = value.pop('game_id')
|
|
|
- # 联赛id
|
|
|
- league_id = value.pop('league_id')
|
|
|
- # 联赛name
|
|
|
- league_name = value.pop('league_name')
|
|
|
- # 主队
|
|
|
- team_home = value.pop('team_home')
|
|
|
- # 客队
|
|
|
- team_guest = value.pop('team_guest')
|
|
|
- # 主队得分
|
|
|
- score_home = value.pop('score_home')
|
|
|
- # 客队得分
|
|
|
- score_guest = value.pop('score_guest')
|
|
|
- # 全场让球
|
|
|
- # number
|
|
|
- number = value.pop('number')
|
|
|
- corner_ball = value.pop('corner_ball')
|
|
|
- half_way = value.pop('half_way')
|
|
|
- concede_home = value.get('concede_home', "")
|
|
|
- concede_home_rule = value.get('concede_home_rule', "")
|
|
|
- concede_guest = value.get("concede_guest", "")
|
|
|
- concede_guest_rule = value.get("concede_guest_rule", "")
|
|
|
- # 上半场让球
|
|
|
- half_concede_home = value.get("half_concede_home", "")
|
|
|
- half_concede_home_rule = value.get("half_concede_home_rule", "")
|
|
|
- half_concede_guest = value.get("half_concede_guest", "")
|
|
|
- half_concede_guest_rule = value.get("half_concede_guest_rule", "")
|
|
|
- # 全场大小
|
|
|
- size_home = value.get('size_home')
|
|
|
- size_home_rule = value.get('size_home')
|
|
|
- size_guest = value.get('size_guest')
|
|
|
- size_guest_rule = value.get('size_guest_rule', "")
|
|
|
- # 上半场大小
|
|
|
- half_size_home = value.get('half_size_home', "")
|
|
|
- half_size_home_rule = value.get('half_size_home_rule', "")
|
|
|
- half_size_guest = value.get('half_size_guset', "")
|
|
|
- half_size_guest_rule = value.get('half_size_guest_rule', "")
|
|
|
- score_status = value.get('status',"")#比赛状态
|
|
|
-
|
|
|
- if score_status == "True":
|
|
|
- score_status = 1
|
|
|
- else:
|
|
|
- score_status = 0
|
|
|
-
|
|
|
- match_score = "{}:{}".format(score_home,score_guest)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- #如果角球存在
|
|
|
- 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 = "two_sides"
|
|
|
- p_id = 4
|
|
|
-
|
|
|
- if StZqResult.filter(match_id=key):
|
|
|
- StZqResult.update(update_time=utime,match_score=match_score,match_time=time_game,match_process=half_way,home_score=score_home,guest_score=score_guest).where(StZqResult.match_id == key).execute()
|
|
|
- else:
|
|
|
- StZqResult.create(match_id=key,match_score=match_score,home_team=team_home, guest_team=team_guest,home_score=score_home,guest_score=score_guest,all_goal=number,status=1,first_score='',last_score='',match_winer='',update_time=utime,match_time=time_game,match_process=half_way,tag=number,lg_id=league_id,u_home_score=0,u_guest_score=0,source='hg3535',p_code=p_code)
|
|
|
-
|
|
|
- #全场让球条件
|
|
|
- if concede_home:
|
|
|
- for index, result in enumerate(concede_home):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="concede_home", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="concede_home", sort=index, p_id=p_id,odd=result)
|
|
|
- st_zq_odd = StZqOdds.filter(sole=new_hash)
|
|
|
- if st_zq_odd:
|
|
|
- StZqOdds.update(odds_only=odds_only,utime=utime, odds=result,expire_time=expire_time,condition=concede_home_rule[index]).where(StZqOdds.sole == new_hash).execute()
|
|
|
- else:
|
|
|
- StZqOdds.create(odds_only=odds_only,match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,
|
|
|
- condition=concede_home_rule[index], odds=result, p_id=p_id,expire_time=expire_time,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="concede_home",sole=new_hash)
|
|
|
-
|
|
|
-
|
|
|
- if concede_guest:
|
|
|
- for index, result in enumerate(concede_guest):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="concede_guest", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="concede_guest", sort=index, p_id=p_id,odd=result)
|
|
|
- st_zq_odd = StZqOdds.filter(sole=new_hash)
|
|
|
- if st_zq_odd:
|
|
|
- StZqOdds.update(odds_only=odds_only,utime=utime, odds=result,expire_time=expire_time,condition=concede_guest_rule[index]).where(StZqOdds.sole == new_hash).execute()
|
|
|
- else:
|
|
|
- StZqOdds.create(odds_only=odds_only,match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,
|
|
|
- condition=concede_guest_rule[index], odds=result, p_id=p_id,expire_time=expire_time,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="concede_guest",sole=new_hash)
|
|
|
-
|
|
|
- if half_concede_home:
|
|
|
- for index, result in enumerate(half_concede_home):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="half_concede_home", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="half_concede_home", sort=index, p_id=p_id,odd=result)
|
|
|
- st_zq_odd = StZqOdds.filter(sole=new_hash)
|
|
|
- if st_zq_odd:
|
|
|
- StZqOdds.update(odds_only=odds_only,utime=utime, odds=result,expire_time=expire_time,condition=half_concede_home_rule[index]).where(StZqOdds.sole == new_hash).execute()
|
|
|
- else:
|
|
|
- StZqOdds.create(odds_only=odds_only,match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,
|
|
|
- condition=half_concede_home_rule[index], odds=result, p_id=p_id,expire_time=expire_time,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="half_concede_home", sole=new_hash)
|
|
|
-
|
|
|
-
|
|
|
- if half_concede_guest:
|
|
|
- for index, result in enumerate(half_concede_guest):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="half_concede_guest", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="half_concede_guest", sort=index, p_id=p_id,odd=result)
|
|
|
- st_zq_odd = StZqOdds.filter(sole=new_hash)
|
|
|
- if st_zq_odd:
|
|
|
- StZqOdds.update(odds_only=odds_only,utime=utime, odds=result,expire_time=expire_time,condition=half_concede_guest_rule[index]).where(StZqOdds.sole == new_hash).execute()
|
|
|
- else:
|
|
|
- StZqOdds.create(odds_only=odds_only,match_id=key, ctime=utime, utime=utime,lg_id=league_id,expire_time=expire_time,
|
|
|
- source='hg3535',is_rollball=1,
|
|
|
- max=half_concede_guest[index],
|
|
|
- condition=half_concede_guest_rule[index],
|
|
|
- odds=half_concede_guest[index], p_id=p_id, p_code=p_code,
|
|
|
- sort=index, odds_code="half_concede_guest", sole=new_hash)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- if size_home:
|
|
|
- for index, result in enumerate(size_home):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="size_home", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="size_home", sort=index, p_id=p_id,odd=result)
|
|
|
- st_zq_odd = StZqOdds.filter(sole=new_hash)
|
|
|
- if st_zq_odd:
|
|
|
- StZqOdds.update(odds_only=odds_only,utime=utime, odds=result,expire_time=expire_time,condition=size_home_rule[index]).where(StZqOdds.sole == new_hash).execute()
|
|
|
- else:
|
|
|
- StZqOdds.create(odds_only=odds_only,match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,
|
|
|
- condition=size_home_rule[index], odds=result, p_id=p_id,expire_time=expire_time,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="size_home", sole=new_hash)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- if size_guest:
|
|
|
- for index, result in enumerate(size_guest):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="size_guest", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="size_guest", sort=index, p_id=p_id,odd=result)
|
|
|
- st_zq_odd = StZqOdds.filter(sole=new_hash)
|
|
|
- if st_zq_odd:
|
|
|
- StZqOdds.update(odds_only=odds_only,utime=utime, odds=result,expire_time=expire_time,condition=size_guest_rule[index]).where(StZqOdds.sole == new_hash).execute()
|
|
|
- else:
|
|
|
- StZqOdds.create(odds_only=odds_only,match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,
|
|
|
- condition=size_guest_rule[index], odds=result, p_id=p_id,expire_time=expire_time,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="size_guest",sole=new_hash)
|
|
|
-
|
|
|
-
|
|
|
- if half_size_home:
|
|
|
- for index, result in enumerate(half_size_home):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="half_size_home", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="half_size_home", sort=index, p_id=p_id,odd=result)
|
|
|
- st_zq_odd = StZqOdds.filter(sole=new_hash)
|
|
|
- if st_zq_odd:
|
|
|
- StZqOdds.update(odds_only=odds_only,utime=utime, odds=result,expire_time=expire_time,condition=half_size_home_rule[index]).where(StZqOdds.sole == new_hash).execute()
|
|
|
- else:
|
|
|
- StZqOdds.create(odds_only=odds_only,match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,
|
|
|
- condition=half_size_home_rule[index], odds=result, p_id=p_id,expire_time=expire_time,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="half_size_home",sole=new_hash)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- if half_size_guest:
|
|
|
- for index, result in enumerate(half_size_guest):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="half_size_guest", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="half_size_guest", sort=index, p_id=p_id,odd=result)
|
|
|
- st_zq_odd = StZqOdds.filter(sole=new_hash)
|
|
|
- if st_zq_odd:
|
|
|
- StZqOdds.update(odds_only=odds_only,utime=utime, odds=result,expire_time=expire_time,condition=half_size_guest_rule[index]).where(StZqOdds.sole==new_hash).execute()
|
|
|
- else:
|
|
|
- StZqOdds.create(odds_only=odds_only,match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,
|
|
|
- condition=half_size_guest_rule[index], odds=result, p_id=p_id,expire_time=expire_time,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="half_size_guest",sole=new_hash)
|
|
|
-
|
|
|
- #赔率插入记录表
|
|
|
-
|
|
|
- if concede_home:
|
|
|
- for index, result in enumerate(concede_home):
|
|
|
- new_hash1 = hash_func(match_id=key, odds_code="concede_home", sort=index, p_id=p_id)
|
|
|
- odds_only1 = r_func(match_id=key, odds_code="concede_home", sort=index, p_id=p_id,odd=result)
|
|
|
- new_hash2 = hash_func(match_id=key, odds_code="concede_guest", sort=index, p_id=p_id)
|
|
|
- odds_only2 = r_func(match_id=key, odds_code="concede_guest", sort=index, p_id=p_id,odd=result)
|
|
|
- StZqOddsRecord.create(odds_only=odds_only1,match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,
|
|
|
- condition=concede_home_rule[index], odds=result, p_id=p_id,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="concede_home",sole=new_hash1)
|
|
|
- StZqOddsRecord.create(odds_only=odds_only2,match_id=key, ctime=utime, utime=utime, max=concede_guest[index],lg_id=league_id,
|
|
|
- condition=concede_guest_rule[index], odds=concede_guest[index],
|
|
|
- p_id=p_id, p_code=p_code, sort=index,source='hg3535',is_rollball=1,
|
|
|
- odds_code="concede_guest",sole=new_hash2)
|
|
|
-
|
|
|
-
|
|
|
- if half_concede_home:
|
|
|
- for index, result in enumerate(half_concede_home):
|
|
|
- new_hash1 = hash_func(match_id=key, odds_code="half_concede_home", sort=index, p_id=p_id)
|
|
|
- odds_only1 = r_func(match_id=key, odds_code="half_concede_home", sort=index, p_id=p_id,odd=result)
|
|
|
- new_hash2 = hash_func(match_id=key, odds_code="half_concede_guest", sort=index, p_id=p_id)
|
|
|
- odds_only2 = r_func(match_id=key, odds_code="half_concede_guest", sort=index, p_id=p_id,odd=result)
|
|
|
- StZqOddsRecord.create(odds_only=odds_only1,match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,
|
|
|
- condition=half_concede_home_rule[index], odds=result, p_id=p_id,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="half_concede_home",sole=new_hash1)
|
|
|
- StZqOddsRecord.create(odds_only=odds_only2,match_id=key, ctime=utime, utime=utime,source='hg3535',lg_id=league_id,
|
|
|
- max=half_concede_guest[index],is_rollball=1,
|
|
|
- condition=half_concede_guest_rule[index],
|
|
|
- odds=half_concede_guest[index], p_id=p_id, p_code=p_code,
|
|
|
- sort=index, odds_code="half_concede_guest",sole=new_hash2)
|
|
|
-
|
|
|
-
|
|
|
- if size_home:
|
|
|
- for index, result in enumerate(size_home):
|
|
|
- new_hash1 = hash_func(match_id=key, odds_code="size_home", sort=index, p_id=p_id)
|
|
|
- odds_only1 = r_func(match_id=key, odds_code="size_home", sort=index, p_id=p_id,odd=result)
|
|
|
- new_hash2 = hash_func(match_id=key, odds_code="size_guest", sort=index, p_id=p_id)
|
|
|
- odds_only2 = r_func(match_id=key, odds_code="size_guest", sort=index, p_id=p_id,odd=result)
|
|
|
- StZqOddsRecord.create(odds_only=odds_only1,match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,
|
|
|
- condition=size_home_rule[index], odds=result, p_id=p_id,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="size_home",sole=new_hash1)
|
|
|
- StZqOddsRecord.create(odds_only=odds_only2,match_id=key, ctime=utime, utime=utime, max=size_guest[index],source='hg3535',
|
|
|
- condition=size_guest_rule[index], odds=size_guest[index], p_id=p_id,lg_id=league_id,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="size_guest",sole=new_hash2)
|
|
|
-
|
|
|
-
|
|
|
- if half_size_home:
|
|
|
- for index, result in enumerate(half_size_home):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="half_size_home", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="half_size_home", sort=index, p_id=p_id,odd=result)
|
|
|
- StZqOddsRecord.create(odds_only=odds_only,match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,
|
|
|
- condition=half_size_home_rule[index], odds=result, p_id=p_id,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="half_size_home",sole=new_hash)
|
|
|
- if half_size_guest:
|
|
|
- for index, result in enumerate(half_size_guest):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="half_size_guest", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="half_size_guest", sort=index, p_id=p_id,odd=result)
|
|
|
- StZqOddsRecord.create(odds_only=odds_only,match_id=key, ctime=utime, utime=utime, max=half_size_guest[index],lg_id=league_id,
|
|
|
- condition=half_size_guest_rule[index], odds=half_size_guest[index],
|
|
|
- p_id=p_id, p_code=p_code, sort=index,source='hg3535',is_rollball=1,
|
|
|
- odds_code="half_size_guest",sole=new_hash)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- #赛事表
|
|
|
- if StZqCompetition.filter(match_id=key):
|
|
|
- StZqCompetition.update(is_rollball=1,utime=utime,status=score_status,tag=number,expire_time=expire_time).where(StZqCompetition.match_id == key).execute()
|
|
|
- else:
|
|
|
- StZqCompetition.create(is_rollball=1,home_team=team_home,guest_team=team_guest,lg_id=league_id,status=score_status,match_id=key,match_date=r_ctime,match_time='00:00:00',ctime=utime,utime=utime,tag=number,source='hg3535',type=4,ptime=time_game,expire_time=expire_time,us_time='2019-01-01 00:00:00')
|
|
|
-
|
|
|
-
|
|
|
- #更新记录表 具体更新哪些值目前随便写未知
|
|
|
- # if StZqResultRecord.filter(match_id=key):
|
|
|
- # StZqResultRecord.update(update_time=utime, status=score_status,match_score=match_score,match_time=time_game).where(StZqResultRecord.match_id == key).execute()
|
|
|
- # else:
|
|
|
- StZqResultRecord.create(lg_id=league_id,home_team=team_home,guest_team=team_guest,home_score=score_home,guest_score=score_guest,all_goal=number,status=1,first_score='',last_score='',match_score=match_score,match_winer='',update_time=utime,match_time=time_game,match_process=half_way,tag=number,match_id=key,source='hg3535',p_code=p_code)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- # for k, v in value.items():
|
|
|
- # if v:
|
|
|
- # for index, result in enumerate(v):
|
|
|
- # st_zq_odd = StZqResult.filter(match_id=key, sort=index, odds_code=k,p_code="concede_size")
|
|
|
- # if st_zq_odd:
|
|
|
- # if result:
|
|
|
- # StZqResult.update(utime=utime, odds=result).where(StZqResult.match_id == key,StZqResult.sort == index,StZqResult.odds_code == k).execute()
|
|
|
- # else:
|
|
|
- # if result:
|
|
|
- # StZqResult.create(match_id=key, ctime=ctime, utime=utime, max=result,condition=concede_home_rule[index], odds=result, p_id=1,p_code="concede_size", sort=index, odds_code=k)
|
|
|
- # else:
|
|
|
- # for k, v in value.items():
|
|
|
- # if v:
|
|
|
- # for index, result in enumerate(v):
|
|
|
- # if result:
|
|
|
- # StZqResult.create(match_id=key, cp_id=competition_id, host_name=team_home, guest_name=team_guest,home_rate=score_home, guest_rate=score_guest,all_goal=1,status=1,first_score='1',last_score='1',match_score='1',match_winer='1',update_time=utime,match_time='1',match_process='1',tag=1)
|
|
|
-
|
|
|
- half_full = item.get('half_full', "")
|
|
|
- if half_full:
|
|
|
- with database.atomic():
|
|
|
- #key 联赛id
|
|
|
- for key, value in half_full.items():
|
|
|
- # 比赛日期
|
|
|
- data_game = value.pop('data_game').split("/")
|
|
|
- month = str(data_game[1].strip())
|
|
|
- day = str(data_game[0])
|
|
|
- # 比赛时间
|
|
|
- time_game = str(value.pop('time_game'))
|
|
|
- # 比赛时间,时间戳
|
|
|
- ctime = "2019" + "-" + month + "-" + day + "" + time_game + ":00" #创建时间
|
|
|
- # match_date,match_time = new_time(ctime)
|
|
|
- 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 = value.pop('game_id')
|
|
|
- # 联赛id
|
|
|
- league_id = value.pop('league_id')
|
|
|
- # 联赛name
|
|
|
- league_name = value.pop('league_name')
|
|
|
- # 主队
|
|
|
- team_home = value.pop('team_home')
|
|
|
- # 客队
|
|
|
- team_guest = value.pop('team_guest')
|
|
|
- # 主队得分
|
|
|
- score_home = value.pop('score_home')
|
|
|
- # 客队得分
|
|
|
- score_guest = value.pop('score_guest')
|
|
|
- # 全场让球
|
|
|
- # number
|
|
|
- number = value.pop('number')
|
|
|
- corner_ball = value.pop('corner_ball')
|
|
|
- half_way = value.pop('half_way')
|
|
|
- concede_home = value.get('concede_home', "")
|
|
|
- concede_home_rule = value.get('concede_home_rule', "")
|
|
|
- concede_guest = value.get("concede_guest", "")
|
|
|
- concede_guest_rule = value.get("concede_guest_rule", "")
|
|
|
- # 上半场让球
|
|
|
- half_concede_home = value.get("half_concede_home", "")
|
|
|
- half_concede_home_rule = value.get("half_concede_home_rule", "")
|
|
|
- half_concede_guest = value.get("half_concede_guest", "")
|
|
|
- half_concede_guest_rule = value.get("half_concede_guest_rule", "")
|
|
|
- # 全场大小
|
|
|
- size_home = value.get('size_home')
|
|
|
- size_home_rule = value.get('size_home')
|
|
|
- size_guest = value.get('size_guest')
|
|
|
- size_guest_rule = value.get('size_guest_rule', "")
|
|
|
- # 上半场大小
|
|
|
- half_size_home = value.get('half_size_home', "")
|
|
|
- half_size_home_rule = value.get('half_size_home_rule', "")
|
|
|
- half_size_guest = value.get('half_size_guset', "")
|
|
|
- half_size_guest_rule = value.get('half_size_guest_rule', "")
|
|
|
- score_status = value.get('status','')#比赛状态
|
|
|
- if score_status == "True":
|
|
|
- score_status = 1
|
|
|
- else:
|
|
|
- score_status = 0
|
|
|
-
|
|
|
- match_score = "{}:{}".format(score_home,score_guest)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- #如果角球存在
|
|
|
- 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 = "two_sides"
|
|
|
- p_id = 5
|
|
|
-
|
|
|
- if StZqResult.filter(match_id=key):
|
|
|
- StZqResult.update(update_time=utime,match_score=match_score,match_time=time_game,match_process=half_way,home_score=score_home,guest_score=score_guest).where(StZqResult.match_id == key).execute()
|
|
|
- else:
|
|
|
- StZqResult.create(match_id=key,match_score=match_score,home_team=team_home, guest_team=team_guest,home_score=score_home,guest_score=score_guest,all_goal=number,status=1,first_score='',last_score='',match_winer='',update_time=utime,match_time=time_game,match_process=half_way,tag=number,lg_id=league_id,u_home_score=0,u_guest_score=0,source='hg3535',p_code=p_code)
|
|
|
-
|
|
|
-
|
|
|
- #全场让球条件
|
|
|
- if concede_home:
|
|
|
- for index, result in enumerate(concede_home):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="concede_home", sort=index, p_id=p_id,pt=4)
|
|
|
- odds_only = r_func(match_id=key, odds_code="concede_home", sort=index, p_id=p_id,pt=4,odd=result)
|
|
|
- st_zq_odd = StZqOdds.filter(sole=new_hash)
|
|
|
- if st_zq_odd:
|
|
|
- StZqOdds.update(odds_only=odds_only,utime=utime, odds=result,expire_time=expire_time,condition=concede_home_rule[index]).where(StZqOdds.sole == new_hash).execute()
|
|
|
- else:
|
|
|
- StZqOdds.create(odds_only=odds_only,match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,
|
|
|
- condition=concede_home_rule[index], odds=result, p_id=p_id,expire_time=expire_time,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="concede_home",sole=new_hash)
|
|
|
-
|
|
|
-
|
|
|
- if concede_guest:
|
|
|
- for index, result in enumerate(concede_guest):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="concede_guest", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="concede_guest", sort=index, p_id=p_id,odd=result)
|
|
|
- st_zq_odd = StZqOdds.filter(sole=new_hash)
|
|
|
- if st_zq_odd:
|
|
|
- StZqOdds.update(odds_only=odds_only,utime=utime, odds=result,expire_time=expire_time,condition=concede_guest_rule[index]).where(StZqOdds.sole == new_hash).execute()
|
|
|
- else:
|
|
|
- StZqOdds.create(odds_only=odds_only,match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,
|
|
|
- condition=concede_guest_rule[index], odds=result, p_id=p_id,expire_time=expire_time,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="concede_guest",sole=new_hash)
|
|
|
-
|
|
|
- if half_concede_home:
|
|
|
- for index, result in enumerate(half_concede_home):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="half_concede_home", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="half_concede_home", sort=index, p_id=p_id,odd=result)
|
|
|
- st_zq_odd = StZqOdds.filter(sole=new_hash)
|
|
|
- if st_zq_odd:
|
|
|
- StZqOdds.update(odds_only=odds_only,utime=utime, odds=result,expire_time=expire_time,condition=half_concede_home_rule[index]).where(StZqOdds.sole == new_hash).execute()
|
|
|
- else:
|
|
|
- StZqOdds.create(odds_only=odds_only,match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,
|
|
|
- condition=half_concede_home_rule[index], odds=result, p_id=p_id,expire_time=expire_time,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="half_concede_home", sole=new_hash)
|
|
|
-
|
|
|
-
|
|
|
- if half_concede_guest:
|
|
|
- for index, result in enumerate(half_concede_guest):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="half_concede_guest", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="half_concede_guest", sort=index, p_id=p_id,odd=result)
|
|
|
- st_zq_odd = StZqOdds.filter(sole=new_hash)
|
|
|
- if st_zq_odd:
|
|
|
- StZqOdds.update(odds_only=odds_only,utime=utime, odds=result,expire_time=expire_time,condition=half_concede_guest_rule[index]).where(StZqOdds.sole == new_hash).execute()
|
|
|
- else:
|
|
|
- StZqOdds.create(odds_only=odds_only,match_id=key, ctime=utime, utime=utime,source='hg3535',lg_id=league_id,expire_time=expire_time,
|
|
|
- max=half_concede_guest[index],is_rollball=1,
|
|
|
- condition=half_concede_guest_rule[index],
|
|
|
- odds=half_concede_guest[index], p_id=p_id, p_code=p_code,
|
|
|
- sort=index, odds_code="half_concede_guest", sole=new_hash)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- if size_home:
|
|
|
- for index, result in enumerate(size_home):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="size_home", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="size_home", sort=index, p_id=p_id,odd=result)
|
|
|
- st_zq_odd = StZqOdds.filter(sole=new_hash)
|
|
|
- if st_zq_odd:
|
|
|
- StZqOdds.update(odds_only=odds_only,utime=utime, odds=result,expire_time=expire_time,condition=size_home_rule[index]).where(StZqOdds.sole == new_hash).execute()
|
|
|
- else:
|
|
|
- StZqOdds.create(odds_only=odds_only,match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,expire_time=expire_time,
|
|
|
- condition=size_home_rule[index], odds=result, p_id=p_id,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="size_home", sole=new_hash)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- if size_guest:
|
|
|
- for index, result in enumerate(size_guest):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="size_guest", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="size_guest", sort=index, p_id=p_id,odd=result)
|
|
|
- st_zq_odd = StZqOdds.filter(sole=new_hash)
|
|
|
- if st_zq_odd:
|
|
|
- StZqOdds.update(odds_only=odds_only,utime=utime, odds=result,expire_time=expire_time,condition=size_guest_rule[index]).where(StZqOdds.sole == new_hash).execute()
|
|
|
- else:
|
|
|
- StZqOdds.create(odds_only=odds_only,match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,
|
|
|
- condition=size_guest_rule[index], odds=result, p_id=p_id,expire_time=expire_time,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="size_guest",sole=new_hash)
|
|
|
-
|
|
|
-
|
|
|
- if half_size_home:
|
|
|
- for index, result in enumerate(half_size_home):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="half_size_home", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="half_size_home", sort=index, p_id=p_id,odd=result)
|
|
|
- st_zq_odd = StZqOdds.filter(sole=new_hash)
|
|
|
- if st_zq_odd:
|
|
|
- StZqOdds.update(odds_only=odds_only,utime=utime, odds=result,expire_time=expire_time,condition=half_size_home_rule[index]).where(StZqOdds.sole == new_hash).execute()
|
|
|
- else:
|
|
|
- StZqOdds.create(odds_only=odds_only,match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,
|
|
|
- condition=half_size_home_rule[index], odds=result, p_id=p_id,expire_time=expire_time,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="half_size_home",sole=new_hash)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- if half_size_guest:
|
|
|
- for index, result in enumerate(half_size_guest):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="half_size_guest", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="half_size_guest", sort=index, p_id=p_id,odd=result)
|
|
|
- st_zq_odd = StZqOdds.filter(sole=new_hash)
|
|
|
- if st_zq_odd:
|
|
|
- StZqOdds.update(odds_only=odds_only,utime=utime, odds=result,expire_time=expire_time,condition=half_size_guest_rule[index]).where(StZqOdds.sole==new_hash).execute()
|
|
|
- else:
|
|
|
- StZqOdds.create(odds_only=odds_only,match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,
|
|
|
- condition=half_size_guest_rule[index], odds=result, p_id=p_id,expire_time=expire_time,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="half_size_guest",sole=new_hash)
|
|
|
-
|
|
|
- #赔率插入记录表
|
|
|
-
|
|
|
- if concede_home:
|
|
|
- for index, result in enumerate(concede_home):
|
|
|
- new_hash1 = hash_func(match_id=key, odds_code="concede_home", sort=index, p_id=p_id)
|
|
|
- odds_only1 = r_func(match_id=key, odds_code="concede_home", sort=index, p_id=p_id,odd=result)
|
|
|
- new_hash2 = hash_func(match_id=key, odds_code="concede_guest", sort=index, p_id=p_id)
|
|
|
- odds_only2 = r_func(match_id=key, odds_code="concede_guest", sort=index, p_id=p_id,odd=result)
|
|
|
- StZqOddsRecord.create(odds_only=odds_only1,match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',
|
|
|
- condition=concede_home_rule[index], odds=result, p_id=p_id,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="concede_home",sole=new_hash1)
|
|
|
- StZqOddsRecord.create(odds_only=odds_only2,match_id=key, ctime=utime, utime=utime, max=concede_guest[index],lg_id=league_id,
|
|
|
- condition=concede_guest_rule[index], odds=concede_guest[index],
|
|
|
- p_id=p_id, p_code=p_code, sort=index,source='hg3535',is_rollball=1,
|
|
|
- odds_code="concede_guest",sole=new_hash2)
|
|
|
-
|
|
|
-
|
|
|
- if half_concede_home:
|
|
|
- for index, result in enumerate(half_concede_home):
|
|
|
- new_hash1 = hash_func(match_id=key, odds_code="half_concede_home", sort=index, p_id=p_id)
|
|
|
- odds_only1 = r_func(match_id=key, odds_code="half_concede_home", sort=index, p_id=p_id,odd=result)
|
|
|
- new_hash2 = hash_func(match_id=key, odds_code="half_concede_guest", sort=index, p_id=p_id)
|
|
|
- odds_only2 = r_func(match_id=key, odds_code="half_concede_guest", sort=index, p_id=p_id,odd=result)
|
|
|
- StZqOddsRecord.create(odds_only=odds_only1,match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,
|
|
|
- condition=half_concede_home_rule[index], odds=result, p_id=p_id,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="half_concede_home",sole=new_hash1)
|
|
|
- StZqOddsRecord.create(odds_only=odds_only2,match_id=key, ctime=utime, utime=utime,lg_id=league_id,
|
|
|
- max=half_concede_guest[index],source='hg3535',is_rollball=1,
|
|
|
- condition=half_concede_guest_rule[index],
|
|
|
- odds=half_concede_guest[index], p_id=p_id, p_code=p_code,
|
|
|
- sort=index, odds_code="half_concede_guest",sole=new_hash2)
|
|
|
-
|
|
|
-
|
|
|
- if size_home:
|
|
|
- for index, result in enumerate(size_home):
|
|
|
- new_hash1 = hash_func(match_id=key, odds_code="size_home", sort=index, p_id=p_id)
|
|
|
- odds_only1 = r_func(match_id=key, odds_code="size_home", sort=index, p_id=p_id,odd=result)
|
|
|
- new_hash2 = hash_func(match_id=key, odds_code="size_guest", sort=index, p_id=p_id)
|
|
|
- odds_only2 = r_func(match_id=key, odds_code="size_guest", sort=index, p_id=p_id,odd=result)
|
|
|
- StZqOddsRecord.create(odds_only=odds_only1,match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,
|
|
|
- condition=size_home_rule[index], odds=result, p_id=p_id,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="size_home",sole=new_hash1)
|
|
|
- StZqOddsRecord.create(odds_only=odds_only2,match_id=key, ctime=utime, utime=utime, max=size_guest[index],source='hg3535',lg_id=league_id,
|
|
|
- condition=size_guest_rule[index], odds=size_guest[index], p_id=p_id,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="size_guest",sole=new_hash2)
|
|
|
-
|
|
|
-
|
|
|
- if half_size_home:
|
|
|
- for index, result in enumerate(half_size_home):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="half_size_home", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="half_size_home", sort=index, p_id=p_id,odd=result)
|
|
|
- StZqOddsRecord.create(odds_only=odds_only,match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,
|
|
|
- condition=half_size_home_rule[index], odds=result, p_id=p_id,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="half_size_home",sole=new_hash)
|
|
|
- if half_size_guest:
|
|
|
- for index, result in enumerate(half_size_guest):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="half_size_guest", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="half_size_guest", sort=index, p_id=p_id,odd=result)
|
|
|
- StZqOddsRecord.create(odds_only=odds_only,match_id=key, ctime=utime, utime=utime, max=half_size_guest[index],lg_id=league_id,
|
|
|
- source='hg3535',is_rollball=1,
|
|
|
- condition=half_size_guest_rule[index], odds=half_size_guest[index],
|
|
|
- p_id=p_id, p_code=p_code, sort=index,
|
|
|
- odds_code="half_size_guest",sole=new_hash)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- #赛事表
|
|
|
- if StZqCompetition.filter(match_id=key):
|
|
|
- StZqCompetition.update(is_rollball=1,utime=utime,status=score_status,tag=number,expire_time=expire_time).where(StZqCompetition.match_id == key).execute()
|
|
|
- else:
|
|
|
- StZqCompetition.create(is_rollball=1,expire_time=expire_time,home_team=team_home,guest_team=team_guest,lg_id=league_id,status=score_status,match_id=key,match_date=r_ctime,match_time='00:00:00',ctime=utime,utime=utime,tag=number,source='hg3535',type=4,ptime=time_game,us_time='2019-01-01 00:00:00')
|
|
|
-
|
|
|
-
|
|
|
- # #更新记录表 具体更新哪些值目前随便写未知
|
|
|
- # if StZqResultRecord.filter(match_id=key):
|
|
|
- # StZqResultRecord.update(update_time=utime, status=score_status,match_score=match_score,match_time=time_game).where(StZqResultRecord.match_id == key).execute()
|
|
|
- # else:
|
|
|
- StZqResultRecord.create(lg_id=league_id,home_team=team_home,guest_team=team_guest,home_score=score_home,guest_score=score_guest,all_goal=number,status=1,first_score='',last_score='',match_score=match_score,match_winer='',update_time=utime,match_time=time_game,match_process=half_way,tag=number,match_id=key,source='hg3535',p_code=p_code)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- # for k, v in value.items():
|
|
|
- # if v:
|
|
|
- # for index, result in enumerate(v):
|
|
|
- # st_zq_odd = StZqResult.filter(match_id=key, sort=index, odds_code=k,p_code="concede_size")
|
|
|
- # if st_zq_odd:
|
|
|
- # if result:
|
|
|
- # StZqResult.update(utime=utime, odds=result).where(StZqResult.match_id == key,StZqResult.sort == index,StZqResult.odds_code == k).execute()
|
|
|
- # else:
|
|
|
- # if result:
|
|
|
- # StZqResult.create(match_id=key, ctime=ctime, utime=utime, max=result,condition=concede_home_rule[index], odds=result, p_id=1,p_code="concede_size", sort=index, odds_code=k)
|
|
|
- # else:
|
|
|
- # for k, v in value.items():
|
|
|
- # if v:
|
|
|
- # for index, result in enumerate(v):
|
|
|
- # if result:
|
|
|
- # StZqResult.create(match_id=key, cp_id=competition_id, host_name=team_home, guest_name=team_guest,home_rate=score_home, guest_rate=score_guest,all_goal=1,status=1,first_score='1',last_score='1',match_score='1',match_winer='1',update_time=utime,match_time='1',match_process='1',tag=1)
|
|
|
-
|
|
|
- bodan = item.get('bodan', "")
|
|
|
- if bodan:
|
|
|
- with database.atomic():
|
|
|
- #key 联赛id
|
|
|
- for key, value in bodan.items():
|
|
|
- # 比赛日期
|
|
|
- data_game = value.pop('data_game').split("/")
|
|
|
- month = str(data_game[1].strip())
|
|
|
- day = str(data_game[0])
|
|
|
- # 比赛时间
|
|
|
- time_game = str(value.pop('time_game'))
|
|
|
- # 比赛时间,时间戳
|
|
|
- ctime = "2019" + "-" + month + "-" + day + "" + time_game + ":00" #创建时间
|
|
|
- # match_date,match_time = new_time(ctime)
|
|
|
- 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 = value.pop('game_id')
|
|
|
- # 联赛id
|
|
|
- league_id = value.pop('league_id')
|
|
|
- # 联赛name
|
|
|
- league_name = value.pop('league_name')
|
|
|
- # 主队
|
|
|
- team_home = value.pop('team_home')
|
|
|
- # 客队
|
|
|
- team_guest = value.pop('team_guest')
|
|
|
- # 主队得分
|
|
|
- score_home = value.pop('score_home')
|
|
|
- # 客队得分
|
|
|
- score_guest = value.pop('score_guest')
|
|
|
- # 全场让球
|
|
|
- # number
|
|
|
- number = value.pop('number')
|
|
|
- corner_ball = value.pop('corner_ball')
|
|
|
- half_way = value.pop('half_way')
|
|
|
- concede_home = value.get('concede_home', "")
|
|
|
- concede_home_rule = value.get('concede_home_rule', "")
|
|
|
- concede_guest = value.get("concede_guest", "")
|
|
|
- concede_guest_rule = value.get("concede_guest_rule", "")
|
|
|
- # 上半场让球
|
|
|
- half_concede_home = value.get("half_concede_home", "")
|
|
|
- half_concede_home_rule = value.get("half_concede_home_rule", "")
|
|
|
- half_concede_guest = value.get("half_concede_guest", "")
|
|
|
- half_concede_guest_rule = value.get("half_concede_guest_rule", "")
|
|
|
- # 全场大小
|
|
|
- size_home = value.get('size_home')
|
|
|
- size_home_rule = value.get('size_home')
|
|
|
- size_guest = value.get('size_guest')
|
|
|
- size_guest_rule = value.get('size_guest_rule', "")
|
|
|
- # 上半场大小
|
|
|
- half_size_home = value.get('half_size_home', "")
|
|
|
- half_size_home_rule = value.get('half_size_home_rule', "")
|
|
|
- half_size_guest = value.get('half_size_guset', "")
|
|
|
- half_size_guest_rule = value.get('half_size_guest_rule', "")
|
|
|
- score_status = value.get('status','')#比赛状态
|
|
|
- if score_status == "True":
|
|
|
- score_status = 1
|
|
|
- else:
|
|
|
- score_status = 0
|
|
|
-
|
|
|
- match_score = "{}:{}".format(score_home,score_guest)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- #如果角球存在
|
|
|
- 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 = "bodan"
|
|
|
- p_id = 6
|
|
|
-
|
|
|
- if StZqResult.filter(match_id=key):
|
|
|
- StZqResult.update(update_time=utime,match_score=match_score,match_time=time_game,match_process=half_way,home_score=score_home,guest_score=score_guest).where(StZqResult.match_id == key).execute()
|
|
|
- else:
|
|
|
- StZqResult.create(match_id=key,match_score=match_score,home_team=team_home, guest_team=team_guest,home_score=score_home,guest_score=score_guest,all_goal=number,status=1,first_score='',last_score='',match_winer='',update_time=utime,match_time=time_game,match_process=half_way,tag=number,lg_id=league_id,u_home_score=0,u_guest_score=0,source='hg3535',p_code=p_code)
|
|
|
-
|
|
|
- #全场让球条件
|
|
|
- if concede_home:
|
|
|
- for index, result in enumerate(concede_home):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="concede_home", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="concede_home", sort=index, p_id=p_id,odd=result)
|
|
|
- st_zq_odd = StZqOdds.filter(sole=new_hash)
|
|
|
- if st_zq_odd:
|
|
|
- StZqOdds.update(odds_only=odds_only,utime=utime, odds=result,expire_time=expire_time,condition=concede_home_rule[index]).where(StZqOdds.sole == new_hash).execute()
|
|
|
- else:
|
|
|
- StZqOdds.create(odds_only=odds_only,match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,
|
|
|
- condition=concede_home_rule[index], odds=result, p_id=p_id,expire_time=expire_time,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="concede_home",sole=new_hash)
|
|
|
-
|
|
|
-
|
|
|
- if concede_guest:
|
|
|
- for index, result in enumerate(concede_guest):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="concede_guest", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="concede_guest", sort=index, p_id=p_id,odd=result)
|
|
|
- st_zq_odd = StZqOdds.filter(sole=new_hash)
|
|
|
- if st_zq_odd:
|
|
|
- StZqOdds.update(odds_only=odds_only,utime=utime, odds=result,expire_time=expire_time,condition=concede_guest_rule[index]).where(StZqOdds.sole == new_hash).execute()
|
|
|
- else:
|
|
|
- StZqOdds.create(odds_only=odds_only,match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,
|
|
|
- condition=concede_guest_rule[index], odds=result, p_id=p_id,expire_time=expire_time,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="concede_guest",sole=new_hash)
|
|
|
-
|
|
|
- if half_concede_home:
|
|
|
- for index, result in enumerate(half_concede_home):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="half_concede_home", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="half_concede_home", sort=index, p_id=p_id,odd=result)
|
|
|
- st_zq_odd = StZqOdds.filter(sole=new_hash)
|
|
|
- if st_zq_odd:
|
|
|
- StZqOdds.update(odds_only=odds_only,utime=utime, odds=result,expire_time=expire_time,condition=half_concede_home_rule[index]).where(StZqOdds.sole == new_hash).execute()
|
|
|
- else:
|
|
|
- StZqOdds.create(odds_only=odds_only,match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,
|
|
|
- condition=half_concede_home_rule[index], odds=result, p_id=p_id,expire_time=expire_time,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="half_concede_home", sole=new_hash)
|
|
|
-
|
|
|
-
|
|
|
- if half_concede_guest:
|
|
|
- for index, result in enumerate(half_concede_guest):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="half_concede_guest", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="half_concede_guest", sort=index, p_id=p_id,odd=result)
|
|
|
- st_zq_odd = StZqOdds.filter(sole=new_hash)
|
|
|
- if st_zq_odd:
|
|
|
- StZqOdds.update(odds_only=odds_only,utime=utime, odds=result,expire_time=expire_time,condition=half_concede_guest_rule[index]).where(StZqOdds.sole == new_hash).execute()
|
|
|
- else:
|
|
|
- StZqOdds.create(odds_only=odds_only,match_id=key, ctime=utime, utime=utime,source='hg3535',lg_id=league_id,expire_time=expire_time,
|
|
|
- max=half_concede_guest[index],is_rollball=1,
|
|
|
- condition=half_concede_guest_rule[index],
|
|
|
- odds=half_concede_guest[index], p_id=p_id, p_code=p_code,
|
|
|
- sort=index, odds_code="half_concede_guest", sole=new_hash)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- if size_home:
|
|
|
- for index, result in enumerate(size_home):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="size_home", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="size_home", sort=index, p_id=p_id,odd=result)
|
|
|
- st_zq_odd = StZqOdds.filter(sole=new_hash)
|
|
|
- if st_zq_odd:
|
|
|
- StZqOdds.update(odds_only=odds_only,utime=utime, odds=result,expire_time=expire_time,condition=size_home_rule[index]).where(StZqOdds.sole == new_hash).execute()
|
|
|
- else:
|
|
|
- StZqOdds.create(odds_only=odds_only,match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,
|
|
|
- condition=size_home_rule[index], odds=result, p_id=p_id,expire_time=expire_time,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="size_home", sole=new_hash)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- if size_guest:
|
|
|
- for index, result in enumerate(size_guest):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="size_guest", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="size_guest", sort=index, p_id=p_id,odd=result)
|
|
|
- st_zq_odd = StZqOdds.filter(sole=new_hash)
|
|
|
- if st_zq_odd:
|
|
|
- StZqOdds.update(odds_only=odds_only,utime=utime, odds=result,expire_time=expire_time,condition=size_guest_rule[index]).where(StZqOdds.sole == new_hash).execute()
|
|
|
- else:
|
|
|
- StZqOdds.create(odds_only=odds_only,match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,
|
|
|
- condition=size_guest_rule[index], odds=result, p_id=p_id,expire_time=expire_time,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="size_guest",sole=new_hash)
|
|
|
-
|
|
|
-
|
|
|
- if half_size_home:
|
|
|
- for index, result in enumerate(half_size_home):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="half_size_home", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="half_size_home", sort=index, p_id=p_id,odd=result)
|
|
|
- st_zq_odd = StZqOdds.filter(sole=new_hash)
|
|
|
- if st_zq_odd:
|
|
|
- StZqOdds.update(odds_only=odds_only,utime=utime, odds=result,expire_time=expire_time,condition=half_size_home_rule[index]).where(StZqOdds.sole == new_hash).execute()
|
|
|
- else:
|
|
|
- StZqOdds.create(odds_only=odds_only,match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,
|
|
|
- condition=half_size_home_rule[index], odds=result, p_id=p_id,expire_time=expire_time,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="half_size_home",sole=new_hash)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- if half_size_guest:
|
|
|
- for index, result in enumerate(half_size_guest):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="half_size_guest", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="half_size_guest", sort=index, p_id=p_id,odd=result)
|
|
|
- st_zq_odd = StZqOdds.filter(sole=new_hash)
|
|
|
- if st_zq_odd:
|
|
|
- StZqOdds.update(odds_only=odds_only,utime=utime, odds=result,expire_time=expire_time,condition=half_size_guest_rule[index]).where(StZqOdds.sole==new_hash).execute()
|
|
|
- else:
|
|
|
- StZqOdds.create(odds_only=odds_only,match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,
|
|
|
- condition=half_size_guest_rule[index], odds=result, p_id=p_id,expire_time=expire_time,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="half_size_guest",sole=new_hash)
|
|
|
-
|
|
|
- #赔率插入记录表
|
|
|
-
|
|
|
- if concede_home:
|
|
|
- for index, result in enumerate(concede_home):
|
|
|
- new_hash1 = hash_func(match_id=key, odds_code="concede_home", sort=index, p_id=p_id)
|
|
|
- odds_only1 = r_func(match_id=key, odds_code="concede_home", sort=index, p_id=p_id,odd=result)
|
|
|
- new_hash2 = hash_func(match_id=key, odds_code="concede_guest", sort=index, p_id=p_id)
|
|
|
- odds_only2 = r_func(match_id=key, odds_code="concede_guest", sort=index, p_id=p_id,odd=result)
|
|
|
- StZqOddsRecord.create(odds_only=odds_only1,match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,
|
|
|
- condition=concede_home_rule[index], odds=result, p_id=p_id,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="concede_home",sole=new_hash1)
|
|
|
- StZqOddsRecord.create(odds_only=odds_only2,match_id=key, ctime=utime, utime=utime, max=concede_guest[index],lg_id=league_id,
|
|
|
- condition=concede_guest_rule[index], odds=concede_guest[index],
|
|
|
- p_id=p_id, p_code=p_code, sort=index,source='hg3535',is_rollball=1,
|
|
|
- odds_code="concede_guest",sole=new_hash2)
|
|
|
-
|
|
|
-
|
|
|
- if half_concede_home:
|
|
|
- for index, result in enumerate(half_concede_home):
|
|
|
- new_hash1 = hash_func(match_id=key, odds_code="half_concede_home", sort=index, p_id=p_id)
|
|
|
- odds_only1 = r_func(match_id=key, odds_code="half_concede_home", sort=index, p_id=p_id,odd=result)
|
|
|
- new_hash2 = hash_func(match_id=key, odds_code="half_concede_guest", sort=index, p_id=p_id)
|
|
|
- odds_only2 = r_func(match_id=key, odds_code="half_concede_guest", sort=index, p_id=p_id,odd=result)
|
|
|
- StZqOddsRecord.create(odds_only=odds_only1,match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',
|
|
|
- condition=half_concede_home_rule[index], odds=result, p_id=p_id,lg_id=league_id,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="half_concede_home",sole=new_hash1)
|
|
|
- StZqOddsRecord.create(odds_only=odds_only2,match_id=key, ctime=utime, utime=utime,source='hg3535',lg_id=league_id,
|
|
|
- max=half_concede_guest[index],is_rollball=1,
|
|
|
- condition=half_concede_guest_rule[index],
|
|
|
- odds=half_concede_guest[index], p_id=p_id, p_code=p_code,
|
|
|
- sort=index, odds_code="half_concede_guest",sole=new_hash2)
|
|
|
-
|
|
|
-
|
|
|
- if size_home:
|
|
|
- for index, result in enumerate(size_home):
|
|
|
- new_hash1 = hash_func(match_id=key, odds_code="size_home", sort=index, p_id=p_id)
|
|
|
- odds_only1 = r_func(match_id=key, odds_code="size_home", sort=index, p_id=p_id,odd=result)
|
|
|
- new_hash2 = hash_func(match_id=key, odds_code="size_guest", sort=index, p_id=p_id)
|
|
|
- odds_only2 = r_func(match_id=key, odds_code="size_guest", sort=index, p_id=p_id,odd=result)
|
|
|
- StZqOddsRecord.create(odds_only=odds_only1,match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,
|
|
|
- condition=size_home_rule[index], odds=result, p_id=p_id,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="size_home",sole=new_hash1)
|
|
|
- StZqOddsRecord.create(odds_only=odds_only2,match_id=key, ctime=utime, utime=utime, max=size_guest[index],source='hg3535',lg_id=league_id,
|
|
|
- condition=size_guest_rule[index], odds=size_guest[index], p_id=p_id,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="size_guest",sole=new_hash2)
|
|
|
-
|
|
|
-
|
|
|
- if half_size_home:
|
|
|
- for index, result in enumerate(half_size_home):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="half_size_home", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="half_size_home", sort=index, p_id=p_id,odd=result)
|
|
|
- StZqOddsRecord.create(odds_only=odds_only,match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,
|
|
|
- condition=half_size_home_rule[index], odds=result, p_id=p_id,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="half_size_home",sole=new_hash)
|
|
|
- if half_size_guest:
|
|
|
- for index, result in enumerate(half_size_guest):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="half_size_guest", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="half_size_guest", sort=index, p_id=p_id,odd=result)
|
|
|
- StZqOddsRecord.create(odds_only=odds_only,match_id=key, ctime=utime, utime=utime, max=half_size_guest[index],source='hg3535',
|
|
|
- condition=half_size_guest_rule[index], odds=half_size_guest[index],lg_id=league_id,
|
|
|
- p_id=p_id, p_code=p_code, sort=index,is_rollball=1,
|
|
|
- odds_code="half_size_guest",sole=new_hash)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- #赛事表
|
|
|
- if StZqCompetition.filter(match_id=key):
|
|
|
- StZqCompetition.update(is_rollball=1,expire_time=expire_time,utime=utime,status=score_status,tag=number).where(StZqCompetition.match_id == key).execute()
|
|
|
- else:
|
|
|
- StZqCompetition.create(is_rollball=1,home_team=team_home,guest_team=team_guest,lg_id=league_id,status=score_status,match_id=key,match_date=r_ctime,match_time='00:00:00',ctime=utime,utime=utime,tag=number,source='hg3535',type=4,ptime=time_game,us_time='2019-01-01 00:00:00')
|
|
|
-
|
|
|
-
|
|
|
- #更新记录表 具体更新哪些值目前随便写未知
|
|
|
- # if StZqResultRecord.filter(match_id=key):
|
|
|
- # StZqResultRecord.update(update_time=utime, status=score_status,match_score=match_score,match_time=time_game).where(StZqResultRecord.match_id == key).execute()
|
|
|
- # else:
|
|
|
- StZqResultRecord.create(lg_id=league_id,home_team=team_home,guest_team=team_guest,home_score=score_home,guest_score=score_guest,all_goal=number,status=1,first_score='',last_score='',match_score=match_score,match_winer='',update_time=utime,match_time=time_game,match_process=half_way,tag=number,match_id=key,source='hg3535',p_code=p_code)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- # for k, v in value.items():
|
|
|
- # if v:
|
|
|
- # for index, result in enumerate(v):
|
|
|
- # st_zq_odd = StZqResult.filter(match_id=key, sort=index, odds_code=k,p_code="concede_size")
|
|
|
- # if st_zq_odd:
|
|
|
- # if result:
|
|
|
- # StZqResult.update(utime=utime, odds=result).where(StZqResult.match_id == key,StZqResult.sort == index,StZqResult.odds_code == k).execute()
|
|
|
- # else:
|
|
|
- # if result:
|
|
|
- # StZqResult.create(match_id=key, ctime=ctime, utime=utime, max=result,condition=concede_home_rule[index], odds=result, p_id=1,p_code="concede_size", sort=index, odds_code=k)
|
|
|
- # else:
|
|
|
- # for k, v in value.items():
|
|
|
- # if v:
|
|
|
- # for index, result in enumerate(v):
|
|
|
- # if result:
|
|
|
- # StZqResult.create(match_id=key, cp_id=competition_id, host_name=team_home, guest_name=team_guest,home_rate=score_home, guest_rate=score_guest,all_goal=1,status=1,first_score='1',last_score='1',match_score='1',match_winer='1',update_time=utime,match_time='1',match_process='1',tag=1)
|
|
|
-
|
|
|
- first_last_ball = item.get('first_last_ball', "")
|
|
|
- if first_last_ball:
|
|
|
- with database.atomic():
|
|
|
- #key 联赛id
|
|
|
- for key, value in first_last_ball.items():
|
|
|
- # 比赛日期
|
|
|
- data_game = value.pop('data_game').split("/")
|
|
|
- month = str(data_game[1].strip())
|
|
|
- day = str(data_game[0])
|
|
|
- # 比赛时间
|
|
|
- time_game = str(value.pop('time_game'))
|
|
|
- # 比赛时间,时间戳
|
|
|
- ctime = "2019" + "-" + month + "-" + day + "" + time_game + ":00" #创建时间
|
|
|
- # match_date,match_time = new_time(ctime)
|
|
|
- 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 = value.pop('game_id')
|
|
|
- # 联赛id
|
|
|
- league_id = value.pop('league_id')
|
|
|
- # 联赛name
|
|
|
- league_name = value.pop('league_name')
|
|
|
- # 主队
|
|
|
- team_home = value.pop('team_home')
|
|
|
- # 客队
|
|
|
- team_guest = value.pop('team_guest')
|
|
|
- # 主队得分
|
|
|
- score_home = value.pop('score_home')
|
|
|
- # 客队得分
|
|
|
- score_guest = value.pop('score_guest')
|
|
|
- # 全场让球
|
|
|
- # number
|
|
|
- number = value.pop('number')
|
|
|
- corner_ball = value.pop('corner_ball')
|
|
|
- half_way = value.pop('half_way')
|
|
|
- concede_home = value.get('concede_home', "")
|
|
|
- concede_home_rule = value.get('concede_home_rule', "")
|
|
|
- concede_guest = value.get("concede_guest", "")
|
|
|
- concede_guest_rule = value.get("concede_guest_rule", "")
|
|
|
- # 上半场让球
|
|
|
- half_concede_home = value.get("half_concede_home", "")
|
|
|
- half_concede_home_rule = value.get("half_concede_home_rule", "")
|
|
|
- half_concede_guest = value.get("half_concede_guest", "")
|
|
|
- half_concede_guest_rule = value.get("half_concede_guest_rule", "")
|
|
|
- # 全场大小
|
|
|
- size_home = value.get('size_home')
|
|
|
- size_home_rule = value.get('size_home')
|
|
|
- size_guest = value.get('size_guest')
|
|
|
- size_guest_rule = value.get('size_guest_rule', "")
|
|
|
- # 上半场大小
|
|
|
- half_size_home = value.get('half_size_home', "")
|
|
|
- half_size_home_rule = value.get('half_size_home_rule', "")
|
|
|
- half_size_guest = value.get('half_size_guset', "")
|
|
|
- half_size_guest_rule = value.get('half_size_guest_rule', "")
|
|
|
- score_status = value.get('status','')#比赛状态
|
|
|
- if score_status:
|
|
|
- score_status = 1
|
|
|
- else:
|
|
|
- score_status = 0
|
|
|
-
|
|
|
- match_score = "{}:{}".format(score_home,score_guest)
|
|
|
-
|
|
|
-
|
|
|
- #如果角球存在
|
|
|
- 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 = "first_last_ball"
|
|
|
- p_id = 7
|
|
|
-
|
|
|
- if StZqResult.filter(match_id=key):
|
|
|
- StZqResult.update(update_time=utime,match_score=match_score,match_time=time_game,match_process=half_way,home_score=score_home,guest_score=score_guest).where(StZqResult.match_id == key).execute()
|
|
|
- else:
|
|
|
- StZqResult.create(match_id=key,match_score=match_score,home_team=team_home, guest_team=team_guest,home_score=score_home,guest_score=score_guest,all_goal=number,status=1,first_score='',last_score='',match_winer='',update_time=utime,match_time=time_game,match_process=half_way,tag=number,lg_id=league_id,u_home_score=0,u_guest_score=0,source='hg3535',p_code=p_code)
|
|
|
-
|
|
|
- #全场让球条件
|
|
|
- if concede_home:
|
|
|
- for index, result in enumerate(concede_home):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="concede_home", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="concede_home", sort=index, p_id=p_id,odd=result)
|
|
|
- st_zq_odd = StZqOdds.filter(sole=new_hash)
|
|
|
- if st_zq_odd:
|
|
|
- StZqOdds.update(odds_only=odds_only,utime=utime, odds=result,expire_time=expire_time,condition=concede_home_rule[index]).where(StZqOdds.sole == new_hash).execute()
|
|
|
- else:
|
|
|
- StZqOdds.create(odds_only=odds_only,match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,
|
|
|
- condition=concede_home_rule[index], odds=result, p_id=p_id,expire_time=expire_time,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="concede_home",sole=new_hash)
|
|
|
-
|
|
|
-
|
|
|
- if concede_guest:
|
|
|
- for index, result in enumerate(concede_guest):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="concede_guest", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="concede_guest", sort=index, p_id=p_id,odd=result)
|
|
|
- st_zq_odd = StZqOdds.filter(sole=new_hash)
|
|
|
- if st_zq_odd:
|
|
|
- StZqOdds.update(odds_only=odds_only,utime=utime, odds=result,expire_time=expire_time,condition=concede_guest_rule[index]).where(StZqOdds.sole == new_hash).execute()
|
|
|
- else:
|
|
|
- StZqOdds.create(odds_only=odds_only,match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,
|
|
|
- condition=concede_guest_rule[index], odds=result, p_id=p_id,expire_time=expire_time,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="concede_guest",sole=new_hash)
|
|
|
-
|
|
|
- if half_concede_home:
|
|
|
- for index, result in enumerate(half_concede_home):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="half_concede_home", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="half_concede_home", sort=index, p_id=p_id,odd=result)
|
|
|
- st_zq_odd = StZqOdds.filter(sole=new_hash)
|
|
|
- if st_zq_odd:
|
|
|
- StZqOdds.update(odds_only=odds_only,utime=utime, odds=result,expire_time=expire_time,condition=half_concede_home_rule[index]).where(StZqOdds.sole == new_hash).execute()
|
|
|
- else:
|
|
|
- StZqOdds.create(odds_only=odds_only,match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,
|
|
|
- condition=half_concede_home_rule[index], odds=result, p_id=p_id,expire_time=expire_time,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="half_concede_home", sole=new_hash)
|
|
|
-
|
|
|
-
|
|
|
- if half_concede_guest:
|
|
|
- for index, result in enumerate(half_concede_guest):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="half_concede_guest", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="half_concede_guest", sort=index, p_id=p_id,odd=result)
|
|
|
- st_zq_odd = StZqOdds.filter(sole=new_hash)
|
|
|
- if st_zq_odd:
|
|
|
- StZqOdds.update(odds_only=odds_only,utime=utime, odds=result,expire_time=expire_time,condition=half_concede_guest_rule[index]).where(StZqOdds.sole == new_hash).execute()
|
|
|
- else:
|
|
|
- StZqOdds.create(odds_only=odds_only,match_id=key, ctime=utime, utime=utime,source='hg3535',lg_id=league_id,
|
|
|
- max=half_concede_guest[index],expire_time=expire_time,is_rollball=1,
|
|
|
- condition=half_concede_guest_rule[index],
|
|
|
- odds=half_concede_guest[index], p_id=p_id, p_code=p_code,
|
|
|
- sort=index, odds_code="half_concede_guest", sole=new_hash)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- if size_home:
|
|
|
- for index, result in enumerate(size_home):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="size_home", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="size_home", sort=index, p_id=p_id,odd=result)
|
|
|
- st_zq_odd = StZqOdds.filter(sole=new_hash)
|
|
|
- if st_zq_odd:
|
|
|
- StZqOdds.update(odds_only=odds_only,utime=utime, odds=result,expire_time=expire_time,condition=size_home_rule[index]).where(StZqOdds.sole == new_hash).execute()
|
|
|
- else:
|
|
|
- StZqOdds.create(odds_only=odds_only,match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,
|
|
|
- condition=size_home_rule[index], odds=result, p_id=p_id,expire_time=expire_time,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="size_home", sole=new_hash)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- if size_guest:
|
|
|
- for index, result in enumerate(size_guest):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="size_guest", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="size_guest", sort=index, p_id=p_id,odd=result)
|
|
|
- st_zq_odd = StZqOdds.filter(sole=new_hash)
|
|
|
- if st_zq_odd:
|
|
|
- StZqOdds.update(odds_only=odds_only,utime=utime, odds=result,expire_time=expire_time,condition=size_guest_rule[index]).where(StZqOdds.sole == new_hash).execute()
|
|
|
- else:
|
|
|
- StZqOdds.create(odds_only=odds_only,match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,
|
|
|
- condition=size_guest_rule[index], odds=result, p_id=p_id,expire_time=expire_time,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="size_guest",sole=new_hash)
|
|
|
-
|
|
|
-
|
|
|
- if half_size_home:
|
|
|
- for index, result in enumerate(half_size_home):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="half_size_home", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="half_size_home", sort=index, p_id=p_id,odd=result)
|
|
|
- st_zq_odd = StZqOdds.filter(sole=new_hash)
|
|
|
- if st_zq_odd:
|
|
|
- StZqOdds.update(odds_only=odds_only,utime=utime, odds=result,expire_time=expire_time,condition=half_size_home_rule[index]).where(StZqOdds.sole == new_hash).execute()
|
|
|
- else:
|
|
|
- StZqOdds.create(odds_only=odds_only,match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,
|
|
|
- condition=half_size_home_rule[index], odds=result, p_id=p_id,expire_time=expire_time,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="half_size_home",sole=new_hash)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- if half_size_guest:
|
|
|
- for index, result in enumerate(half_size_guest):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="half_size_guest", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="half_size_guest", sort=index, p_id=p_id,odd=result)
|
|
|
- st_zq_odd = StZqOdds.filter(sole=new_hash)
|
|
|
- if st_zq_odd:
|
|
|
- StZqOdds.update(odds_only=odds_only,utime=utime, odds=result,expire_time=expire_time,condition=half_size_guest_rule[index]).where(StZqOdds.sole==new_hash).execute()
|
|
|
- else:
|
|
|
- StZqOdds.create(odds_only=odds_only,match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,
|
|
|
- condition=half_size_guest_rule[index], odds=result, p_id=p_id,expire_time=expire_time,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="half_size_guest",sole=new_hash)
|
|
|
-
|
|
|
- #赔率插入记录表
|
|
|
-
|
|
|
- if concede_home:
|
|
|
- for index, result in enumerate(concede_home):
|
|
|
- new_hash1 = hash_func(match_id=key, odds_code="concede_home", sort=index, p_id=p_id)
|
|
|
- odds_only1 = r_func(match_id=key, odds_code="concede_home", sort=index, p_id=p_id,odd=result)
|
|
|
- new_hash2 = hash_func(match_id=key, odds_code="concede_guest", sort=index, p_id=p_id)
|
|
|
- odds_only2 = r_func(match_id=key, odds_code="concede_guest", sort=index, p_id=p_id,odd=result)
|
|
|
- StZqOddsRecord.create(odds_only=odds_only1,match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,
|
|
|
- condition=concede_home_rule[index], odds=result, p_id=p_id,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="concede_home",sole=new_hash1)
|
|
|
- StZqOddsRecord.create(odds_only=odds_only2,match_id=key, ctime=utime, utime=utime, max=concede_guest[index],lg_id=league_id,
|
|
|
- condition=concede_guest_rule[index], odds=concede_guest[index],is_rollball=1,
|
|
|
- p_id=p_id, p_code=p_code, sort=index,source='hg3535',
|
|
|
- odds_code="concede_guest",sole=new_hash2)
|
|
|
-
|
|
|
-
|
|
|
- if half_concede_home:
|
|
|
- for index, result in enumerate(half_concede_home):
|
|
|
- new_hash1 = hash_func(match_id=key, odds_code="half_concede_home", sort=index, p_id=p_id)
|
|
|
- odds_only1 = r_func(match_id=key, odds_code="half_concede_home", sort=index, p_id=p_id,odd=result)
|
|
|
- new_hash2 = hash_func(match_id=key, odds_code="half_concede_guest", sort=index, p_id=p_id)
|
|
|
- odds_only2 = r_func(match_id=key, odds_code="half_concede_guest", sort=index, p_id=p_id,odd=result)
|
|
|
- StZqOddsRecord.create(odds_only=odds_only1,match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,
|
|
|
- condition=half_concede_home_rule[index], odds=result, p_id=p_id,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="half_concede_home",sole=new_hash1)
|
|
|
- StZqOddsRecord.create(odds_only=odds_only2,match_id=key, ctime=utime, utime=utime,source='hg3535',lg_id=league_id,
|
|
|
- max=half_concede_guest[index],is_rollball=1,
|
|
|
- condition=half_concede_guest_rule[index],
|
|
|
- odds=half_concede_guest[index], p_id=p_id, p_code=p_code,
|
|
|
- sort=index, odds_code="half_concede_guest",sole=new_hash2)
|
|
|
-
|
|
|
-
|
|
|
- if size_home:
|
|
|
- for index, result in enumerate(size_home):
|
|
|
- new_hash1 = hash_func(match_id=key, odds_code="size_home", sort=index, p_id=p_id)
|
|
|
- odds_only1 = r_func(match_id=key, odds_code="size_home", sort=index, p_id=p_id,odd=result)
|
|
|
- new_hash2 = hash_func(match_id=key, odds_code="size_guest", sort=index, p_id=p_id)
|
|
|
- odds_only2 = r_func(match_id=key, odds_code="size_guest", sort=index, p_id=p_id,odd=result)
|
|
|
- StZqOddsRecord.create(odds_only=odds_only1,match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,
|
|
|
- condition=size_home_rule[index], odds=result, p_id=p_id,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="size_home",sole=new_hash1)
|
|
|
- StZqOddsRecord.create(odds_only=odds_only2,match_id=key, ctime=utime, utime=utime, max=size_guest[index],source='hg3535',lg_id=league_id,
|
|
|
- condition=size_guest_rule[index], odds=size_guest[index], p_id=p_id,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="size_guest",sole=new_hash2)
|
|
|
-
|
|
|
-
|
|
|
- if half_size_home:
|
|
|
- for index, result in enumerate(half_size_home):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="half_size_home", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="half_size_home", sort=index, p_id=p_id,odd=result)
|
|
|
- StZqOddsRecord.create(odds_only=odds_only,match_id=key, ctime=utime, utime=utime, max=result,source='hg3535',lg_id=league_id,
|
|
|
- condition=half_size_home_rule[index], odds=result, p_id=p_id,is_rollball=1,
|
|
|
- p_code=p_code, sort=index, odds_code="half_size_home",sole=new_hash)
|
|
|
- if half_size_guest:
|
|
|
- for index, result in enumerate(half_size_guest):
|
|
|
- new_hash = hash_func(match_id=key, odds_code="half_size_guest", sort=index, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=key, odds_code="half_size_guest", sort=index, p_id=p_id,odd=result)
|
|
|
- StZqOddsRecord.create(odds_only=odds_only,match_id=key, ctime=utime, utime=utime, max=half_size_guest[index],source='hg3535',lg_id=league_id,
|
|
|
- condition=half_size_guest_rule[index], odds=half_size_guest[index],
|
|
|
- p_id=p_id, p_code=p_code, sort=index,is_rollball=1,
|
|
|
- odds_code="half_size_guest",sole=new_hash)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- #赛事表
|
|
|
- if StZqCompetition.filter(match_id=key):
|
|
|
- StZqCompetition.update(is_rollball=1,expire_time=expire_time,utime=utime,status=score_status,tag=number).where(StZqCompetition.match_id == key).execute()
|
|
|
- else:
|
|
|
- StZqCompetition.create(is_rollball=1,expire_time=expire_time,home_team=team_home,guest_team=team_guest,lg_id=league_id,status=score_status,match_id=key,match_date=r_ctime,match_time='00:00:00',ctime=utime,utime=utime,tag=number,source='hg3535',type=4,ptime=time_game,us_time='2019-01-01 00:00:00')
|
|
|
-
|
|
|
- #更新记录表 具体更新哪些值目前随便写未知
|
|
|
- # if StZqResultRecord.filter(match_id=key):
|
|
|
- # StZqResultRecord.update(update_time=utime, status=score_status,match_score=match_score,match_time=time_game).where(StZqResultRecord.match_id == key).execute()
|
|
|
- # else:
|
|
|
- StZqResultRecord.create(lg_id=league_id,home_team=team_home,guest_team=team_guest,home_score=score_home,guest_score=score_guest,all_goal=number,status=1,first_score='',last_score='',match_score=match_score,match_winer='',update_time=utime,match_time=time_game,match_process=half_way,tag=number,match_id=key,source='hg3535',p_code=p_code)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- # for k, v in value.items():
|
|
|
- # if v:
|
|
|
- # for index, result in enumerate(v):
|
|
|
- # st_zq_odd = StZqResult.filter(match_id=key, sort=index, odds_code=k,p_code="concede_size")
|
|
|
- # if st_zq_odd:
|
|
|
- # if result:
|
|
|
- # StZqResult.update(utime=utime, odds=result).where(StZqResult.match_id == key,StZqResult.sort == index,StZqResult.odds_code == k).execute()
|
|
|
- # else:
|
|
|
- # if result:
|
|
|
- # StZqResult.create(match_id=key, ctime=ctime, utime=utime, max=result,condition=concede_home_rule[index], odds=result, p_id=1,p_code="concede_size", sort=index, odds_code=k)
|
|
|
- # else:
|
|
|
- # for k, v in value.items():
|
|
|
- # if v:
|
|
|
- # for index, result in enumerate(v):
|
|
|
- # if result:
|
|
|
- # StZqResult.create(match_id=key, cp_id=competition_id, host_name=team_home, guest_name=team_guest,home_rate=score_home, guest_rate=score_guest,all_goal=1,status=1,first_score='1',last_score='1',match_score='1',match_winer='1',update_time=utime,match_time='1',match_process='1',tag=1)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- # items = dict(item)
|
|
|
- # print(type(items))
|
|
|
- # print(items)
|
|
|
- # StZqOdds.create()
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- # return item
|
|
|
-
|
|
|
- #爬虫关闭关闭数据库连接
|
|
|
- def close_spider(self, spider):
|
|
|
- self.conn.close()
|
|
|
- self.cursor.close()
|
|
|
- database.close()
|
|
|
-
|
|
|
-
|
|
|
-# class MysqlTwistedPipline(object):
|
|
|
-# cursor = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
|
|
|
-#
|
|
|
-# def __init__(self, dbpool):
|
|
|
-# self.dbpool = dbpool
|
|
|
-#
|
|
|
-#
|
|
|
-# @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'],
|
|
|
-# # charset='utf8',
|
|
|
-# # cursorclass = cls.cursor,
|
|
|
-# # use_unicode = True,
|
|
|
-# )
|
|
|
-# dbpool = adbapi.ConnectionPool("psycopg2", **dbparms)
|
|
|
-#
|
|
|
-# return cls(dbpool)
|
|
|
-#
|
|
|
-# 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):
|
|
|
-# #执行具体的插入
|
|
|
-# #根据不同的item 构建不同的sql语句并插入到mysql中
|
|
|
-# insert_sql, params = item.get_insert_sql()
|
|
|
-# cursor.execute(insert_sql, params)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-# 球队进球 大小----------------------------------------------------------------------------------------------------------
|
|
|
-class Temaballpipeline(object):
|
|
|
- # cursor = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
|
|
|
- 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'],
|
|
|
- # charset='utf8',
|
|
|
- # cursorclass = cls.cursor,
|
|
|
- # use_unicode = True,
|
|
|
- )
|
|
|
- dbpool = adbapi.ConnectionPool("psycopg2", **dbparms)
|
|
|
- conn = psycopg2.connect(host='192.168.2.200', port=10432, user='kaiyou', password='123456', database='kaiyou')
|
|
|
- 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):
|
|
|
- # 比赛日期
|
|
|
- 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())
|
|
|
- # 比赛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']
|
|
|
- p_code = "temaball"
|
|
|
- p_id = 11
|
|
|
- full_dicts = item['full_data']
|
|
|
- half_dicts = item['half_data']
|
|
|
- full_dict_rules = item['full_data_rule']
|
|
|
- half_dict_rules = item['half_data_rule']
|
|
|
- if full_dicts:
|
|
|
- for key, value in full_dicts.items():
|
|
|
- if value:
|
|
|
- # 构建唯一索引
|
|
|
- new_hash = hash_func(match_id=competition_id, odds_code=key, sort=0, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=competition_id, odds_code=key, sort=0, p_id=p_id,odd=value)
|
|
|
- # 更新st_zq_odds表
|
|
|
- sql1 = "insert into st_zq_odds(lg_id, odds_code, match_id, ctime, utime, max, 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,%s) on conflict(sole) do update set utime = %s,odds = %s,odds_only=%s;"
|
|
|
- cursor.execute(sql1, (
|
|
|
- int(league_id), key, int(competition_id), utime, utime, value, value, p_id, p_code, 0, "hg3535",
|
|
|
- new_hash, full_dict_rules[key], odds_only,1,utime, value,odds_only))
|
|
|
- # 更新st_zq_odds_record
|
|
|
- sql2 = "insert into st_zq_odds_record(lg_id, odds_code, match_id, ctime, utime, max, 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,%s);"
|
|
|
- cursor.execute(sql2, (
|
|
|
- int(league_id), key, int(competition_id), utime, utime, value, value, p_id, p_code, 0, "hg3535",
|
|
|
- full_dict_rules[key],odds_only,1))
|
|
|
-
|
|
|
- if half_dicts:
|
|
|
- for key, value in half_dicts.items():
|
|
|
- if value:
|
|
|
- # 构建唯一索引
|
|
|
- new_hash = hash_func(match_id=competition_id, odds_code=key, sort=0, p_id=p_id)
|
|
|
- odds_only = r_func(match_id=competition_id, odds_code=key, sort=0, p_id=p_id,odd=value)
|
|
|
- # 更新st_zq_odds表
|
|
|
- sql1 = "insert into st_zq_odds(lg_id, odds_code, match_id, ctime, utime, max, 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,%s) on conflict(sole) do update set utime = %s,odds = %s,odds_only=%s;"
|
|
|
- cursor.execute(sql1, (
|
|
|
- int(league_id), key, int(competition_id), utime, utime, value, value, p_id, p_code, 0, "hg3535",
|
|
|
- new_hash, half_dict_rules[key],odds_only,1,utime, value,odds_only))
|
|
|
- # 更新st_zq_odds_record
|
|
|
- sql2 = "insert into st_zq_odds_record(lg_id, odds_code, match_id, ctime, utime, max, 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,%s);"
|
|
|
- cursor.execute(sql2, (
|
|
|
- int(league_id), key, int(competition_id), utime, utime, value, value, p_id, p_code, 0, "hg3535",
|
|
|
- half_dict_rules[key],odds_only,1))
|
|
|
-
|
|
|
-
|
|
|
- def close_spider(self, spider):
|
|
|
- self.conn.close()
|
|
|
- self.dbpool.close()
|
|
|
- database.close()
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-# 篮球 让球大小----------------------------------------------------------------------------------------------------------
|
|
|
-class Lanqiupipeline(object):
|
|
|
- # cursor = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
|
|
|
- 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'],
|
|
|
- # charset='utf8',
|
|
|
- # cursorclass = cls.cursor,
|
|
|
- # use_unicode = True,
|
|
|
- )
|
|
|
- dbpool = adbapi.ConnectionPool("psycopg2", **dbparms)
|
|
|
- conn = psycopg2.connect(host='192.168.2.200', port=10432, user='kaiyou', password='123456', database='kaiyou')
|
|
|
- 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
|
|
|
- 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, "lq_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, "lq_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, "lq_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, "lq_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, "lq_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, "lq_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['lq_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, "lq_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, "lq_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['lq_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, "lq_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, "lq_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, "lq_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, "lq_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, "lq_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, "lq_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.conn.close()
|
|
|
- self.dbpool.close()
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-# 网球 让球&大小盘--------------------------------------------------------------------------------------------------------
|
|
|
-class Wangqiupipeline(object):
|
|
|
- # cursor = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
|
|
|
- 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'],
|
|
|
- # charset='utf8',
|
|
|
- # cursorclass = cls.cursor,
|
|
|
- # use_unicode = True,
|
|
|
- )
|
|
|
- dbpool = adbapi.ConnectionPool("psycopg2", **dbparms)
|
|
|
- # database = PostgresqlDatabase('kaiyou',**{'host': '192.168.2.200', 'port': 10432, 'user': 'kaiyou', 'password': '123456'})
|
|
|
-
|
|
|
- conn = psycopg2.connect(host='192.168.2.200', port=10432, user='kaiyou', password='123456', database='kaiyou')
|
|
|
- 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
|
|
|
- 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_time(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, "wq_concede", 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, "wq_concede", 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, "wq_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, "wq_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, "wq_bureau", 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, "wq_bureau", 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, "wq_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, "wq_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, "wq_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, "wq_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.conn.close()
|
|
|
- self.dbpool.close()
|
|
|
-
|
|
|
-
|
|
|
-#网球
|
|
|
-# class Wangqiupipeline1(object):
|
|
|
-# cursor = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
|
|
|
-#
|
|
|
-# def __init__(self, dbpool):
|
|
|
-# self.dbpool = dbpool
|
|
|
-#
|
|
|
-# @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'],
|
|
|
-# # charset='utf8',
|
|
|
-# # cursorclass = cls.cursor,
|
|
|
-# # use_unicode = True,
|
|
|
-# )
|
|
|
-# dbpool = adbapi.ConnectionPool("psycopg2", **dbparms)
|
|
|
-# return cls(dbpool)
|
|
|
-#
|
|
|
-# 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']
|
|
|
-# concedes_dict = item['concedes_dict']
|
|
|
-# concedes_dict_rule = item['concedes_dict_rule']
|
|
|
-# odd_evens_dict = item['odd_evens_dict']
|
|
|
-# odd_evens_dict_rule = item['odd_evens_dict_rule']
|
|
|
-# total_sizes_dict = item['total_number_dict']
|
|
|
-# total_sizes_dict_rule = item['total_number_dict_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:
|
|
|
-# new_hash = hash_func(match_id=game_id, odds_code=key, sort=0, p_id=1)
|
|
|
-# sql1 = "insert into st_wq_odds(lg_id, odds_code, match_id, ctime, utime, max, odds, p_id, p_code, sort, source, sole,condition) values (%s, %s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s, %s) on conflict(sole) do update set utime = %s,odds = %s;"
|
|
|
-# cursor.execute(sql1, (
|
|
|
-# int(league_id), key, int(game_id), utime, utime, value, value, 1, "concede", 0, "hg3535", new_hash,
|
|
|
-# concedes_dict_rule[key], utime, value))
|
|
|
-# # 更新主队st_zq_odds_record表
|
|
|
-# sql2 = "insert into st_wq_odds_record(lg_id, odds_code, match_id, ctime, utime, max, odds, p_id, p_code, sort, source, condition) 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, value, 1, "concede", 0, "hg3535",
|
|
|
-# concedes_dict_rule[key]))
|
|
|
-#
|
|
|
-# # 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)
|
|
|
-# # sql1 = "insert into st_lq_odds(lg_id, odds_code, match_id, ctime, utime, max, odds, p_id, p_code, sort, source, sole,condition) values (%s, %s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s, %s) on conflict(sole) do update set utime = %s,odds = %s;"
|
|
|
-# # cursor.execute(sql1, (int(league_id), key, int(game_id), utime, utime, y, y, 2, "odd_even",x, "hg3535", new_hash, odd_evens_dict_rule[key][x], utime, y))
|
|
|
-# # # 更新主队st_zq_odds_record表
|
|
|
-# # sql2 = "insert into st_lq_odds_record(lg_id, odds_code, match_id, ctime, utime, max, odds, p_id, p_code, sort, source, condition) 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, y, y, 2, "odd_even", x, "hg3535", odd_evens_dict_rule[key][x]))
|
|
|
-#
|
|
|
-# # 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)
|
|
|
-# # sql1 = "insert into st_lq_odds(lg_id, odds_code, match_id, ctime, utime, max, odds, p_id, p_code, sort, source, sole,condition) values (%s, %s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s, %s) on conflict(sole) do update set utime = %s,odds = %s;"
|
|
|
-# # cursor.execute(sql1, (int(league_id), key, int(game_id), utime, utime, y, y, 3, "total_size",x, "hg3535", new_hash, total_sizes_dict_rule[key][x], utime, y))
|
|
|
-# # # 更新主队st_zq_odds_record表
|
|
|
-# # sql2 = "insert into st_lq_odds_record(lg_id, odds_code, match_id, ctime, utime, max, odds, p_id, p_code, sort, source, condition) 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, y, y, 3, "total_size", x, "hg3535", total_sizes_dict_rule[key][x]))
|
|
|
-#
|
|
|
-# # 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)
|
|
|
-# # sql1 = "insert into st_lq_odds(lg_id, odds_code, match_id, ctime, utime, max, odds, p_id, p_code, sort, source, sole,condition) values (%s, %s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s, %s) on conflict(sole) do update set utime = %s,odds = %s;"
|
|
|
-# # cursor.execute(sql1, (int(league_id), "last_home", int(game_id), utime, utime, value, value, 4, "last_number",0, "hg3535", new_hash, key, utime, value))
|
|
|
-# # # 更新主队st_zq_odds_record表
|
|
|
-# # sql2 = "insert into st_lq_odds_record(lg_id, odds_code, match_id, ctime, utime, max, odds, p_id, p_code, sort, source, condition) values (%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, value, 4, "last_number", 0, "hg3535", key))
|
|
|
-#
|
|
|
-# # last_guest = last_numbers_dict['last_home']
|
|
|
-# # 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)
|
|
|
-# # sql1 = "insert into st_lq_odds(lg_id, odds_code, match_id, ctime, utime, max, odds, p_id, p_code, sort, source, sole,condition) values (%s, %s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s, %s) on conflict(sole) do update set utime = %s,odds = %s;"
|
|
|
-# # cursor.execute(sql1, (int(league_id), "last_guest", int(game_id), utime, utime, value, value, 4, "last_number",0, "hg3535", new_hash, key, utime, value))
|
|
|
-# # # 更新主队st_zq_odds_record表
|
|
|
-# # sql2 = "insert into st_lq_odds_record(lg_id, odds_code, match_id, ctime, utime, max, odds, p_id, p_code, sort, source, condition) values (%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, value, 4, "last_number", 0, "hg3535", key))
|
|
|
-#
|
|
|
-# # 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)
|
|
|
-# # sql1 = "insert into st_lq_odds(lg_id, odds_code, match_id, ctime, utime, max, odds, p_id, p_code, sort, source, sole) values (%s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s, %s) on conflict(sole) do update set utime = %s,odds = %s;"
|
|
|
-# # cursor.execute(sql1, (int(league_id), key, int(game_id), utime, utime, value, value, 5, "capot",0, "hg3535", new_hash, utime, value))
|
|
|
-# # # 更新主队st_zq_odds_record表
|
|
|
-# # sql2 = "insert into st_lq_odds_record(lg_id, odds_code, match_id, ctime, utime, max, odds, p_id, p_code, sort, source) values (%s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s);"
|
|
|
-# # cursor.execute(sql2, (int(league_id), key, int(game_id), utime, utime, value, value, 5, "capot", 0, "hg3535"))
|
|
|
-#
|
|
|
-# # 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)
|
|
|
-# # sql1 = "insert into st_lq_odds(lg_id, odds_code, match_id, ctime, utime, max, odds, p_id, p_code, sort, source, sole,condition) values (%s, %s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s, %s) on conflict(sole) do update set utime = %s,odds = %s;"
|
|
|
-# # cursor.execute(sql1, (int(league_id), key, int(game_id), utime, utime, y, y, 6, "team_score", x, "hg3535", new_hash,team_scores_dict_rule[key][x], utime, y))
|
|
|
-# # # 更新主队st_zq_odds_record表
|
|
|
-# # sql2 = "insert into st_lq_odds_record(lg_id, odds_code, match_id, ctime, utime, max, odds, p_id, p_code, sort, source, condition) 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, y, y, 6, "team_score", x, "hg3535",team_scores_dict_rule[key][x]))
|
|
|
-# # 插入赛事表
|
|
|
-# Competition_sql = "insert into st_lq_competition(home_team, guest_team, lg_id, match_id, match_date, match_time,ctime, utime, tag,type,source) values (%s, %s, %s, %s, %s, %s, %s, %s,%s, %s, %s) on conflict(match_id) do update set tag = %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",number))
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-# 棒球 插入赔率----------------------------------------------------------------------------------------------------------
|
|
|
-def bqone_intodb(data1, data2, data3, cursor):
|
|
|
- if data1:
|
|
|
- for key, value in data1.items():
|
|
|
- if value:
|
|
|
- new_hash = hash_func(match_id=data2['game_id'], odds_code=key, sort=data2['sort'], p_id=data2['p_id'])
|
|
|
- odds_only = r_func(match_id=data2['game_id'], odds_code=key, sort=data2['sort'], p_id=data2['p_id'],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, 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;"
|
|
|
- cursor.execute(sql1, (
|
|
|
- int(data2['league_id']), key, int(data2['game_id']), data2['utime'], data2['utime'], value, data2['p_id'], data2["p_code"], data2['sort'], data2["source"], new_hash,
|
|
|
- data3[key], data2['expire_time'],odds_only,1,data2['utime'], value, data2['expire_time'],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(data2['league_id']), key, int(data2['game_id']), data2['utime'], data2['utime'], value, data2['p_id'], data2["p_code"], data2['sort'], data2["source"], data3[key],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(data2['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))
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-def out_time(ctime, i):
|
|
|
- ctime1 = datetime.datetime.strptime(ctime, "%Y-%m-%d %H:%M:%S")
|
|
|
- n_ctime = (ctime1 + datetime.timedelta(hours=i)).strftime("%Y-%m-%d %H:%M:%S")
|
|
|
- return n_ctime
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-class Banqiupipeline(object):
|
|
|
- # cursor = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
|
|
|
-
|
|
|
- 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'],
|
|
|
- # charset='utf8',
|
|
|
- # cursorclass = cls.cursor,
|
|
|
- # use_unicode = True,
|
|
|
- )
|
|
|
- dbpool = adbapi.ConnectionPool("psycopg2", **dbparms)
|
|
|
- conn = psycopg2.connect(host='192.168.2.200', port=10432, user='kaiyou', password='123456', database='kaiyou')
|
|
|
- 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
|
|
|
- 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".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': "bq_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': "bq_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': "bq_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, "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=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, "bq_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, "bq_concede", 0, "hg3535",
|
|
|
- concedes_dict_rule[key],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))
|
|
|
- # 插入记录表
|
|
|
- sql4 = "insert into st_bq_result_record(lg_id, home_team, guest_team, 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'))
|
|
|
- # 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()
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-class BallStatuspipeline(object):
|
|
|
- # cursor = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
|
|
|
- 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'],
|
|
|
- # charset='utf8',
|
|
|
- # cursorclass = cls.cursor,
|
|
|
- # use_unicode = True,
|
|
|
- )
|
|
|
- dbpool = adbapi.ConnectionPool("psycopg2", **dbparms)
|
|
|
- # database = PostgresqlDatabase('kaiyou',**{'host': '192.168.2.200', 'port': 10432, 'user': 'kaiyou', 'password': '123456'})
|
|
|
-
|
|
|
- conn = psycopg2.connect(host='192.168.2.200', port=10432, user='kaiyou', password='123456', database='kaiyou')
|
|
|
- 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;"
|
|
|
- # sql1 = "insert into st_ball_status2(match_id, create_time, status,update_time, ball_type) values (%s,%s, %s, %s, %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)
|
|
|
- # print(zuqiu_toal)
|
|
|
- # print(type(zuqiu_toal))
|
|
|
-
|
|
|
- # match_id = item['match_id']
|
|
|
- # ball_type = item['ball_type']
|
|
|
- # zuqiu_toal = item['zuqiu_total']
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- # 现在时间,时间戳
|
|
|
- utime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- def close_spider(self, spider):
|
|
|
- self.conn.close()
|
|
|
- self.dbpool.close()
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-class BangqiuStatuspipeline(object):
|
|
|
- # cursor = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
|
|
|
- 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'],
|
|
|
- # charset='utf8',
|
|
|
- # cursorclass = cls.cursor,
|
|
|
- # use_unicode = True,
|
|
|
- )
|
|
|
- dbpool = adbapi.ConnectionPool("psycopg2", **dbparms)
|
|
|
- # database = PostgresqlDatabase('kaiyou',**{'host': '192.168.2.200', 'port': 10432, 'user': 'kaiyou', 'password': '123456'})
|
|
|
-
|
|
|
- conn = psycopg2.connect(host='192.168.2.200', port=10432, user='kaiyou', password='123456', database='kaiyou')
|
|
|
- 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, Bangqiustatus):
|
|
|
- zuqiu_toal = item['bangqiu_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;"
|
|
|
- # sql1 = "insert into st_ball_status2(match_id, create_time, status,update_time, ball_type) values (%s,%s, %s, %s, %s);"
|
|
|
- cursor.execute(sql1, (match_id, create_time,staus,update_time, ball_type,update_time))
|
|
|
- # print(zuqiu_toal)
|
|
|
- # print(type(zuqiu_toal))
|
|
|
-
|
|
|
- # match_id = item['match_id']
|
|
|
- # ball_type = item['ball_type']
|
|
|
- # zuqiu_toal = item['zuqiu_total']
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- # 现在时间,时间戳
|
|
|
- utime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- def close_spider(self, spider):
|
|
|
- self.conn.close()
|
|
|
- self.dbpool.close()
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-class lanqiuStatuspipeline(object):
|
|
|
- # cursor = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
|
|
|
- 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'],
|
|
|
- # charset='utf8',
|
|
|
- # cursorclass = cls.cursor,
|
|
|
- # use_unicode = True,
|
|
|
- )
|
|
|
- dbpool = adbapi.ConnectionPool("psycopg2", **dbparms)
|
|
|
- # database = PostgresqlDatabase('kaiyou',**{'host': '192.168.2.200', 'port': 10432, 'user': 'kaiyou', 'password': '123456'})
|
|
|
-
|
|
|
- conn = psycopg2.connect(host='192.168.2.200', port=10432, user='kaiyou', password='123456', database='kaiyou')
|
|
|
- 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, Lanqiustatus):
|
|
|
- zuqiu_toal = item['lanqiu_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;"
|
|
|
- # sql1 = "insert into st_ball_status2(match_id, create_time, status,update_time, ball_type) values (%s,%s, %s, %s, %s);"
|
|
|
- cursor.execute(sql1, (match_id, create_time,staus,update_time, ball_type,update_time))
|
|
|
- # print(zuqiu_toal)
|
|
|
- # print(type(zuqiu_toal))
|
|
|
-
|
|
|
- # match_id = item['match_id']
|
|
|
- # ball_type = item['ball_type']
|
|
|
- # zuqiu_toal = item['zuqiu_total']
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- # 现在时间,时间戳
|
|
|
- utime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- def close_spider(self, spider):
|
|
|
- self.conn.close()
|
|
|
- self.dbpool.close()
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-class WangqiuStatuspipeline(object):
|
|
|
- # cursor = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
|
|
|
- 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'],
|
|
|
- # charset='utf8',
|
|
|
- # cursorclass = cls.cursor,
|
|
|
- # use_unicode = True,
|
|
|
- )
|
|
|
- dbpool = adbapi.ConnectionPool("psycopg2", **dbparms)
|
|
|
- # database = PostgresqlDatabase('kaiyou',**{'host': '192.168.2.200', 'port': 10432, 'user': 'kaiyou', 'password': '123456'})
|
|
|
-
|
|
|
- conn = psycopg2.connect(host='192.168.2.200', port=10432, user='kaiyou', password='123456', database='kaiyou')
|
|
|
- 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, Wanqiustatus):
|
|
|
- zuqiu_toal = item['wangqiu_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;"
|
|
|
- # sql1 = "insert into st_ball_status2(match_id, create_time, status,update_time, ball_type) values (%s,%s, %s, %s, %s);"
|
|
|
- cursor.execute(sql1, (match_id, create_time,staus,update_time, ball_type,update_time))
|
|
|
- # print(zuqiu_toal)
|
|
|
- # print(type(zuqiu_toal))
|
|
|
-
|
|
|
- # match_id = item['match_id']
|
|
|
- # ball_type = item['ball_type']
|
|
|
- # zuqiu_toal = item['zuqiu_total']
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- # 现在时间,时间戳
|
|
|
- utime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- def close_spider(self, spider):
|
|
|
- self.conn.close()
|
|
|
- self.dbpool.close()
|