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