ball_func.py 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  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=0, p_id=p_id)
  109. o_hash = r_func(match_id=match_id, odds_code=odds_code, sort=0, 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. f1 = fuhao(str(condition[key]))
  141. payload = {
  142. "game_code": game_code,
  143. "title": "odds",
  144. "data": {
  145. "match_id": match_id,
  146. "lg_id": league_id,
  147. "odds_code": key,
  148. "status": 0,
  149. "sort": 0,
  150. "p_code": p_code,
  151. "odds": value,
  152. "condition": f1,
  153. "odds_only": o_hash,
  154. "sole": s_hash,
  155. "source": "hg3535",
  156. "type": 0,
  157. "team": ""
  158. }
  159. }
  160. zq_odds.append(payload)
  161. # odd_list.append(payload)
  162. # return odd_list
  163. def gs_post(ball, league_id, league_name, data_game):
  164. if ball == "足球":
  165. n_gameid = int('1' + str(league_id))
  166. payload = {
  167. "game_code": "zq",
  168. "title": "competition",
  169. "data": {
  170. "home_team": league_name,
  171. "lg_id": league_id,
  172. "status": 0,
  173. "match_id": n_gameid,
  174. "source": "hg3535",
  175. "us_time": data_game
  176. }
  177. }
  178. elif ball == "篮球":
  179. n_gameid = int('1' + str(league_id))
  180. payload = {
  181. "game_code": "zq",
  182. "title": "competition",
  183. "data": {
  184. "home_team": league_name,
  185. "lg_id": league_id,
  186. "status": 0,
  187. "match_id": n_gameid,
  188. "source": "hg3535",
  189. "us_time": data_game
  190. }
  191. }
  192. elif ball == "网球":
  193. n_gameid = int('1' + str(league_id))
  194. payload = {
  195. "game_code": "zq",
  196. "title": "competition",
  197. "data": {
  198. "home_team": league_name,
  199. "lg_id": league_id,
  200. "status": 0,
  201. "match_id": n_gameid,
  202. "source": "hg3535",
  203. "us_time": data_game
  204. }
  205. }
  206. elif ball == "棒球":
  207. n_gameid = int('1' + str(league_id))
  208. payload = {
  209. "game_code": "zq",
  210. "title": "competition",
  211. "data": {
  212. "home_team": league_name,
  213. "lg_id": league_id,
  214. "status": 0,
  215. "match_id": n_gameid,
  216. "source": "hg3535",
  217. "us_time": data_game
  218. }
  219. }
  220. return payload
  221. def go_post(ball, league_id, new_champion, new_league_name, value, r_hash, new_hash, tema_home):
  222. game_id = int('1' + str(league_id))
  223. if ball == "足球":
  224. payload = {
  225. "game_code": "zq",
  226. "title": "odds",
  227. "data": {
  228. "match_id": league_id,
  229. "lg_id": game_id,
  230. "odds_code": new_champion,
  231. "status": 0,
  232. "sort": 0,
  233. "p_code": new_league_name,
  234. "odds": value,
  235. "condition": None,
  236. "odds_only": r_hash,
  237. "sole": new_hash,
  238. "source": 'hg3535',
  239. "type": 1,
  240. "team": tema_home
  241. }
  242. }
  243. elif ball == "篮球":
  244. payload = {
  245. "game_code": "lq",
  246. "title": "odds",
  247. "data": {
  248. "match_id": league_id,
  249. "lg_id": game_id,
  250. "odds_code": new_champion,
  251. "status": 0,
  252. "sort": 0,
  253. "p_code": new_league_name,
  254. "odds": value,
  255. "condition": None,
  256. "odds_only": r_hash,
  257. "sole": new_hash,
  258. "source": "hg3535",
  259. "type": 1,
  260. "team": tema_home
  261. }
  262. }
  263. elif ball == "网球":
  264. payload = {
  265. "game_code": "wq",
  266. "title": "odds",
  267. "data": {
  268. "match_id": league_id,
  269. "lg_id": game_id,
  270. "odds_code": new_champion,
  271. "status": 0,
  272. "sort": 0,
  273. "p_code": new_league_name,
  274. "odds": value,
  275. "condition": None,
  276. "odds_only": r_hash,
  277. "sole": new_hash,
  278. "source": "hg3535",
  279. "type": 1,
  280. "team": tema_home
  281. }
  282. }
  283. elif ball == "棒球":
  284. payload = {
  285. "game_code": "bq",
  286. "title": "odds",
  287. "data": {
  288. "match_id": league_id,
  289. "lg_id": game_id,
  290. "odds_code": new_champion,
  291. "status": 0,
  292. "sort": 0,
  293. "p_code": new_league_name,
  294. "odds": value,
  295. "condition": None,
  296. "odds_only": r_hash,
  297. "sole": new_hash,
  298. "source": "hg3535",
  299. "type": 1,
  300. "team": tema_home
  301. }
  302. }
  303. return payload
  304. def guanl_post(ball, league_name, league_id, time3):
  305. if ball == "足球":
  306. payload = {
  307. "game_code": "zq",
  308. "title": "league",
  309. "data": {
  310. "name_chinese": league_name,
  311. "kind": "1",
  312. "match_mode": "1",
  313. "if_stop": "0",
  314. # "belong": None,
  315. "last_time": time3,
  316. "lg_id": league_id,
  317. "source": "hg3535"
  318. }
  319. }
  320. elif ball == "篮球":
  321. payload = {
  322. "game_code": "zq",
  323. "title": "league",
  324. "data": {
  325. "name_chinese": league_name,
  326. "kind": "1",
  327. "match_mode": "1",
  328. "if_stop": "0",
  329. # "belong": None,
  330. "last_time": time3,
  331. "lg_id": league_id,
  332. "source": "hg3535"
  333. }
  334. }
  335. elif ball == "网球":
  336. payload = {
  337. "game_code": "zq",
  338. "title": "league",
  339. "data": {
  340. "name_chinese": league_name,
  341. "kind": "1",
  342. "match_mode": "1",
  343. "if_stop": "0",
  344. # "belong": None,
  345. "last_time": time3,
  346. "lg_id": league_id,
  347. "source": "hg3535"
  348. }
  349. }
  350. elif ball == "棒球":
  351. payload = {
  352. "game_code": "zq",
  353. "title": "league",
  354. "data": {
  355. "name_chinese": league_name,
  356. "kind": "1",
  357. "match_mode": "1",
  358. "if_stop": "0",
  359. # "belong": None,
  360. "last_time": time3,
  361. "lg_id": league_id,
  362. "source": "hg3535"
  363. }
  364. }
  365. return payload
  366. def liansai(area_name, name_chinese, st_league, area_dict, game_code, qiu):
  367. if area_name in area_dict:
  368. payload = {
  369. "game_code": game_code,
  370. "title": "league",
  371. "data": {
  372. "name_chinese": name_chinese,
  373. "kind": "1",
  374. "match_mode": "1",
  375. "if_stop": "0",
  376. "belong": area_name,
  377. "last_time": None,
  378. "lg_id": st_league,
  379. "source": "hg3535"
  380. }
  381. }
  382. else:
  383. if area_name == qiu:
  384. payload = {
  385. "game_code": game_code,
  386. "title": "league",
  387. "data": {
  388. "name_chinese": name_chinese,
  389. "kind": "1",
  390. "match_mode": "1",
  391. "if_stop": "0",
  392. "belong": " ",
  393. "last_time": None,
  394. "lg_id": st_league,
  395. "source": "hg3535"
  396. }
  397. }
  398. else:
  399. payload = {
  400. "game_code": game_code,
  401. "title": "league",
  402. "data": {
  403. "name_chinese": name_chinese,
  404. "kind": "1",
  405. "match_mode": "1",
  406. "if_stop": "0",
  407. "belong": area_name,
  408. "last_time": None,
  409. "lg_id": st_league,
  410. "source": "hg3535"
  411. }}
  412. return payload