# import datetime # import json # import pymongo import time import logging # import requests # from ball_func import fuhao from ..utils.helper import Helper from .ball_func import get_pcode, new_time, out_time class Lanqiupipeline(object): def process_item(self, item, spider): # 使用twisted将mysql插入变成异步执行 lq_odds = [] url = 'http://admin.5gogo.com' logger = logging.getLogger(__name__) # # 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'] # 球队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']) # 比赛时间,时间戳 us_time = "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['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'] # 让球 lanqiu = item['lanqiu'] match_date, match_time, time3 = new_time(us_time) # 让球 数据插入数据库 last_time = '2019-12-31 23:59:59' league_dict = {"game_code": "lq", "title": "league", "source": "hg3535"} league_list = [] uuid = Helper.genearte_MD5(league_name + 'hg3535') 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 response_data = Helper.async_post(url + '/setLeague', league_dict) print(response_data) 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": "lq", "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"] 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_list = [] match_data = dict(zip(match_kay, match_value)) match_list.append(match_data) match_dict['data'] = match_list response_data = Helper.async_post(url + '/setMatch', match_dict) print(response_data) # if concedes_dict: # for key, value in concedes_dict.items(): # two_post(data=value, match_id=game_id, odds_code=key, p_id=1, # league_id=league_id, p_code='concede', condition=concedes_dict_rule[key], game_code='lq', zq_odds=lq_odds) # if odd_evens_dict: # for key, value in odd_evens_dict.items(): # one_post(data=value, match_id=game_id, odds_code=key, p_id=2, # league_id=league_id, p_code='two_sides', condition=odd_evens_dict_rule[key], game_code='lq', zq_odds=lq_odds) # # 总分单双 数据插入数据库 # if total_sizes_dict: # for key, value in total_sizes_dict.items(): # two_post(data=value, match_id=game_id, odds_code=key, p_id=3, # league_id=league_id, p_code='total_size', condition=total_sizes_dict_rule[key], game_code='lq', zq_odds=lq_odds) # # 全场总分大小 数据插入数据库 # # 全场总分大小 数据插入数据库 # if team_scores_dict: # for key, value in team_scores_dict.items(): # two_post(data=value, match_id=game_id, odds_code=key, p_id=6, # league_id=league_id, p_code='total_size', condition=team_scores_dict_rule[key], game_code='lq', zq_odds=lq_odds) # lastnumber_dict = {'0或5': '_zero_five', '1或6': '_one_six', '2或7': '_two_seven', '3或8': '_three_eight', '4或9': '_four_nine'} # if last_numbers_dict['last_home']: # for key, value in last_numbers_dict['last_home'].items(): # one_post(data=value, match_id=game_id, odds_code="last_home" + lastnumber_dict[key], p_id=4, # league_id=league_id, p_code='last_number', condition=key, game_code='lq', zq_odds=lq_odds) # if last_numbers_dict['last_guest']: # for key, value in last_numbers_dict['last_guest'].items(): # one_post(data=value, match_id=game_id, odds_code="last_guest" + lastnumber_dict[key], p_id=4, # league_id=league_id, p_code='last_number', condition=key, game_code='lq', zq_odds=lq_odds) # three_post(data=capots_dict, match_id=game_id, p_id=5, league_id=league_id, p_code='capot', condition="", game_code='lq', zq_odds=lq_odds) # match_date, match_time, time3 = new_time(ctime) # n_time = out_time(time3, 1.5) # us_time = ctime # if lanqiu == "篮球": # if pt == 1: # payload = { # "game_code": "lq", # "title": "competition", # "data": { # "home_team": team_home, # "guest_team": team_guest, # "lg_id": league_id, # "status": 0, # "match_id": game_id, # "match_date": match_date, # "match_time": match_time, # "tag": number, # "source": "hg3535", # "is_rollball": 0, # "is_today": 1, # "is_morningplate": 0, # "is_stringscene": 0, # "us_time": us_time # } # } # if pt == 2: # payload = { # "game_code": "lq", # "title": "competition", # "data": { # "home_team": team_home, # "guest_team": team_guest, # "lg_id": league_id, # "status": 0, # "match_id": game_id, # "match_date": match_date, # "match_time": match_time, # "tag": number, # "source": "hg3535", # "is_rollball": 0, # "is_today": 0, # "is_morningplate": 1, # "is_stringscene": 0, # "us_time": us_time # } # } # if pt == 3: # payload = { # "game_code": "lq", # "title": "competition", # "data": { # "home_team": team_home, # "guest_team": team_guest, # "lg_id": league_id, # "status": 0, # "match_id": game_id, # "match_date": match_date, # "match_time": match_time, # "tag": number, # "source": "hg3535", # "is_rollball": 0, # "is_today": 0, # "is_morningplate": 0, # "is_stringscene": 1, # "us_time": us_time # } # } # lq_odds.insert(0, payload) # r = requests.post(url, data={"data": json.dumps(lq_odds)}) # # logger.warning(r.text) # print(r.text) # return item