| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315 |
- import datetime
- import pymongo
- import time
- import logging
- from .ball_func import fuhao
- from ..utils.helper import Helper
- from .ball_func import get_pcode, new_time, out_time
- from concurrent.futures import ThreadPoolExecutor
- from requests_futures.sessions import FuturesSession
- class Wangqiupipeline(object):
- def open_spider(self, spider):
- self.mongo = pymongo.MongoClient(host="192.168.2.200", username="kaiyou", password="kaiyou", port=27017)
- self.db = self.mongo['kaiyou']
- self.session = FuturesSession(executor=ThreadPoolExecutor(max_workers=10))
- def process_item(self, item, spider):
- wq_odds = []
- logger = logging.getLogger(__name__)
- url = 'http://admin.5gogo.com'
- # logger.warning(query.addErrback(self.handle_error, item, spider))
- # 联赛id
- league_id = item['league_id']
- # 联赛名
- league_name = item['league_name']
- # result = item['result']
- # 比赛id
- match_id = item['game_id']
- # print(game_id)
- # 球队1
- team_home = item['team_home']
- # 球队2
- team_guest = item['team_guest']
- # 数量(97>)
- tag_number = item['number']
- # 比赛状态
- zhuangtai = item['zhuangtai']
- # 日期
- # data_game = item['data_game']
- try:
- data_game = item['data_game'].split("/")
- month = str(data_game[1].strip())
- day = str(data_game[0])
- except Exception as e:
- logger.warning(e)
- data_game = item['data_game'].split(" ")
- months = str(data_game[1].strip())
- month_dict = {'Jan': '01', 'Feb': '02', 'Mar': '03', 'Apr': '04', 'May': '05', 'Jun': '06', 'Jul': '07',
- 'Aug': '08', 'Sep': '09', 'Oct': '10', 'Nov': '11', 'Dec': '12'}
- month = month_dict[months]
- day = str(data_game[0])
- # 比赛时间
- time_game = str(item['time_game'])
- # 比赛时间,时间戳
- ctime = "2019" + "-" + month + "-" + day + " " + time_game + ":00"
- r_ctime = "2019" + "-" + month + "-" + day
- # 现在时间,时间戳
- utime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
- expire_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time() + 60))
- # 队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']
- # 冠军
- 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']
- us_time = ctime
- match_date, match_time, time3 = new_time(ctime)
- n_time = out_time(time3, 3)
- uuid = Helper.genearte_MD5(league_name + 'hg3535')
- """联赛"""
- last_time = '2019-12-31 23:59:59'
- league_dict = {"game_code": "wq", "title": "league", "source": "hg3535"}
- league_list = []
- league_key = ["name_chinese", "kind", "match_mode", "if_stop", "last_time", "lg_id", "source", "uuid"]
- league_value = [league_name, "1", "1", "0", last_time, league_id, "hg3535", uuid]
- league_data = dict(zip(league_key, league_value))
- league_list.append(league_data)
- league_dict['data'] = league_list
- # print(league_list)
- # print(league_dict)
- if self.db.hg3535_wq_league.find({'lg_id': league_id}).count() < 1:
- res = Helper.async_post(url + '/setLeague', league_dict)
- print(res)
- self.db.hg3535_wq_league.insert(league_list)
- """赛事"""
- competition = self.db.hg3535_wq_competition.find_one({"match_id": match_id})
- match_list = []
- if competition:
- print('赛事已存在,修改赛事四状态')
- is_morningplate = competition['is_morningplate']
- is_rollball = competition['is_rollball']
- is_stringscene = competition['is_stringscene']
- is_today = competition['is_today']
- lmtime = competition['match_time']
- if pt == 3:
- if is_stringscene != 1 or lmtime != match_time:
- match_dict = {"game_code": "wq", "title": "match", "source": "hg3535"}
- match_key = ["home_team", "guest_team", "lg_id", "status", "match_id", "match_date", "match_time",
- "tag", "source", "is_rollball", "is_morningplate", "is_stringscene", "us_time", "uuid",
- "half_match_id", "is_today", 'rule']
- match_value = [team_home, team_guest, league_id, 0, match_id, match_date, match_time, tag_number,
- "hg3535", is_rollball, is_morningplate, 1, us_time, uuid, 0, is_today, '']
- match_data = dict(zip(match_key, match_value))
- match_list.append(match_data)
- match_dict['data'] = match_list
- # print(match_list)
- # print(match_dict)
- res = Helper.async_post(url + '/setMatch', match_dict)
- print(res)
- self.db.hg3535_wq_competition.update({'match_id': match_id},
- {"$set": {"is_stringscene": 1, 'match_time': match_time}},
- upsert=True)
- if pt == 2:
- if is_morningplate != 1 or lmtime != match_time:
- match_dict = {"game_code": "wq", "title": "match", "source": "hg3535"}
- match_key = ["home_team", "guest_team", "lg_id", "status", "match_id", "match_date", "match_time",
- "tag", "source", "is_rollball", "is_morningplate", "is_stringscene", "us_time", "uuid",
- "half_match_id", "is_today", 'rule']
- match_value = [team_home, team_guest, league_id, 0, match_id, match_date, match_time, tag_number,
- "hg3535", is_rollball, 1, is_stringscene, us_time, uuid, 0, is_today, '']
- match_data = dict(zip(match_key, match_value))
- match_list.append(match_data)
- match_dict['data'] = match_list
- # print(match_list)
- # print(match_dict)
- res = Helper.async_post(url + '/setMatch', match_dict)
- print(res)
- self.db.hg3535_wq_competition.update({'match_id': match_id},
- {"$set": {"is_morningplate": 1, 'match_time': match_time}},
- upsert=True)
- if pt == 1:
- if is_today != 1 or lmtime != match_time:
- match_dict = {"game_code": "wq", "title": "match", "source": "hg3535"}
- match_kay = ["home_team", "guest_team", "lg_id", "status", "match_id", "match_date", "match_time",
- "tag", "source", "is_rollball", "is_morningplate", "is_stringscene", "us_time", "uuid",
- "half_match_id", "is_today", 'rule']
- match_value = [team_home, team_guest, league_id, 0, match_id, match_date, match_time, tag_number,
- "hg3535", is_rollball, is_morningplate, is_stringscene, us_time, uuid, 0, 1, '']
- match_data = dict(zip(match_kay, match_value))
- match_list.append(match_data)
- match_dict['data'] = match_list
- # print(match_list)
- # print(match_dict)
- res = Helper.async_post(url + '/setMatch', match_dict)
- print(res)
- self.db.hg3535_wq_competition.update({'match_id': match_id},
- {"$set": {"is_today": 1, 'match_time': match_time}},
- upsert=True)
- else:
- print("赛事已存在,赛事状态时间未改变,不做修改")
- else:
- if pt == 3:
- is_rollball = 0
- is_today = 0
- is_morningplate = 0
- is_stringscene = 1
- elif pt == 2:
- is_rollball = 0
- is_today = 0
- is_morningplate = 1
- is_stringscene = 0
- else:
- is_today = 1
- is_rollball = 0
- is_morningplate = 0
- is_stringscene = 0
- match_dict = {"game_code": "wq", "title": "match", "source": "hg3535"}
- match_kay = ["home_team", "guest_team", "lg_id", "status", "match_id", "match_date", "match_time", "tag",
- "source", "is_rollball", "is_morningplate", "is_stringscene", "us_time", "uuid",
- "half_match_id", "is_today", 'rule']
- match_value = [team_home, team_guest, league_id, 0, match_id, match_date, match_time, tag_number, "hg3535",
- is_rollball, is_morningplate, is_stringscene, us_time, uuid, 0, is_today, '']
- match_data = dict(zip(match_kay, match_value))
- match_list.append(match_data)
- match_dict['data'] = match_list
- res = Helper.async_post(url + '/setMatch', match_dict)
- print(res)
- self.db.hg3535_wq_competition.insert(match_list)
- """赔率"""
- try:
- result = self.db.hg3535_wq_odds.find_one({'match_id': match_id, 'pt': pt})
- odds_only_list = result['odds_only']
- except:
- result = ''
- odds_only_list = []
- wangqiu = item['wangqiu']
- data_list = []
- odds_onlys = []
- # 让盘
- if concedes_dict:
- for key, value in concedes_dict.items():
- sole_str = 'LD' + str(key) + '0' + str(match_id) + 'hg3535'
- sole = Helper.genearte_MD5(sole_str)
- odds_str = 'LD' + str(key) + str(match_id) + 'hg3535' + str(concedes_dict_rule[key]) + str(
- value)
- odds_only = Helper.genearte_MD5(odds_str)
- condition = fuhao(concedes_dict_rule[key])
- concedes_dict_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
- "odds_only", "sole", "source", "type", "team"]
- concedes_dict_value = [match_id, league_id, key, '0', 0, 'LD', value, condition,
- odds_only, sole, 'hg3535', '0', '']
- concedes_dict_data = dict(zip(concedes_dict_key, concedes_dict_value))
- odds_onlys.append(odds_only)
- if odds_only not in odds_only_list:
- data_list.append(concedes_dict_data)
- # 让局
- if bureaus_dict:
- for key, value in bureaus_dict.items():
- sole_str = 'LB' + str(key) + str(match_id) + 'hg3535'
- sole = Helper.genearte_MD5(sole_str)
- odds_str = 'LB' + str(key) + str(match_id) + 'hg3535' + str(bureaus_dict_rule[key]) + str(
- value)
- odds_only = Helper.genearte_MD5(odds_str)
- condition = fuhao(bureaus_dict_rule[key])
- bureaus_dict_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
- "odds_only", "sole", "source", "type", "team"]
- bureaus_dict_value = [match_id, league_id, key, '0', 0, 'LB', value, condition,
- odds_only, sole, 'hg3535', '0', '']
- bureaus_dict_data = dict(zip(bureaus_dict_key, bureaus_dict_value))
- odds_onlys.append(odds_only)
- if odds_only not in odds_only_list:
- data_list.append(bureaus_dict_data)
- # 总局数大小
- if total_number_dict:
- for key, value in total_number_dict.items():
- sole_str = 'TN' + str(key) + str(match_id) + 'hg3535'
- sole = Helper.genearte_MD5(sole_str)
- odds_str = 'TN' + str(key) + str(match_id) + 'hg3535' + str(
- total_number_dict_rule[key]) + str(value)
- odds_only = Helper.genearte_MD5(odds_str)
- condition = fuhao(total_number_dict_rule[key])
- total_number_dict_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
- "condition",
- "odds_only", "sole", "source", "type", "team"]
- total_number_dict_value = [match_id, league_id, key, '0', 0, 'TN', value, condition,
- odds_only, sole, 'hg3535', '0', '']
- total_number_dict_data = dict(zip(total_number_dict_key, total_number_dict_value))
- odds_onlys.append(odds_only)
- if odds_only not in odds_only_list:
- data_list.append(total_number_dict_data)
- # 总局数单双
- if odd_evens_dict:
- for key, value in odd_evens_dict.items():
- sole_str = 'TS' + str(key) + str(match_id) + 'hg3535'
- sole = Helper.genearte_MD5(sole_str)
- odds_str = 'TS' + str(key) + str(match_id) + 'hg3535' + str(odd_evens_dict_rule[key]) + str(
- value)
- odds_only = Helper.genearte_MD5(odds_str)
- condition = fuhao(odd_evens_dict_rule[key])
- odd_evens_dict_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
- "odds_only", "sole", "source", "type", "team"]
- odd_evens_dict_value = [match_id, league_id, key, '0', 0, 'TS', value, condition,
- odds_only, sole, 'hg3535', '0', '']
- odd_evens_dict_data = dict(zip(odd_evens_dict_key, odd_evens_dict_value))
- odds_onlys.append(odds_only)
- if odds_only not in odds_only_list:
- data_list.append(odd_evens_dict_data)
- # 冠军
- if kemps_dict:
- for key, value in kemps_dict.items():
- sole_str = 'C' + str(key) + str(match_id) + 'hg3535'
- sole = Helper.genearte_MD5(sole_str)
- odds_str = 'C' + str(key) + str(match_id) + 'hg3535' + '2' + str(value)
- odds_only = Helper.genearte_MD5(odds_str)
- kemps_dict_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
- "odds_only", "sole", "source", "type", "team"]
- kemps_dict_value = [match_id, league_id, key, '0', 0, 'C', value, '',
- odds_only, sole, 'hg3535', '0', '']
- kemps_dict_data = dict(zip(kemps_dict_key, kemps_dict_value))
- odds_onlys.append(odds_only)
- if odds_only not in odds_only_list:
- data_list.append(kemps_dict_data)
- if pt == 3:
- ris_stringscene = 1
- else:
- ris_stringscene = 0
- odds_key = ["game_code", "title", "match_id", "lg_id", "data", "source", "odds_only", "tag", "uuid",
- "is_stringscene", "utime", "pt"]
- odds_value = ["wq", "odds", match_id, league_id, data_list, "hg3535", odds_onlys, tag_number, uuid,
- ris_stringscene, utime, pt]
- odds_dict = dict(zip(odds_key, odds_value))
- # print(odds_dict)
- # print(123)
- if data_list:
- res = Helper.async_post(url + '/setOdds', odds_dict)
- print(res)
- if '成功' in res:
- if result:
- self.db.hg3535_wq_odds.update({'match_id': match_id, 'pt': pt}, {
- '$set': {"data": data_list, "odds_only": odds_onlys, "utime": utime}}, upsert=True)
- else:
- self.db.hg3535_wq_odds.insert(odds_dict)
|