ball_func.py 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. import datetime
  2. import hashlib
  3. import time
  4. # 生成哈希索引 sole
  5. def hash_func(match_id, odds_code, sort, p_id):
  6. m = hashlib.md5()
  7. a = str(match_id) + str(odds_code) + str(sort) + str(p_id)
  8. m.update(a.encode('utf-8'))
  9. c = m.hexdigest()
  10. return c
  11. # 生成odds_only哈希
  12. def r_func(match_id, odds_code, sort, p_id, odd):
  13. m = hashlib.md5()
  14. a = str(match_id) + str(odds_code) + str(sort) + str(p_id) + str(odd)
  15. m.update(a.encode('utf-8'))
  16. c = m.hexdigest()
  17. return c
  18. # 转换成本地时间
  19. def new_time(ctime):
  20. time1 = time.mktime(time.strptime(ctime, '%Y-%m-%d %H:%M:%S')) + 43200
  21. time2 = time.localtime(time1)
  22. time3 = time.strftime('%Y-%m-%d %H:%M:%S', time2)
  23. time4 = time3
  24. data_time = str(time4).split(" ")
  25. match_date = data_time[0]
  26. match_time = data_time[1]
  27. return match_date, match_time, time3
  28. def out_time(ctime, i):
  29. ctime1 = datetime.datetime.strptime(ctime, "%Y-%m-%d %H:%M:%S")
  30. n_ctime = (ctime1 + datetime.timedelta(hours=i)).strftime("%Y-%m-%d %H:%M:%S")
  31. return n_ctime
  32. def fuhao(f):
  33. if f.startswith('+'):
  34. f = f.replace('+', '-')
  35. return f
  36. elif f.startswith('-'):
  37. f = f.replace('-', '+')
  38. return f
  39. else:
  40. return f
  41. def get_pcode(corner_ball, code):
  42. code_dict = {'concede': 1, 'capot': 2, 'two_sides': 3, 'total_goal': 4, 'half_full': 5, 'bodan': 6,
  43. 'first_last_ball': 7, 'tema_ball': 11, 'goal_size': 13}
  44. if corner_ball:
  45. if corner_ball == "角球":
  46. p_code = "corner_ball"
  47. p_id = 9
  48. elif corner_ball == "会晋级":
  49. p_code = "promotion"
  50. p_id = 10
  51. elif corner_ball == "罚牌数":
  52. p_code = "Penalty_card"
  53. p_id = 12
  54. else:
  55. p_code = code
  56. p_id = code_dict[code]
  57. return p_code, p_id
  58. else:
  59. return code, code_dict[code]
  60. # ----------------------------------------------------------------------------------------------------------------------
  61. def new_times(ctime):
  62. time1 = time.mktime(time.strptime(ctime, '%Y-%m-%d %H:%M:%S')) + 43200
  63. time2 = time.localtime(time1)
  64. time3 = time.strftime('%Y-%m-%d %H:%M:%S', time2)
  65. data_time = str(time3).split(" ")
  66. match_date = data_time[0]
  67. match_time = data_time[1]
  68. return match_date,match_time
  69. def news_times(ctime):
  70. time1 = time.mktime(time.strptime(ctime, '%Y-%m-%d %H:%M:%S')) + 43200
  71. time2 = time.localtime(time1)
  72. time3 = time.strftime('%Y-%m-%d %H:%M:%S', time2)
  73. time4 = time3
  74. data_time = str(time4).split(" ")
  75. match_date = data_time[0]
  76. match_time = data_time[1]
  77. return match_date, match_time, time3
  78. def one_post(data, match_id, odds_code, p_id, league_id, p_code, condition, game_code, zq_odds):
  79. if data:
  80. new_hash = hash_func(match_id=match_id, odds_code=odds_code, sort=0, p_id=p_id)
  81. r_hash = r_func(match_id=match_id, odds_code=odds_code, sort=0, p_id=p_id, odd=data)
  82. payload = {
  83. "game_code": game_code,
  84. "title": "odds",
  85. "data": {
  86. "match_id": match_id,
  87. "lg_id": league_id,
  88. "odds_code": odds_code,
  89. "status": 0,
  90. "sort": 0,
  91. "p_code": p_code,
  92. "odds": data,
  93. "condition": condition,
  94. "odds_only": r_hash,
  95. "sole": new_hash,
  96. "source": "hg3535",
  97. "type": 0,
  98. "team": ""
  99. }
  100. }
  101. zq_odds.append(payload)
  102. # return payload
  103. def two_post(data, match_id, odds_code, p_id, league_id, p_code, condition, game_code, zq_odds):
  104. if data:
  105. # odds_list = []
  106. for index, value in enumerate(data):
  107. if value:
  108. s_hash = hash_func(match_id=match_id, odds_code=odds_code, sort=index, p_id=p_id)
  109. o_hash = r_func(match_id=match_id, odds_code=odds_code, sort=index, p_id=p_id, odd=value)
  110. f1 = fuhao(str(condition[index]))
  111. payload = {
  112. "game_code": game_code,
  113. "title": "odds",
  114. "data": {
  115. "match_id": match_id,
  116. "lg_id": league_id,
  117. "odds_code": odds_code,
  118. "status": 0,
  119. "sort": index,
  120. "p_code": p_code,
  121. "odds": value,
  122. "condition": f1,
  123. "odds_only": o_hash,
  124. "sole": s_hash,
  125. "source": "hg3535",
  126. "type": 0,
  127. "team": ""
  128. }
  129. }
  130. zq_odds.append(payload)
  131. # odds_list.append(payload)
  132. # return odds_list
  133. def three_post(data, match_id, p_id, league_id, p_code, condition, game_code, zq_odds):
  134. if data:
  135. # odd_list = []
  136. for key, value in data.items():
  137. if value:
  138. s_hash = hash_func(match_id=match_id, odds_code=key, sort=0, p_id=p_id)
  139. o_hash = r_func(match_id=match_id, odds_code=key, sort=0, p_id=p_id, odd=value)
  140. try:
  141. f1 = fuhao(str(condition[key]))
  142. except:
  143. f1 = ""
  144. payload = {
  145. "game_code": game_code,
  146. "title": "odds",
  147. "data": {
  148. "match_id": match_id,
  149. "lg_id": league_id,
  150. "odds_code": key,
  151. "status": 0,
  152. "sort": 0,
  153. "p_code": p_code,
  154. "odds": value,
  155. "condition": f1,
  156. "odds_only": o_hash,
  157. "sole": s_hash,
  158. "source": "hg3535",
  159. "type": 0,
  160. "team": ""
  161. }
  162. }
  163. zq_odds.append(payload)
  164. # odd_list.append(payload)
  165. # return odd_list
  166. def gs_post(ball, league_id, league_name, data_game):
  167. if ball == "足球":
  168. n_gameid = int('1' + str(league_id))
  169. payload = {
  170. "game_code": "zq",
  171. "title": "competition",
  172. "data": {
  173. "home_team": league_name,
  174. "guest_team": "",
  175. "lg_id": league_id,
  176. "status": 0,
  177. "match_id": n_gameid,
  178. "source": "hg3535",
  179. "us_time": data_game,
  180. "match_date": "",
  181. "match_time": "",
  182. "tag": "",
  183. "is_rollball": 0,
  184. "is_today": 0,
  185. "is_morningplate": 0,
  186. "is_stringscene": 0,
  187. }
  188. }
  189. elif ball == "篮球":
  190. n_gameid = int('1' + str(league_id))
  191. payload = {
  192. "game_code": "zq",
  193. "title": "competition",
  194. "data": {
  195. "home_team": league_name,
  196. "guest_team": "",
  197. "lg_id": league_id,
  198. "status": 0,
  199. "match_id": n_gameid,
  200. "source": "hg3535",
  201. "us_time": data_game,
  202. "match_date": "",
  203. "match_time": "",
  204. "tag": "",
  205. "is_rollball": 0,
  206. "is_today": 0,
  207. "is_morningplate": 0,
  208. "is_stringscene": 0,
  209. }
  210. }
  211. elif ball == "网球":
  212. n_gameid = int('1' + str(league_id))
  213. payload = {
  214. "game_code": "zq",
  215. "title": "competition",
  216. "data": {
  217. "home_team": league_name,
  218. "guest_team": "",
  219. "lg_id": league_id,
  220. "status": 0,
  221. "match_id": n_gameid,
  222. "source": "hg3535",
  223. "us_time": data_game,
  224. "match_date": "",
  225. "match_time": "",
  226. "tag": "",
  227. "is_rollball": 0,
  228. "is_today": 0,
  229. "is_morningplate": 0,
  230. "is_stringscene": 0,
  231. }
  232. }
  233. elif ball == "棒球":
  234. n_gameid = int('1' + str(league_id))
  235. payload = {
  236. "game_code": "zq",
  237. "title": "competition",
  238. "data": {
  239. "home_team": league_name,
  240. "guest_team": "",
  241. "lg_id": league_id,
  242. "status": 0,
  243. "match_id": n_gameid,
  244. "source": "hg3535",
  245. "us_time": data_game,
  246. "match_date": "",
  247. "match_time": "",
  248. "tag": "",
  249. "is_rollball": 0,
  250. "is_today": 0,
  251. "is_morningplate": 0,
  252. "is_stringscene": 0,
  253. }
  254. }
  255. return payload
  256. def go_post(ball, league_id, new_champion, new_league_name, value, r_hash, new_hash, tema_home):
  257. game_id = int('1' + str(league_id))
  258. if ball == "足球":
  259. payload = {
  260. "game_code": "zq",
  261. "title": "odds",
  262. "data": {
  263. "match_id": league_id,
  264. "lg_id": game_id,
  265. "odds_code": new_champion,
  266. "status": 0,
  267. "sort": 0,
  268. "p_code": new_league_name,
  269. "odds": value,
  270. "condition": "",
  271. "odds_only": r_hash,
  272. "sole": new_hash,
  273. "source": 'hg3535',
  274. "type": 1,
  275. "team": tema_home
  276. }
  277. }
  278. elif ball == "篮球":
  279. payload = {
  280. "game_code": "lq",
  281. "title": "odds",
  282. "data": {
  283. "match_id": league_id,
  284. "lg_id": game_id,
  285. "odds_code": new_champion,
  286. "status": 0,
  287. "sort": 0,
  288. "p_code": new_league_name,
  289. "odds": value,
  290. "condition": "",
  291. "odds_only": r_hash,
  292. "sole": new_hash,
  293. "source": "hg3535",
  294. "type": 1,
  295. "team": tema_home
  296. }
  297. }
  298. elif ball == "网球":
  299. payload = {
  300. "game_code": "wq",
  301. "title": "odds",
  302. "data": {
  303. "match_id": league_id,
  304. "lg_id": game_id,
  305. "odds_code": new_champion,
  306. "status": 0,
  307. "sort": 0,
  308. "p_code": new_league_name,
  309. "odds": value,
  310. "condition": "",
  311. "odds_only": r_hash,
  312. "sole": new_hash,
  313. "source": "hg3535",
  314. "type": 1,
  315. "team": tema_home
  316. }
  317. }
  318. elif ball == "棒球":
  319. payload = {
  320. "game_code": "bq",
  321. "title": "odds",
  322. "data": {
  323. "match_id": league_id,
  324. "lg_id": game_id,
  325. "odds_code": new_champion,
  326. "status": 0,
  327. "sort": 0,
  328. "p_code": new_league_name,
  329. "odds": value,
  330. "condition": "",
  331. "odds_only": r_hash,
  332. "sole": new_hash,
  333. "source": "hg3535",
  334. "type": 1,
  335. "team": tema_home
  336. }
  337. }
  338. return payload
  339. def guanl_post(ball, league_name, league_id, time3):
  340. if ball == "足球":
  341. payload = {
  342. "game_code": "zq",
  343. "title": "league",
  344. "data": {
  345. "name_chinese": league_name,
  346. "kind": "1",
  347. "match_mode": "1",
  348. "if_stop": "0",
  349. # "belong": "",
  350. "last_time": time3,
  351. "lg_id": league_id,
  352. "source": "hg3535"
  353. }
  354. }
  355. elif ball == "篮球":
  356. payload = {
  357. "game_code": "zq",
  358. "title": "league",
  359. "data": {
  360. "name_chinese": league_name,
  361. "kind": "1",
  362. "match_mode": "1",
  363. "if_stop": "0",
  364. # "belong": "",
  365. "last_time": time3,
  366. "lg_id": league_id,
  367. "source": "hg3535"
  368. }
  369. }
  370. elif ball == "网球":
  371. payload = {
  372. "game_code": "zq",
  373. "title": "league",
  374. "data": {
  375. "name_chinese": league_name,
  376. "kind": "1",
  377. "match_mode": "1",
  378. "if_stop": "0",
  379. # "belong": "",
  380. "last_time": time3,
  381. "lg_id": league_id,
  382. "source": "hg3535"
  383. }
  384. }
  385. elif ball == "棒球":
  386. payload = {
  387. "game_code": "zq",
  388. "title": "league",
  389. "data": {
  390. "name_chinese": league_name,
  391. "kind": "1",
  392. "match_mode": "1",
  393. "if_stop": "0",
  394. # "belong": "",
  395. "last_time": time3,
  396. "lg_id": league_id,
  397. "source": "hg3535"
  398. }
  399. }
  400. return payload
  401. def liansai(area_name, name_chinese, st_league, area_dict, game_code, qiu):
  402. if area_name in area_dict:
  403. payload = {
  404. "game_code": game_code,
  405. "title": "league",
  406. "data": {
  407. "name_chinese": name_chinese,
  408. "kind": "1",
  409. "match_mode": "1",
  410. "if_stop": "0",
  411. "belong": area_name,
  412. "last_time": '2019-12-31 23:59:59',
  413. "lg_id": st_league,
  414. "source": "hg3535"
  415. }
  416. }
  417. else:
  418. if area_name == qiu:
  419. payload = {
  420. "game_code": game_code,
  421. "title": "league",
  422. "data": {
  423. "name_chinese": name_chinese,
  424. "kind": "1",
  425. "match_mode": "1",
  426. "if_stop": "0",
  427. "belong": " ",
  428. "last_time": '2019-12-31 23:59:59',
  429. "lg_id": st_league,
  430. "source": "hg3535"
  431. }
  432. }
  433. else:
  434. payload = {
  435. "game_code": game_code,
  436. "title": "league",
  437. "data": {
  438. "name_chinese": name_chinese,
  439. "kind": "1",
  440. "match_mode": "1",
  441. "if_stop": "0",
  442. "belong": area_name,
  443. "last_time": '2019-12-31 23:59:59',
  444. "lg_id": st_league,
  445. "source": "hg3535"
  446. }}
  447. return payload