roll_zuqiu.py 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. # import datetime
  2. import pymongo
  3. import time
  4. import logging
  5. from ball_func import fuhao
  6. from ..utils.helper import Helper
  7. from .ball_func import get_pcode
  8. # 滚球足球 插入
  9. class Roll_Zuqiupipeline(object):
  10. def open_spider(self, spider):
  11. self.mongo = pymongo.MongoClient(host="192.168.2.200", username="kaiyou", password="kaiyou", port=27017)
  12. self.db = self.mongo['kaiyou']
  13. def process_item(self, item, spider):
  14. logger = logging.getLogger(__name__)
  15. url = 'http://admin.5gogo.com'
  16. pt = 4
  17. roll_zq = []
  18. # 比赛日期
  19. try:
  20. data_game = item['data_game'].split("/")
  21. month = str(data_game[1].strip())
  22. day = str(data_game[0])
  23. except Exception as e:
  24. logger.warning(e)
  25. data_game = item['data_game'].split(" ")
  26. months = str(data_game[1].strip())
  27. month_dict = {'Jan': '01', 'Feb': '02', 'Mar': '03', 'Apr': '04', 'May': '05', 'Jun': '06', 'Jul': '07', 'Aug': '08', 'Sep': '09', 'Oct': '10', 'Nov': '11', 'Dec': '12'}
  28. month = month_dict[months]
  29. day = str(data_game[0])
  30. # 比赛时间
  31. time_game = str(item['time_game'])
  32. # print(time_game)
  33. # 比赛时间,时间戳
  34. ctime = "2019" + "-" + month + "-" + day + "" + time_game + ":00"
  35. r_ctime = "2019" + "-" + month + "-" + day
  36. # 现在时间,时间戳
  37. utime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
  38. expire_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time() + 60))
  39. # 比赛id
  40. match_id = item['game_id']
  41. # 联赛id
  42. league_id = item['league_id']
  43. # 联赛name
  44. league_name = item['league_name']
  45. # 主队
  46. team_home = item['team_home']
  47. # 客队
  48. team_guest = item['team_guest']
  49. # number
  50. number = item['number']
  51. score_home = item['score_home']
  52. score_guest = item['score_guest']
  53. all_goal = int(score_home) + int(score_guest)
  54. half_way = item['half_way']
  55. # pt = item['pt']
  56. match_score = "{}:{}".format(score_home,score_guest)
  57. corner_ball = item['corner_ball']
  58. last_time = '2019-12-31 23:59:59'
  59. league_dict = {"game_code": "zq", "title": "league", "source": "hg3535"}
  60. league_list = []
  61. uuid = Helper.genearte_MD5(league_name + 'hg3535')
  62. league_key = ["name_chinese", "kind", "match_mode", "if_stop", "last_time", "lg_id", "source", "uuid"]
  63. league_value = [league_name, "1", "1", "0", last_time, league_id, "hg3535", uuid]
  64. league_data = dict(zip(league_key, league_value))
  65. league_list.append(league_data)
  66. league_dict['data'] = league_list
  67. if self.db.hg3535_zq_league.find({'league_id': league_id}).count() < 1:
  68. response_data = Helper.async_post(url + '/setLeague', league_dict)
  69. print('足球联赛请求成功', response_data)
  70. if "成功" in response_data:
  71. self.db.hg3535_zq_league.insert(league_list)
  72. competition = self.db.hg3535_zq_competition.find_one({"match_id": match_id})
  73. match_list = []
  74. if competition:
  75. print('赛事已存在,修改赛事四状态')
  76. is_morningplate = competition['is_morningplate']
  77. is_rollball = competition['is_rollball']
  78. is_stringscene = competition['is_stringscene']
  79. is_today = competition['is_today']
  80. status = competition['status']
  81. match_date = competition['match_date']
  82. match_time = competition['match_time']
  83. us_time = competition['us_time']
  84. # if pt == '3':
  85. if is_rollball != 1 or status != 1:
  86. match_dict = {"game_code": "zq", "title": "match", "source": "hg3535"}
  87. match_kay = ["home_team", "guest_team", "lg_id", "status", "match_id", "match_date", "match_time",
  88. "tag", "source", "is_rollball", "is_morningplate", "is_stringscene", "us_time", "uuid",
  89. "half_match_id", "is_today"]
  90. match_value = [team_home, team_guest, league_id, 1, match_id, match_date, match_time, number,
  91. "hg3535", 1, is_morningplate, is_stringscene, us_time, uuid, 0, is_today]
  92. match_data = dict(zip(match_kay, match_value))
  93. match_list.append(match_data)
  94. match_dict['data'] = match_list
  95. print(match_dict)
  96. response_data = Helper.async_post(url + '/setMatch', match_dict)
  97. print('足球赛事请求成功', response_data)
  98. if "成功" in response_data:
  99. self.db.hg3535_zq_competition.update({'match_id': match_id}, {"$set": {"is_rollball": 1, "status": 1}},
  100. upsert=True)
  101. else:
  102. print("赛事已存在,赛事状态时间为改变,不做修改")
  103. else:
  104. is_rollball = 1
  105. is_today = 0
  106. is_morningplate = 0
  107. is_stringscene = 0
  108. # 赛事接口写入
  109. match_dict = {"game_code": "zq", "title": "match", "source": "hg3535"}
  110. match_kay = ["home_team", "guest_team", "lg_id", "status", "match_id", "match_date", "match_time", "tag",
  111. "source", "is_rollball", "is_morningplate", "is_stringscene", "us_time", "uuid",
  112. "half_match_id", "is_today"]
  113. match_value = [team_home, team_guest, league_id, 1, match_id, r_ctime, "00:00", number, "hg3535",
  114. is_rollball, is_morningplate, is_stringscene, utime, uuid, 0, is_today]
  115. match_data = dict(zip(match_kay, match_value))
  116. match_list.append(match_data)
  117. match_dict['data'] = match_list
  118. response_data = Helper.async_post(url + '/setMatch', match_dict)
  119. print(match_dict)
  120. print('足球赛事请求成功', response_data)
  121. if "成功" in response_data:
  122. self.db.hg3535_zq_competition.insert(match_list)
  123. # print(response_data)
  124. # 赔率
  125. try:
  126. result = self.db.hg3535_zq_odds.find_one({'match_id': match_id, 'pt': pt})
  127. uuid_list = result['odds_only']
  128. except:
  129. uuid_list = []
  130. result = ''
  131. p_code, p_id = get_pcode(corner_ball, 'goal_size')
  132. # 构建唯一索引
  133. half_size_guest = item["half_size_guest"]
  134. half_size_guest_rule = item["half_size_guest_rule"]
  135. half_size_home = item["half_size_home"]
  136. half_size_home_rule = item["half_size_home_rule"]
  137. # zuqiu = item['zuqiu']
  138. data_list = []
  139. odds_onlys = []
  140. # half_size_guest
  141. for index, value in enumerate(half_size_guest):
  142. hash_str = p_code + "half_size_guest" + str(index) + str(half_size_guest_rule[index]) + str(
  143. value) + "hg3535" + str(match_id)
  144. sole_str = p_code + "half_size_guest" + str(index) + str(match_id) + "hg3535"
  145. odds_only = Helper.genearte_MD5(hash_str)
  146. sole = Helper.genearte_MD5(sole_str)
  147. odds_onlys.append(odds_only)
  148. half_size_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  149. "odds_only", "sole", "source", "type", "team"]
  150. condition = fuhao(half_size_guest_rule[index])
  151. half_size_guest_value = [match_id, league_id, "half_size_guest", "0", index, p_code, value, condition,
  152. odds_only, sole, "hg3535", "0", ""]
  153. half_size_guest_data = dict(zip(half_size_guest_key, half_size_guest_value))
  154. if odds_only not in uuid_list:
  155. data_list.append(half_size_guest_data)
  156. # half_size_home
  157. for index, value in enumerate(half_size_home):
  158. hash_str = p_code + "half_size_home" + str(index) + str(half_size_home_rule[index]) + str(
  159. value) + "hg3535" + str(match_id)
  160. sole_str = p_code + "half_size_home" + str(index) + str(match_id) + "hg3535"
  161. odds_only = Helper.genearte_MD5(hash_str)
  162. sole = Helper.genearte_MD5(sole_str)
  163. odds_onlys.append(odds_only)
  164. half_size_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  165. "odds_only", "sole", "source", "type", "team"]
  166. condition = fuhao(half_size_home_rule[index])
  167. half_size_home_value = [match_id, league_id, "half_size_guest", "0", index, p_code, value, condition,
  168. odds_only, sole, "hg3535", "0", ""]
  169. half_size_home_data = dict(zip(half_size_home_key, half_size_home_value))
  170. if odds_only not in uuid_list:
  171. data_list.append(half_size_home_data)
  172. # 全场场大小
  173. size_guest = item["size_guest"]
  174. size_guest_rule = item["size_guest_rule"]
  175. size_home = item["size_home"]
  176. size_home_rule = item["size_home_rule"]
  177. # size_home
  178. for index, value in enumerate(size_home):
  179. hash_str = p_code + "size_home" + str(index) + str(size_home_rule[index]) + str(value) + "hg3535" + str(
  180. match_id)
  181. sole_str = p_code + "size_home" + str(index) + str(match_id) + "hg3535"
  182. odds_only = Helper.genearte_MD5(hash_str)
  183. sole = Helper.genearte_MD5(sole_str)
  184. odds_onlys.append(odds_only)
  185. size_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  186. "odds_only", "sole", "source", "type", "team"]
  187. condition = fuhao(size_home_rule[index])
  188. size_home_value = [match_id, league_id, "size_home", "0", index, p_code, value, condition, odds_only,
  189. sole, "hg3535", "0", ""]
  190. size_home_data = dict(zip(size_home_key, size_home_value))
  191. if odds_only not in uuid_list:
  192. data_list.append(size_home_data)
  193. # size_guest
  194. for index, value in enumerate(size_guest):
  195. hash_str = p_code + "size_guest" + str(index) + str(size_guest_rule[index]) + str(value) + "hg3535" + str(
  196. match_id)
  197. sole_str = p_code + "size_guest" + str(index) + str(match_id) + "hg3535"
  198. odds_only = Helper.genearte_MD5(hash_str)
  199. sole = Helper.genearte_MD5(sole_str)
  200. odds_onlys.append(odds_only)
  201. size_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  202. "odds_only", "sole", "source", "type", "team"]
  203. condition = fuhao(size_guest_rule[index])
  204. size_guest_value = [match_id, league_id, "size_guest", "0", index, p_code, value, condition, odds_only,
  205. sole, "hg3535", "0", ""]
  206. size_home_data = dict(zip(size_guest_key, size_guest_value))
  207. if odds_only not in uuid_list:
  208. data_list.append(size_home_data)
  209. p_code, p_id = get_pcode(corner_ball, 'concede')
  210. half_concede_home_rule = item["half_concede_home_rule"]
  211. half_concede_home = item["half_concede_home"]
  212. half_concede_guest_rule = item["half_concede_guest_rule"]
  213. half_concede_guest = item["half_concede_guest"]
  214. # half_concede_home
  215. for index, value in enumerate(half_concede_guest):
  216. hash_str = p_code + "half_concede_guest" + str(index) + str(half_concede_guest_rule[index]) + str(
  217. value) + "hg3535" + str(match_id)
  218. sole_str = p_code + "half_concede_guest" + str(index) + str(match_id) + "hg3535"
  219. odds_only = Helper.genearte_MD5(hash_str)
  220. sole = Helper.genearte_MD5(sole_str)
  221. odds_onlys.append(odds_only)
  222. half_concede_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  223. "odds_only", "sole", "source", "type", "team"]
  224. condition = fuhao(half_concede_guest_rule[index])
  225. half_concede_guest_value = [match_id, league_id, "half_concede_guest", "0", index, p_code, value, condition,
  226. odds_only, sole, "hg3535", "0", ""]
  227. half_concede_guest_data = dict(zip(half_concede_guest_key, half_concede_guest_value))
  228. if odds_only not in uuid_list:
  229. data_list.append(half_concede_guest_data)
  230. # half_concede_home
  231. for index, value in enumerate(half_concede_home):
  232. hash_str = p_code + "half_concede_home" + str(index) + str(half_concede_home_rule[index]) + str(
  233. value) + "hg3535" + str(match_id)
  234. sole_str = p_code + "half_concede_home" + str(index) + str(match_id) + "hg3535"
  235. odds_only = Helper.genearte_MD5(hash_str)
  236. sole = Helper.genearte_MD5(sole_str)
  237. odds_onlys.append(odds_only)
  238. half_concede_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  239. "odds_only", "sole", "source", "type", "team"]
  240. condition = fuhao(half_concede_home_rule[index])
  241. half_concede_home_value = [match_id, league_id, "half_concede_home", "0", index, p_code, value, condition,
  242. odds_only, sole, "hg3535", "0", ""]
  243. half_concede_home_data = dict(zip(half_concede_home_key, half_concede_home_value))
  244. if odds_only not in uuid_list:
  245. data_list.append(half_concede_home_data)
  246. concede_guest = item["concede_guest"]
  247. concede_guest_rule = item["concede_guest_rule"]
  248. concede_home = item["concede_home"]
  249. concede_home_rule = item["concede_home_rule"]
  250. # concede_guest
  251. for index, value in enumerate(concede_guest):
  252. hash_str = p_code + "concede_guest" + str(index) + str(concede_guest_rule[index]) + str(
  253. value) + "hg3535" + str(match_id)
  254. sole_str = p_code + "concede_guest" + str(index) + str(match_id) + "hg3535"
  255. odds_only = Helper.genearte_MD5(hash_str)
  256. sole = Helper.genearte_MD5(sole_str)
  257. odds_onlys.append(odds_only)
  258. concede_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  259. "odds_only", "sole", "source", "type", "team"]
  260. condition = fuhao(concede_guest[index])
  261. concede_guest_value = [match_id, league_id, "concede_guest", "0", index, p_code, value, condition,
  262. odds_only, sole, "hg3535", "0", ""]
  263. concede_guest_data = dict(zip(concede_guest_key, concede_guest_value))
  264. if odds_only not in uuid_list:
  265. data_list.append(concede_guest_data)
  266. # concede_home
  267. for index, value in enumerate(concede_home):
  268. hash_str = p_code + "concede_home" + str(index) + str(concede_home_rule[index]) + str(
  269. value) + "hg3535" + str(match_id)
  270. sole_str = p_code + "concede_home" + str(index) + str(match_id) + "hg3535"
  271. odds_only = Helper.genearte_MD5(hash_str)
  272. sole = Helper.genearte_MD5(sole_str)
  273. odds_onlys.append(odds_only)
  274. concede_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  275. "odds_only", "sole", "source", "type", "team"]
  276. condition = fuhao(concede_home_rule[index])
  277. concede_home_value = [match_id, league_id, "concede_home", "0", index, p_code, value, condition, odds_only,
  278. sole, "hg3535", "0", ""]
  279. concede_guest_data = dict(zip(concede_home_key, concede_home_value))
  280. if odds_only not in uuid_list:
  281. data_list.append(concede_guest_data)
  282. # 独赢----------------------------------------------------------------------------------------------------------
  283. p_code, p_id = get_pcode(corner_ball, 'capot')
  284. half_capot_home = item["half_capot_home"]
  285. half_capot_guest = item["half_capot_guest"]
  286. half_capot_dogfall = item["half_capot_dogfall"]
  287. capot_home = item["capot_home"]
  288. capot_guest = item["capot_guest"]
  289. capot_dogfall = item["capot_dogfall"]
  290. # half_capot_home
  291. hash_str = p_code + "half_capot_home" + '0' + '1' + str(half_capot_home) + "hg3535" + str(match_id)
  292. sole_str = p_code + "half_capot_home" + '0' + str(match_id) + "hg3535"
  293. odds_only = Helper.genearte_MD5(hash_str)
  294. sole = Helper.genearte_MD5(sole_str)
  295. odds_onlys.append(odds_only)
  296. half_capot_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  297. "odds_only", "sole", "source", "type", "team"]
  298. half_capot_home_value = [match_id, league_id, "half_capot_home", "0", 0, p_code, half_capot_home, '1',
  299. odds_only, sole, "hg3535", "0", ""]
  300. half_capot_homet_data = dict(zip(half_capot_home_key, half_capot_home_value))
  301. if odds_only not in uuid_list:
  302. data_list.append(half_capot_homet_data)
  303. # half_capot_guest
  304. hash_str = p_code + "half_capot_guest" + '0' + '2' + str(half_capot_guest) + "hg3535" + str(match_id)
  305. sole_str = p_code + "half_capot_guest" + '0' + str(match_id) + "hg3535"
  306. odds_only = Helper.genearte_MD5(hash_str)
  307. sole = Helper.genearte_MD5(sole_str)
  308. odds_onlys.append(odds_only)
  309. half_capot_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  310. "odds_only", "sole", "source", "type", "team"]
  311. half_capot_guest_value = [match_id, league_id, "half_capot_guest", "0", 0, p_code, half_capot_guest, '2',
  312. odds_only, sole, "hg3535", "0", ""]
  313. half_capot_guest_data = dict(zip(half_capot_guest_key, half_capot_guest_value))
  314. if odds_only not in uuid_list:
  315. data_list.append(half_capot_guest_data)
  316. # half_capot_dogfall
  317. hash_str = p_code + "half_capot_dogfall" + '0' + 'X' + str(half_capot_dogfall) + "hg3535" + str(match_id)
  318. sole_str = p_code + "half_capot_dogfall" + '0' + str(match_id) + "hg3535"
  319. odds_only = Helper.genearte_MD5(hash_str)
  320. sole = Helper.genearte_MD5(sole_str)
  321. odds_onlys.append(odds_only)
  322. half_capot_dogfall_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  323. "odds_only", "sole", "source", "type", "team"]
  324. half_capot_dogfall_value = [match_id, league_id, "half_capot_guest", "0", 0, p_code, half_capot_dogfall, 'X',
  325. odds_only, sole, "hg3535", "0", ""]
  326. half_capot_dogfall_data = dict(zip(half_capot_dogfall_key, half_capot_dogfall_value))
  327. if odds_only not in uuid_list:
  328. data_list.append(half_capot_dogfall_data)
  329. # capot_dogfall
  330. hash_str = p_code + "capot_dogfall" + '0' + 'X' + str(capot_dogfall) + "hg3535" + str(match_id)
  331. sole_str = p_code + "capot_dogfall" + '0' + str(match_id) + "hg3535"
  332. odds_only = Helper.genearte_MD5(hash_str)
  333. sole = Helper.genearte_MD5(sole_str)
  334. odds_onlys.append(odds_only)
  335. capot_dogfall_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  336. "odds_only", "sole", "source", "type", "team"]
  337. capot_dogfall_value = [match_id, league_id, "half_capot_guest", "0", 0, p_code, capot_dogfall, 'X', odds_only,
  338. sole, "hg3535", "0", ""]
  339. capot_dogfall_data = dict(zip(capot_dogfall_key, capot_dogfall_value))
  340. if odds_only not in uuid_list:
  341. data_list.append(capot_dogfall_data)
  342. # capot_home
  343. hash_str = p_code + "capot_home" + '0' + '1' + str(capot_home) + "hg3535" + str(match_id)
  344. sole_str = p_code + "capot_home" + '0' + str(match_id) + "hg3535"
  345. odds_only = Helper.genearte_MD5(hash_str)
  346. sole = Helper.genearte_MD5(sole_str)
  347. odds_onlys.append(odds_only)
  348. capot_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  349. "odds_only", "sole", "source", "type", "team"]
  350. capot_home_value = [match_id, league_id, "half_capot_home", "0", 0, p_code, capot_home, '1',
  351. odds_only, sole, "hg3535", "0", ""]
  352. capot_homet_data = dict(zip(capot_home_key, capot_home_value))
  353. if odds_only not in uuid_list:
  354. data_list.append(capot_homet_data)
  355. # capot_guest
  356. hash_str = p_code + "capot_guest" + '0' + '2' + str(capot_guest) + "hg3535" + str(match_id)
  357. sole_str = p_code + "capot_guest" + '0' + str(match_id) + "hg3535"
  358. odds_only = Helper.genearte_MD5(hash_str)
  359. sole = Helper.genearte_MD5(sole_str)
  360. odds_onlys.append(odds_only)
  361. capot_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  362. "odds_only", "sole", "source", "type", "team"]
  363. capot_guest_value = [match_id, league_id, "half_capot_guest", "0", 0, p_code, capot_home, '2',
  364. odds_only, sole, "hg3535", "0", ""]
  365. capot_guest_data = dict(zip(capot_guest_key, capot_guest_value))
  366. if odds_only not in uuid_list:
  367. data_list.append(capot_guest_data)
  368. # 入球数单双-----------------------------------------------------------------------------------------------------
  369. p_code, p_id = get_pcode(corner_ball, 'two_sides')
  370. odd_even_odd = item["odd_even_odd"]
  371. odd_even_even = item["odd_even_even"]
  372. half_odd_even_odd = item["half_odd_even_odd"]
  373. half_odd_even_even = item["half_odd_even_even"]
  374. # odd_even_odd
  375. hash_str = p_code + "two_sides_single" + '0' + '单' + str(odd_even_odd) + "hg3535" + str(match_id)
  376. sole_str = p_code + "two_sides_single" + '0' + str(match_id) + "hg3535"
  377. odds_only = Helper.genearte_MD5(hash_str)
  378. sole = Helper.genearte_MD5(sole_str)
  379. odds_onlys.append(odds_only)
  380. single_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  381. "odds_only", "sole", "source", "type", "team"]
  382. single_value = [match_id, league_id, "two_sides_single", "0", 0, p_code, odd_even_odd, '单',
  383. odds_only, sole, "hg3535", "0", ""]
  384. single_data = dict(zip(single_key, single_value))
  385. if odds_only not in uuid_list:
  386. data_list.append(single_data)
  387. # odd_even_even
  388. hash_str = p_code + "two_sides_double" + '0' + '双' + str(odd_even_even) + "hg3535" + str(match_id)
  389. sole_str = p_code + "two_sides_double" + '0' + str(match_id) + "hg3535"
  390. odds_only = Helper.genearte_MD5(hash_str)
  391. sole = Helper.genearte_MD5(sole_str)
  392. odds_onlys.append(odds_only)
  393. double_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  394. "odds_only", "sole", "source", "type", "team"]
  395. double_value = [match_id, league_id, "two_sides_double", "0", 0, p_code, odd_even_even, '双',
  396. odds_only, sole, "hg3535", "0", ""]
  397. double_data = dict(zip(double_key, double_value))
  398. if odds_only not in uuid_list:
  399. data_list.append(double_data)
  400. # half_odd_even_even
  401. hash_str = p_code + "two_sides_double" + '0' + '双' + str(half_odd_even_even) + "hg3535" + str(match_id)
  402. sole_str = p_code + "two_sides_double" + '0' + str(match_id) + "hg3535"
  403. odds_only = Helper.genearte_MD5(hash_str)
  404. sole = Helper.genearte_MD5(sole_str)
  405. odds_onlys.append(odds_only)
  406. half_double_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  407. "odds_only", "sole", "source", "type", "team"]
  408. half_double_value = [match_id, league_id, "two_sides_double", "0", 0, p_code, half_odd_even_even, '双',
  409. odds_only, sole, "hg3535", "0", ""]
  410. half_double_data = dict(zip(half_double_key, half_double_value))
  411. if odds_only not in uuid_list:
  412. data_list.append(half_double_data)
  413. # half_odd_even_odd
  414. hash_str = p_code + "two_sides_single" + '0' + '单' + str(half_odd_even_odd) + "hg3535" + str(match_id)
  415. sole_str = p_code + "two_sides_single" + '0' + str(match_id) + "hg3535"
  416. odds_only = Helper.genearte_MD5(hash_str)
  417. sole = Helper.genearte_MD5(sole_str)
  418. odds_onlys.append(odds_only)
  419. half_single_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  420. "odds_only", "sole", "source", "type", "team"]
  421. half_single_value = [match_id, league_id, "two_sides_single", "0", 0, p_code, half_odd_even_odd, '单', odds_only,
  422. sole, "hg3535", "0", ""]
  423. half_single_data = dict(zip(half_single_key, half_single_value))
  424. if odds_only not in uuid_list:
  425. data_list.append(half_single_data)
  426. # 总入球数 ------------------------------------------------------------------------------------------------------
  427. p_code, p_id = get_pcode(corner_ball, 'total_goal')
  428. total_goals = item['total_goal']
  429. total_dict = {'total_goal_zero': '0-1', 'total_goal_two': '2-3', 'total_goal_four': '4-6',
  430. 'total_goal_seven': '7或以上', 'half_total_goal_zero': '0', "half_total_goal_one": '1',
  431. "half_total_goal_two": '2', "half_total_goal_three": '3或以上'}
  432. # 全场入球数 单双
  433. # 上半场入球数 单双
  434. for key, value in total_goals.items():
  435. hash_str = p_code + key + '0' + total_dict[key] + str(value) + "hg3535" + str(match_id)
  436. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  437. odds_only = Helper.genearte_MD5(hash_str)
  438. sole = Helper.genearte_MD5(sole_str)
  439. odds_onlys.append(odds_only)
  440. total_goals_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  441. "odds_only", "sole", "source", "type", "team"]
  442. total_goals_value = [match_id, league_id, key, "0", 0, p_code, value, total_dict[key], odds_only,
  443. sole, "hg3535", "0", ""]
  444. total_goals_data = dict(zip(total_goals_key, total_goals_value))
  445. if odds_only not in uuid_list:
  446. data_list.append(total_goals_data)
  447. # 全场半场 ------------------------------------------------------------------------------------------------------
  448. half_fulls = item['half_full']
  449. p_code, p_id = get_pcode(corner_ball, 'half_full')
  450. full_dict = {"half_full_home_home": "主主", "half_full_home_dogfall": "主和",
  451. "half_full_home_guest": "主客", "half_full_dogfall_home": "和主",
  452. "half_full_dogfall_dogfall": "和和", "half_full_dogfall_guest": "和客",
  453. "half_full_guest_home": "客主", "half_full_guest_dogfall": "客和",
  454. "half_full_guest_guest": "客客"}
  455. if half_fulls:
  456. for key, value in half_fulls.items():
  457. hash_str = p_code + key + '0' + full_dict[key] + str(value) + "hg3535" + str(match_id)
  458. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  459. odds_only = Helper.genearte_MD5(hash_str)
  460. sole = Helper.genearte_MD5(sole_str)
  461. odds_onlys.append(odds_only)
  462. half_fulls_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  463. "odds_only", "sole", "source", "type", "team"]
  464. half_fulls_value = [match_id, league_id, key, "0", 0, p_code, value, full_dict[key], odds_only,
  465. sole, "hg3535", "0", ""]
  466. half_fulls_data = dict(zip(half_fulls_key, half_fulls_value))
  467. if odds_only not in uuid_list:
  468. data_list.append(half_fulls_data)
  469. # 波胆------------------------------------------------------------------------------------------------------------------
  470. bodan_datas = item['bodan_data']
  471. p_code, p_id = get_pcode(corner_ball, 'bodan')
  472. bodan_dict = {"bodanhome_one_zero": "1-0", "bodanhome_two_zero": "2-0",
  473. "bodanhome_two_one": "2-1", "bodanhome_three_zero": "3-0",
  474. "bodanhome_three_one": "3-1", "bodanhome_three_two": "3-2",
  475. "bodanhome_four_zero": "4-0", "bodanhome_four_one": "4-1",
  476. "bodanhome_four_two": "4-2", "bodanhome_four_three": "4-3",
  477. "bodanguest_one_zero": "0-1", "bodanguest_two_zero": "0-2",
  478. "bodanguest_two_one": "1-2", "bodanguest_three_zero": "0-3",
  479. "bodanguest_three_one": "1-3", "bodanguest_three_two": "2-3",
  480. "bodanguest_four_zero": "0-4", "bodanguest_four_one": "1-4",
  481. "bodanguest_four_two": "2-4", "bodanguest_four_three": "3-4",
  482. "bodandogfall_zero_zero": "0-0", "bodandogfall_one_one": "1-1",
  483. "bodandogfall_two_two": "2-2", "bodandogfall_three_three": "3-3",
  484. "bodandogfall_four_four": "4-4", "bodanother": "其他",
  485. "halfbodanhome_one_zero": "1-0", "halfbodanhome_two_zero": "2-0",
  486. "halfbodanhome_two_one": "2-1", "halfbodanhome_three_zero": "3-0",
  487. "halfbodanhome_three_one": "3-1", "halfbodanhome_three_two": "3-2",
  488. "halfbodanguest_one_zero": "0-1", "halfbodanguest_two_zero": "0-2",
  489. "halfbodanguest_two_one": "1-2", "halfbodanguest_three_zero": "0-3",
  490. "halfbodanguest_three_one": "1-3", "halfbodanguest_three_two": "2-3",
  491. "halfbodandogfall_zero_zero": "0-0", "halfbodandogfall_one_one": "1-1",
  492. "halfbodandogfall_two_two": "2-2", "halfbodandogfall_three_three": "3-3",
  493. "halfbodanother": "其他"}
  494. if bodan_datas:
  495. for key, value in bodan_datas.items():
  496. hash_str = p_code + key + '0' + bodan_dict[key] + str(value) + "hg3535" + str(match_id)
  497. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  498. odds_only = Helper.genearte_MD5(hash_str)
  499. sole = Helper.genearte_MD5(sole_str)
  500. odds_onlys.append(odds_only)
  501. bodan_dict_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  502. "odds_only", "sole", "source", "type", "team"]
  503. bodan_dict_value = [match_id, league_id, key, "0", 0, p_code, value, bodan_dict[key], odds_only,
  504. sole, "hg3535", "0", ""]
  505. bodan_dict_data = dict(zip(bodan_dict_key, bodan_dict_value))
  506. if odds_only not in uuid_list:
  507. data_list.append(bodan_dict_data)
  508. # 最先进球/最后进球 ----------------------------------------------------------------------------------------------
  509. first_last_balls = item['first_last_ball']
  510. p_code, p_id = get_pcode(corner_ball, 'first_last_ball')
  511. first_last_dict = {"first_last_ball": "最先进球", "first_ball_home": "最先进球", "first_ball_guest": "最先进球",
  512. "last_ball_home": "最后进球", "last_ball_guest": "最后进球", "not_ball": "没有进球"}
  513. if first_last_balls:
  514. for key, value in first_last_balls.items():
  515. hash_str = p_code + key + '0' + first_last_dict[key] + str(value) + "hg3535" + str(match_id)
  516. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  517. odds_only = Helper.genearte_MD5(hash_str)
  518. sole = Helper.genearte_MD5(sole_str)
  519. odds_onlys.append(odds_only)
  520. first_last_balls_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  521. "condition",
  522. "odds_only", "sole", "source", "type", "team"]
  523. first_last_balls_value = [match_id, league_id, key, "0", 0, p_code, value, first_last_dict[key],
  524. odds_only,
  525. sole, "hg3535", "0", ""]
  526. first_last_balls_data = dict(zip(first_last_balls_key, first_last_balls_value))
  527. if odds_only not in uuid_list:
  528. data_list.append(first_last_balls_data)
  529. p_code, p_id = get_pcode(corner_ball, 'tema_ball')
  530. full_dicts = item['full_data']
  531. half_dicts = item['half_data']
  532. full_dict_rules = item['full_data_rule']
  533. half_dict_rules = item['half_data_rule']
  534. if full_dicts:
  535. for key, value in full_dicts.items():
  536. hash_str = p_code + key + '0' + full_dict_rules[key] + str(value) + "hg3535" + str(match_id)
  537. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  538. odds_only = Helper.genearte_MD5(hash_str)
  539. sole = Helper.genearte_MD5(sole_str)
  540. odds_onlys.append(odds_only)
  541. full_dict_rules_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  542. "condition", "odds_only", "sole", "source", "type", "team"]
  543. full_dict_rules_value = [match_id, league_id, key, "0", 0, p_code, value, full_dict_rules[key],
  544. odds_only, sole, "hg3535", "0", ""]
  545. full_dict_rules_data = dict(zip(full_dict_rules_key, full_dict_rules_value))
  546. if odds_only not in uuid_list:
  547. data_list.append(full_dict_rules_data)
  548. if half_dicts:
  549. for key, value in half_dicts.items():
  550. hash_str = p_code + key + '0' + half_dict_rules[key] + str(value) + "hg3535" + str(match_id)
  551. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  552. odds_only = Helper.genearte_MD5(hash_str)
  553. sole = Helper.genearte_MD5(sole_str)
  554. odds_onlys.append(odds_only)
  555. half_dicts_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  556. "condition", "odds_only", "sole", "source", "type", "team"]
  557. half_dicts_value = [match_id, league_id, key, "0", 0, p_code, value, half_dict_rules[key],
  558. odds_only, sole, "hg3535", "0", ""]
  559. half_dicts_data = dict(zip(half_dicts_key, half_dicts_value))
  560. if odds_only not in uuid_list:
  561. data_list.append(half_dicts_data)
  562. odds_key = ["game_code", "title", "match_id", "lg_id", "data", "source", "odds_only", "tag", "uuid",
  563. "is_stringscene", "utime", "pt"]
  564. odds_value = ["zq", "odds", match_id, league_id, data_list, "hg3535", odds_onlys, number, uuid,
  565. 0, utime, pt]
  566. odds_dict = dict(zip(odds_key, odds_value))
  567. if data_list:
  568. # print(odds_dict)
  569. response_data = Helper.async_post(url + '/setOdds', odds_dict)
  570. # print(response_data)
  571. print('足球赔率请求成功', response_data)
  572. if "成功" in response_data:
  573. if result:
  574. self.db.hg3535_zq_odds.update({'match_id': match_id, 'pt': pt}, {
  575. '$set': {"data": data_list, "odds_only": odds_onlys, "utime": utime}}, upsert=True)
  576. else:
  577. self.db.hg3535_zq_odds.insert(odds_dict)
  578. data_list = []
  579. zq_rball = {"home_team": team_home, "guest_team": team_guest,
  580. "lg_id": league_id, "home_rate": 0,
  581. "guest_rate": 0, "home_score": score_home,
  582. "guest_score": score_guest, "all_goal": all_goal, "status": 1,
  583. "first_score": "", "last_score": "", "match_score": match_score, "uuid": uuid,
  584. "match_winer": "", "match_time": time_game,
  585. "match_process": half_way, "tag": number,
  586. "match_id": match_id, "p_code": ""}
  587. data_list.append(zq_rball)
  588. r_data_dict = {
  589. "game_code": "zq",
  590. "title": "match_result_r",
  591. "source": "hg3535",
  592. "data": data_list
  593. }
  594. if data_list:
  595. try:
  596. response_data = Helper.async_post(url + '/setMatchResult', r_data_dict)
  597. print(r_data_dict)
  598. print("滚球赛事结果post提交", response_data)
  599. except Exception as e:
  600. logger.warning('滚球数据接口异常,提交失败')
  601. logger.warning(e)