import datetime import hashlib import time # 生成哈希索引 sole 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 # 生成odds_only哈希 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 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) time4 = time3 data_time = str(time4).split(" ") match_date = data_time[0] match_time = data_time[1] return match_date, match_time, time3 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 def fuhao(f): if f.startswith('+'): f = f.replace('+', '-') return f elif f.startswith('-'): f = f.replace('-', '+') return f else: return f def get_pcode(corner_ball, code): code_dict = {'concede': 1, 'capot': 2, 'two_sides': 3, 'total_goal': 4, 'half_full': 5, 'bodan': 6, 'first_last_ball': 7, 'tema_ball': 11, 'goal_size': 13} if corner_ball: if corner_ball == "角球": p_code = "corner_ball" p_id = 9 elif corner_ball == "会晋级": p_code = "promotion" p_id = 10 elif corner_ball == "罚牌数": p_code = "Penalty_card" p_id = 12 else: p_code = code p_id = code_dict[code] return p_code, p_id else: return code, code_dict[code] # ---------------------------------------------------------------------------------------------------------------------- def new_times(ctime): time1 = time.mktime(time.strptime(ctime, '%Y-%m-%d %H:%M:%S')) + 43200 time2 = time.localtime(time1) time3 = time.strftime('%Y-%m-%d %H:%M:%S', time2) data_time = str(time3).split(" ") match_date = data_time[0] match_time = data_time[1] return match_date,match_time def news_times(ctime): time1 = time.mktime(time.strptime(ctime, '%Y-%m-%d %H:%M:%S')) + 43200 time2 = time.localtime(time1) time3 = time.strftime('%Y-%m-%d %H:%M:%S', time2) time4 = time3 data_time = str(time4).split(" ") match_date = data_time[0] match_time = data_time[1] return match_date, match_time, time3 def one_post(data, match_id, odds_code, p_id, league_id, p_code, condition, game_code, zq_odds): if data: new_hash = hash_func(match_id=match_id, odds_code=odds_code, sort=0, p_id=p_id) r_hash = r_func(match_id=match_id, odds_code=odds_code, sort=0, p_id=p_id, odd=data) payload = { "game_code": game_code, "title": "odds", "data": { "match_id": match_id, "lg_id": league_id, "odds_code": odds_code, "status": 0, "sort": 0, "p_code": p_code, "odds": data, "condition": condition, "odds_only": r_hash, "sole": new_hash, "source": "hg3535", "type": 0, "team": "" } } zq_odds.append(payload) # return payload def two_post(data, match_id, odds_code, p_id, league_id, p_code, condition, game_code, zq_odds): if data: # odds_list = [] for index, value in enumerate(data): if value: s_hash = hash_func(match_id=match_id, odds_code=odds_code, sort=index, p_id=p_id) o_hash = r_func(match_id=match_id, odds_code=odds_code, sort=index, p_id=p_id, odd=value) f1 = fuhao(str(condition[index])) payload = { "game_code": game_code, "title": "odds", "data": { "match_id": match_id, "lg_id": league_id, "odds_code": odds_code, "status": 0, "sort": index, "p_code": p_code, "odds": value, "condition": f1, "odds_only": o_hash, "sole": s_hash, "source": "hg3535", "type": 0, "team": "" } } zq_odds.append(payload) # odds_list.append(payload) # return odds_list def three_post(data, match_id, p_id, league_id, p_code, condition, game_code, zq_odds): if data: # odd_list = [] for key, value in data.items(): if value: s_hash = hash_func(match_id=match_id, odds_code=key, sort=0, p_id=p_id) o_hash = r_func(match_id=match_id, odds_code=key, sort=0, p_id=p_id, odd=value) try: f1 = fuhao(str(condition[key])) except: f1 = "" payload = { "game_code": game_code, "title": "odds", "data": { "match_id": match_id, "lg_id": league_id, "odds_code": key, "status": 0, "sort": 0, "p_code": p_code, "odds": value, "condition": f1, "odds_only": o_hash, "sole": s_hash, "source": "hg3535", "type": 0, "team": "" } } zq_odds.append(payload) # odd_list.append(payload) # return odd_list def gs_post(ball, league_id, league_name, data_game): if ball == "足球": n_gameid = int('1' + str(league_id)) payload = { "game_code": "zq", "title": "competition", "data": { "home_team": league_name, "guest_team": "", "lg_id": league_id, "status": 0, "match_id": n_gameid, "source": "hg3535", "us_time": data_game, "match_date": "", "match_time": "", "tag": "", "is_rollball": 0, "is_today": 0, "is_morningplate": 0, "is_stringscene": 0, } } elif ball == "篮球": n_gameid = int('1' + str(league_id)) payload = { "game_code": "zq", "title": "competition", "data": { "home_team": league_name, "guest_team": "", "lg_id": league_id, "status": 0, "match_id": n_gameid, "source": "hg3535", "us_time": data_game, "match_date": "", "match_time": "", "tag": "", "is_rollball": 0, "is_today": 0, "is_morningplate": 0, "is_stringscene": 0, } } elif ball == "网球": n_gameid = int('1' + str(league_id)) payload = { "game_code": "zq", "title": "competition", "data": { "home_team": league_name, "guest_team": "", "lg_id": league_id, "status": 0, "match_id": n_gameid, "source": "hg3535", "us_time": data_game, "match_date": "", "match_time": "", "tag": "", "is_rollball": 0, "is_today": 0, "is_morningplate": 0, "is_stringscene": 0, } } elif ball == "棒球": n_gameid = int('1' + str(league_id)) payload = { "game_code": "zq", "title": "competition", "data": { "home_team": league_name, "guest_team": "", "lg_id": league_id, "status": 0, "match_id": n_gameid, "source": "hg3535", "us_time": data_game, "match_date": "", "match_time": "", "tag": "", "is_rollball": 0, "is_today": 0, "is_morningplate": 0, "is_stringscene": 0, } } return payload def go_post(ball, league_id, new_champion, new_league_name, value, r_hash, new_hash, tema_home): game_id = int('1' + str(league_id)) if ball == "足球": payload = { "game_code": "zq", "title": "odds", "data": { "match_id": league_id, "lg_id": game_id, "odds_code": new_champion, "status": 0, "sort": 0, "p_code": new_league_name, "odds": value, "condition": "", "odds_only": r_hash, "sole": new_hash, "source": 'hg3535', "type": 1, "team": tema_home } } elif ball == "篮球": payload = { "game_code": "lq", "title": "odds", "data": { "match_id": league_id, "lg_id": game_id, "odds_code": new_champion, "status": 0, "sort": 0, "p_code": new_league_name, "odds": value, "condition": "", "odds_only": r_hash, "sole": new_hash, "source": "hg3535", "type": 1, "team": tema_home } } elif ball == "网球": payload = { "game_code": "wq", "title": "odds", "data": { "match_id": league_id, "lg_id": game_id, "odds_code": new_champion, "status": 0, "sort": 0, "p_code": new_league_name, "odds": value, "condition": "", "odds_only": r_hash, "sole": new_hash, "source": "hg3535", "type": 1, "team": tema_home } } elif ball == "棒球": payload = { "game_code": "bq", "title": "odds", "data": { "match_id": league_id, "lg_id": game_id, "odds_code": new_champion, "status": 0, "sort": 0, "p_code": new_league_name, "odds": value, "condition": "", "odds_only": r_hash, "sole": new_hash, "source": "hg3535", "type": 1, "team": tema_home } } return payload def guanl_post(ball, league_name, league_id, time3): if ball == "足球": payload = { "game_code": "zq", "title": "league", "data": { "name_chinese": league_name, "kind": "1", "match_mode": "1", "if_stop": "0", # "belong": "", "last_time": time3, "lg_id": league_id, "source": "hg3535" } } elif ball == "篮球": payload = { "game_code": "zq", "title": "league", "data": { "name_chinese": league_name, "kind": "1", "match_mode": "1", "if_stop": "0", # "belong": "", "last_time": time3, "lg_id": league_id, "source": "hg3535" } } elif ball == "网球": payload = { "game_code": "zq", "title": "league", "data": { "name_chinese": league_name, "kind": "1", "match_mode": "1", "if_stop": "0", # "belong": "", "last_time": time3, "lg_id": league_id, "source": "hg3535" } } elif ball == "棒球": payload = { "game_code": "zq", "title": "league", "data": { "name_chinese": league_name, "kind": "1", "match_mode": "1", "if_stop": "0", # "belong": "", "last_time": time3, "lg_id": league_id, "source": "hg3535" } } return payload def liansai(area_name, name_chinese, st_league, area_dict, game_code, qiu): if area_name in area_dict: payload = { "game_code": game_code, "title": "league", "data": { "name_chinese": name_chinese, "kind": "1", "match_mode": "1", "if_stop": "0", "belong": area_name, "last_time": '2019-12-31 23:59:59', "lg_id": st_league, "source": "hg3535" } } else: if area_name == qiu: payload = { "game_code": game_code, "title": "league", "data": { "name_chinese": name_chinese, "kind": "1", "match_mode": "1", "if_stop": "0", "belong": " ", "last_time": '2019-12-31 23:59:59', "lg_id": st_league, "source": "hg3535" } } else: payload = { "game_code": game_code, "title": "league", "data": { "name_chinese": name_chinese, "kind": "1", "match_mode": "1", "if_stop": "0", "belong": area_name, "last_time": '2019-12-31 23:59:59', "lg_id": st_league, "source": "hg3535" }} return payload