| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478 |
- 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
|