roll_zuqiu.py 67 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103
  1. # import datetime
  2. import datetime
  3. import pymongo
  4. import time
  5. import logging
  6. from twisted.internet import defer, reactor
  7. # from .ball_func import fuhao
  8. from ..utils.helper import Helper
  9. # from .ball_func import get_pcode
  10. from ..settings import M_HOST, M_USER, M_PASSWORD, M_POST, M_DB, LEAGUE_URL, ODDS_URL, MATCH_URL, MATCH_RESULT
  11. # 滚球足球 插入
  12. class Roll_Zuqiupipeline(object):
  13. def open_spider(self, spider):
  14. self.mongo = pymongo.MongoClient(host=M_HOST, username=M_USER, password=M_PASSWORD, port=M_POST)
  15. self.db = self.mongo[M_DB]
  16. @defer.inlineCallbacks
  17. def process_item(self, item, spider):
  18. out = defer.Deferred()
  19. reactor.callInThread(self._do_calculation, item, out)
  20. yield out
  21. defer.returnValue(item)
  22. # def process_item(self, item, spider):
  23. def _do_calculation(self, item, out):
  24. logger = logging.getLogger(__name__)
  25. pt = 4
  26. # 比赛日期
  27. # try:
  28. # data_game = item['data_game'].split("/")
  29. # month = str(data_game[1].strip())
  30. # day = str(data_game[0])
  31. # except Exception as e:
  32. # logger.warning(e)
  33. # data_game = item['data_game'].split(" ")
  34. # months = str(data_game[1].strip())
  35. # 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'}
  36. # month = month_dict[months]
  37. # day = str(data_game[0])
  38. # 比赛时间
  39. time_game = str(item['time_game'])
  40. # 现在时间,时间戳
  41. utime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
  42. match_date = datetime.datetime.now().strftime("%Y-%m-%d")
  43. # 比赛id
  44. match_id = item['game_id']
  45. # 联赛id
  46. league_id = item['league_id']
  47. # 联赛name
  48. league_name = item['league_name']
  49. # 主队
  50. team_home = item['team_home']
  51. # 客队
  52. team_guest = item['team_guest']
  53. # number
  54. number = item['number']
  55. score_home = item['score_home']
  56. score_guest = item['score_guest']
  57. all_goal = int(score_home) + int(score_guest)
  58. half_way = item['half_way']
  59. match_score = "{}:{}".format(score_home, score_guest)
  60. last_time = '{}-12-31 23:59:59'.format(datetime.datetime.now().year)
  61. league_list = []
  62. uuid = Helper.genearte_uuid(league_name + 'hg3535')
  63. horn_team = item['horn_team']
  64. if self.db.zq_league35.find({'league_id': league_id}).count() < 1:
  65. league_dict = {"game_code": "zq", "title": "league", "source": "hg3535"}
  66. league_key = ["name_chinese", "kind", "match_mode", "if_stop", "last_time", "lg_id", "source", "uuid"]
  67. league_value = [league_name, "1", "1", "0", last_time, league_id, "hg3535", uuid]
  68. league_data = dict(zip(league_key, league_value))
  69. league_list.append(league_data)
  70. league_dict['data'] = league_list
  71. res = Helper.async_post(LEAGUE_URL, league_dict)
  72. if res:
  73. if "成功" in res:
  74. self.db.hg3535_zq_league.insert(league_list)
  75. logger.info('足球滚球联赛提交成功, {}'.format(res))
  76. logger.info(league_dict)
  77. else:
  78. logger.warning('足球滚球联赛提交失败, {}'.format(res))
  79. logger.warning(league_dict)
  80. else:
  81. logger.warning('足球滚球联赛接口异常提交失败, {}'.format(res))
  82. logger.warning(league_dict)
  83. else:
  84. logger.info('足球滚球联赛已存在, 不存在')
  85. if self.db.zq_competition35.find({"match_id": match_id, 'is_rollball': 1}).count() < 1:
  86. match_list = []
  87. match_dict = {"game_code": "zq", "title": "match", "source": "hg3535"}
  88. match_kay = ["home_team", "guest_team", "lg_id", "status", "match_id", "match_date", "match_time",
  89. "tag", "source", "is_rollball", "is_morningplate", "is_stringscene", "us_time", "uuid",
  90. "half_match_id", "is_today", "is_horn"]
  91. match_value = [team_home, team_guest, league_id, 1, match_id, match_date, '00:00', number,
  92. "hg3535", 1, 0, 0, utime, uuid, 0, 0, 0]
  93. match_data = dict(zip(match_kay, match_value))
  94. match_list.append(match_data)
  95. match_dict['data'] = match_list
  96. res = Helper.async_post(MATCH_URL, match_dict)
  97. if res:
  98. if "成功" in res:
  99. self.db.zq_competition35.insert(match_data)
  100. logger.info('足球滚球赛事提交成功, {}'.format(res))
  101. logger.info(match_data)
  102. else:
  103. logger.warning('足球滚球赛事,提交失败, {}'.format(res))
  104. logger.warning(match_data)
  105. else:
  106. logger.warning('足球滚球赛事接口异常提交失败, {}'.format(res))
  107. logger.warning(match_data)
  108. else:
  109. logger.info('足球滚球赛事已存在, 不提交')
  110. p_code = "GS"
  111. # 构建唯一索引
  112. half_size_guest = item["half_size_guest"]
  113. half_size_guest_rule = item["half_size_guest_rule"]
  114. half_size_home = item["half_size_home"]
  115. half_size_home_rule = item["half_size_home_rule"]
  116. data_list = []
  117. odds_onlys = []
  118. # half_size_guest
  119. for index, value in enumerate(half_size_guest):
  120. hash_str = p_code + "gss_h" + str(index) + str(half_size_guest_rule[index]) + str(
  121. value) + "hg3535" + str(match_id)
  122. sole_str = p_code + "gss_h" + str(index) + str(match_id) + "hg3535"
  123. odds_only = Helper.genearte_MD5(hash_str, pt)
  124. sole = Helper.genearte_MD5(sole_str, pt)
  125. half_size_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  126. "odds_only", "sole", "source", "type", "team"]
  127. condition = half_size_guest_rule[index]
  128. half_size_guest_value = [match_id, league_id, "gss_h", "0", index, p_code, value, condition,
  129. odds_only, sole, "hg3535", "0", ""]
  130. half_size_guest_data = dict(zip(half_size_guest_key, half_size_guest_value))
  131. data_list.append(half_size_guest_data)
  132. # half_size_home
  133. for index, value in enumerate(half_size_home):
  134. hash_str = p_code + "gsb_h" + str(index) + str(half_size_home_rule[index]) + str(
  135. value) + "hg3535" + str(match_id)
  136. sole_str = p_code + "gsb_h" + str(index) + str(match_id) + "hg3535"
  137. odds_only = Helper.genearte_MD5(hash_str, pt)
  138. sole = Helper.genearte_MD5(sole_str, pt)
  139. half_size_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  140. "odds_only", "sole", "source", "type", "team"]
  141. condition = half_size_home_rule[index]
  142. half_size_home_value = [match_id, league_id, "gsb_h", "0", index, p_code, value, condition,
  143. odds_only, sole, "hg3535", "0", ""]
  144. half_size_home_data = dict(zip(half_size_home_key, half_size_home_value))
  145. data_list.append(half_size_home_data)
  146. # 全场场大小
  147. size_guest = item["size_guest"]
  148. size_guest_rule = item["size_guest_rule"]
  149. size_home = item["size_home"]
  150. size_home_rule = item["size_home_rule"]
  151. # size_home
  152. for index, value in enumerate(size_home):
  153. hash_str = p_code + "gsb" + str(index) + str(size_home_rule[index]) + str(value) + "hg3535" + str(
  154. match_id)
  155. sole_str = p_code + "gsb" + str(index) + str(match_id) + "hg3535"
  156. odds_only = Helper.genearte_MD5(hash_str, pt)
  157. sole = Helper.genearte_MD5(sole_str, pt)
  158. size_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  159. "odds_only", "sole", "source", "type", "team"]
  160. condition = size_home_rule[index]
  161. size_home_value = [match_id, league_id, "gsb", "0", index, p_code, value, condition, odds_only,
  162. sole, "hg3535", "0", ""]
  163. size_home_data = dict(zip(size_home_key, size_home_value))
  164. data_list.append(size_home_data)
  165. # size_guest
  166. for index, value in enumerate(size_guest):
  167. hash_str = p_code + "gss" + str(index) + str(size_guest_rule[index]) + str(value) + "hg3535" + str(
  168. match_id)
  169. sole_str = p_code + "gss" + str(index) + str(match_id) + "hg3535"
  170. odds_only = Helper.genearte_MD5(hash_str, pt)
  171. sole = Helper.genearte_MD5(sole_str, pt)
  172. size_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  173. "odds_only", "sole", "source", "type", "team"]
  174. condition = size_guest_rule[index]
  175. size_guest_value = [match_id, league_id, "gss", "0", index, p_code, value, condition, odds_only,
  176. sole, "hg3535", "0", ""]
  177. size_home_data = dict(zip(size_guest_key, size_guest_value))
  178. data_list.append(size_home_data)
  179. p_code = 'CO'
  180. half_concede_home_rule = item["half_concede_home_rule"]
  181. half_concede_home = item["half_concede_home"]
  182. half_concede_guest_rule = item["half_concede_guest_rule"]
  183. half_concede_guest = item["half_concede_guest"]
  184. # half_concede_home
  185. for index, value in enumerate(half_concede_guest):
  186. hash_str = p_code + "cog_h" + str(index) + str(half_concede_guest_rule[index]) + str(
  187. value) + "hg3535" + str(match_id)
  188. sole_str = p_code + "cog_h" + str(index) + str(match_id) + "hg3535"
  189. odds_only = Helper.genearte_MD5(hash_str, pt)
  190. sole = Helper.genearte_MD5(sole_str, pt)
  191. half_concede_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  192. "odds_only", "sole", "source", "type", "team"]
  193. condition = half_concede_guest_rule[index]
  194. half_concede_guest_value = [match_id, league_id, "cog_h", "0", index, p_code, value, condition,
  195. odds_only, sole, "hg3535", "0", ""]
  196. half_concede_guest_data = dict(zip(half_concede_guest_key, half_concede_guest_value))
  197. data_list.append(half_concede_guest_data)
  198. # half_concede_home
  199. for index, value in enumerate(half_concede_home):
  200. hash_str = p_code + "coh_h" + str(index) + str(half_concede_home_rule[index]) + str(
  201. value) + "hg3535" + str(match_id)
  202. sole_str = p_code + "coh_h" + str(index) + str(match_id) + "hg3535"
  203. odds_only = Helper.genearte_MD5(hash_str, pt)
  204. sole = Helper.genearte_MD5(sole_str, pt)
  205. half_concede_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  206. "odds_only", "sole", "source", "type", "team"]
  207. condition = half_concede_home_rule[index]
  208. half_concede_home_value = [match_id, league_id, "coh_h", "0", index, p_code, value, condition,
  209. odds_only, sole, "hg3535", "0", ""]
  210. half_concede_home_data = dict(zip(half_concede_home_key, half_concede_home_value))
  211. data_list.append(half_concede_home_data)
  212. concede_guest = item["concede_guest"]
  213. concede_guest_rule = item["concede_guest_rule"]
  214. concede_home = item["concede_home"]
  215. concede_home_rule = item["concede_home_rule"]
  216. # concede_guest
  217. for index, value in enumerate(concede_guest):
  218. hash_str = p_code + "cog" + str(index) + str(concede_guest_rule[index]) + str(
  219. value) + "hg3535" + str(match_id)
  220. sole_str = p_code + "cog" + str(index) + str(match_id) + "hg3535"
  221. odds_only = Helper.genearte_MD5(hash_str, pt)
  222. sole = Helper.genearte_MD5(sole_str, pt)
  223. concede_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  224. "odds_only", "sole", "source", "type", "team"]
  225. condition = concede_guest_rule[index]
  226. concede_guest_value = [match_id, league_id, "cog", "0", index, p_code, value, condition,
  227. odds_only, sole, "hg3535", "0", ""]
  228. concede_guest_data = dict(zip(concede_guest_key, concede_guest_value))
  229. data_list.append(concede_guest_data)
  230. # concede_home
  231. for index, value in enumerate(concede_home):
  232. hash_str = p_code + "coh" + str(index) + str(concede_home_rule[index]) + str(
  233. value) + "hg3535" + str(match_id)
  234. sole_str = p_code + "coh" + str(index) + str(match_id) + "hg3535"
  235. odds_only = Helper.genearte_MD5(hash_str, pt)
  236. sole = Helper.genearte_MD5(sole_str, pt)
  237. concede_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  238. "odds_only", "sole", "source", "type", "team"]
  239. condition = concede_home_rule[index]
  240. concede_home_value = [match_id, league_id, "coh", "0", index, p_code, value, condition, odds_only,
  241. sole, "hg3535", "0", ""]
  242. concede_guest_data = dict(zip(concede_home_key, concede_home_value))
  243. data_list.append(concede_guest_data)
  244. # 独赢-------------------------------------------------------------------------------------------------------
  245. p_code = 'C'
  246. half_capot_home = item["half_capot_home"]
  247. half_capot_guest = item["half_capot_guest"]
  248. half_capot_dogfall = item["half_capot_dogfall"]
  249. capot_home = item["capot_home"]
  250. capot_guest = item["capot_guest"]
  251. capot_dogfall = item["capot_dogfall"]
  252. # half_capot_home
  253. hash_str = p_code + "ch_h" + '0' + '1' + str(half_capot_home) + "hg3535" + str(match_id)
  254. sole_str = p_code + "ch_h" + '0' + str(match_id) + "hg3535"
  255. odds_only = Helper.genearte_MD5(hash_str, pt)
  256. sole = Helper.genearte_MD5(sole_str, pt)
  257. half_capot_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  258. "odds_only", "sole", "source", "type", "team"]
  259. half_capot_home_value = [match_id, league_id, "ch_h", "0", 0, p_code, half_capot_home, '1',
  260. odds_only, sole, "hg3535", "0", ""]
  261. half_capot_homet_data = dict(zip(half_capot_home_key, half_capot_home_value))
  262. data_list.append(half_capot_homet_data)
  263. # half_capot_guest
  264. hash_str = p_code + "cg_h" + '0' + '2' + str(half_capot_guest) + "hg3535" + str(match_id)
  265. sole_str = p_code + "cg_h" + '0' + str(match_id) + "hg3535"
  266. odds_only = Helper.genearte_MD5(hash_str, pt)
  267. sole = Helper.genearte_MD5(sole_str, pt)
  268. half_capot_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  269. "odds_only", "sole", "source", "type", "team"]
  270. half_capot_guest_value = [match_id, league_id, "cg_h", "0", 0, p_code, half_capot_guest, '2',
  271. odds_only, sole, "hg3535", "0", ""]
  272. half_capot_guest_data = dict(zip(half_capot_guest_key, half_capot_guest_value))
  273. data_list.append(half_capot_guest_data)
  274. # half_capot_dogfall
  275. hash_str = p_code + "cd_h" + '0' + 'X' + str(half_capot_dogfall) + "hg3535" + str(match_id)
  276. sole_str = p_code + "cd_h" + '0' + str(match_id) + "hg3535"
  277. odds_only = Helper.genearte_MD5(hash_str, pt)
  278. sole = Helper.genearte_MD5(sole_str, pt)
  279. half_capot_dogfall_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  280. "odds_only", "sole", "source", "type", "team"]
  281. half_capot_dogfall_value = [match_id, league_id, "cd_h", "0", 0, p_code, half_capot_dogfall, 'X',
  282. odds_only, sole, "hg3535", "0", ""]
  283. half_capot_dogfall_data = dict(zip(half_capot_dogfall_key, half_capot_dogfall_value))
  284. data_list.append(half_capot_dogfall_data)
  285. # capot_dogfall
  286. hash_str = p_code + "cd" + '0' + 'X' + str(capot_dogfall) + "hg3535" + str(match_id)
  287. sole_str = p_code + "cd" + '0' + str(match_id) + "hg3535"
  288. odds_only = Helper.genearte_MD5(hash_str, pt)
  289. sole = Helper.genearte_MD5(sole_str, pt)
  290. capot_dogfall_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  291. "odds_only", "sole", "source", "type", "team"]
  292. capot_dogfall_value = [match_id, league_id, "cd", "0", 0, p_code, capot_dogfall, 'X', odds_only,
  293. sole, "hg3535", "0", ""]
  294. capot_dogfall_data = dict(zip(capot_dogfall_key, capot_dogfall_value))
  295. data_list.append(capot_dogfall_data)
  296. # capot_home
  297. hash_str = p_code + "ch" + '0' + '1' + str(capot_home) + "hg3535" + str(match_id)
  298. sole_str = p_code + "ch" + '0' + str(match_id) + "hg3535"
  299. odds_only = Helper.genearte_MD5(hash_str, pt)
  300. sole = Helper.genearte_MD5(sole_str, pt)
  301. capot_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  302. "odds_only", "sole", "source", "type", "team"]
  303. capot_home_value = [match_id, league_id, "ch", "0", 0, p_code, capot_home, '1',
  304. odds_only, sole, "hg3535", "0", ""]
  305. capot_homet_data = dict(zip(capot_home_key, capot_home_value))
  306. data_list.append(capot_homet_data)
  307. # capot_guest
  308. hash_str = p_code + "cg" + '0' + '2' + str(capot_guest) + "hg3535" + str(match_id)
  309. sole_str = p_code + "cg" + '0' + str(match_id) + "hg3535"
  310. odds_only = Helper.genearte_MD5(hash_str, pt)
  311. sole = Helper.genearte_MD5(sole_str, pt)
  312. capot_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  313. "odds_only", "sole", "source", "type", "team"]
  314. capot_guest_value = [match_id, league_id, "cg", "0", 0, p_code, capot_guest, '2',
  315. odds_only, sole, "hg3535", "0", ""]
  316. capot_guest_data = dict(zip(capot_guest_key, capot_guest_value))
  317. data_list.append(capot_guest_data)
  318. # 入球数单双--------------------------------------------------------------------------------------------------
  319. p_code = 'TS'
  320. odd_even_odd = item["odd_even_odd"]
  321. odd_even_even = item["odd_even_even"]
  322. half_odd_even_odd = item["half_odd_even_odd"]
  323. half_odd_even_even = item["half_odd_even_even"]
  324. # odd_even_odd
  325. hash_str = p_code + "tss" + '0' + '单' + str(odd_even_odd) + "hg3535" + str(match_id)
  326. sole_str = p_code + "tss" + '0' + str(match_id) + "hg3535"
  327. odds_only = Helper.genearte_MD5(hash_str, pt)
  328. sole = Helper.genearte_MD5(sole_str, pt)
  329. single_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  330. "odds_only", "sole", "source", "type", "team"]
  331. single_value = [match_id, league_id, "tss", "0", 0, p_code, odd_even_odd, '单',
  332. odds_only, sole, "hg3535", "0", ""]
  333. single_data = dict(zip(single_key, single_value))
  334. data_list.append(single_data)
  335. # odd_even_even
  336. hash_str = p_code + "tsd" + '0' + '双' + str(odd_even_even) + "hg3535" + str(match_id)
  337. sole_str = p_code + "tsd" + '0' + str(match_id) + "hg3535"
  338. odds_only = Helper.genearte_MD5(hash_str, pt)
  339. sole = Helper.genearte_MD5(sole_str, pt)
  340. double_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  341. "odds_only", "sole", "source", "type", "team"]
  342. double_value = [match_id, league_id, "tsd", "0", 0, p_code, odd_even_even, '双',
  343. odds_only, sole, "hg3535", "0", ""]
  344. double_data = dict(zip(double_key, double_value))
  345. data_list.append(double_data)
  346. # half_odd_even_even
  347. hash_str = p_code + "tsd_h" + '0' + '双' + str(half_odd_even_even) + "hg3535" + str(match_id)
  348. sole_str = p_code + "tsd_h" + '0' + str(match_id) + "hg3535"
  349. odds_only = Helper.genearte_MD5(hash_str, pt)
  350. sole = Helper.genearte_MD5(sole_str, pt)
  351. half_double_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  352. "odds_only", "sole", "source", "type", "team"]
  353. half_double_value = [match_id, league_id, "tsd_h", "0", 0, p_code, half_odd_even_even, '双',
  354. odds_only, sole, "hg3535", "0", ""]
  355. half_double_data = dict(zip(half_double_key, half_double_value))
  356. data_list.append(half_double_data)
  357. # half_odd_even_odd
  358. hash_str = p_code + "tss_h" + '0' + '单' + str(half_odd_even_odd) + "hg3535" + str(match_id)
  359. sole_str = p_code + "tss_h" + '0' + str(match_id) + "hg3535"
  360. odds_only = Helper.genearte_MD5(hash_str, pt)
  361. sole = Helper.genearte_MD5(sole_str, pt)
  362. half_single_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  363. "odds_only", "sole", "source", "type", "team"]
  364. half_single_value = [match_id, league_id, "tss_h", "0", 0, p_code, half_odd_even_odd, '单', odds_only,
  365. sole, "hg3535", "0", ""]
  366. half_single_data = dict(zip(half_single_key, half_single_value))
  367. data_list.append(half_single_data)
  368. p_code = 'TG'
  369. # 总入球数 ---------------------------------------------------------------------------------------------------
  370. total_goals = item['total_goal']
  371. total_dict = {'tg0': '0-1', 'tg1': '2-3', 'tg2': '4-6', 'tg3': '7或以上', 'tg0_h': '0', "tg1_h": '1',
  372. "tg2_h": '2', "tg3_h": '3或以上'}
  373. # 全场入球数 单双
  374. for key, value in total_goals.items():
  375. hash_str = p_code + key + '0' + total_dict[key] + str(value) + "hg3535" + str(match_id)
  376. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  377. odds_only = Helper.genearte_MD5(hash_str, pt)
  378. sole = Helper.genearte_MD5(sole_str, pt)
  379. total_goals_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  380. "odds_only", "sole", "source", "type", "team"]
  381. total_goals_value = [match_id, league_id, key, "0", 0, p_code, value, total_dict[key], odds_only,
  382. sole, "hg3535", "0", ""]
  383. total_goals_data = dict(zip(total_goals_key, total_goals_value))
  384. data_list.append(total_goals_data)
  385. # 全场半场 ---------------------------------------------------------------------------------------------------
  386. half_fulls = item['half_full']
  387. # p_code, p_id = get_pcode(corner_ball, 'half_full')
  388. p_code = 'HF'
  389. full_dict = {"hfhh": "主主", "hfhd": "主和", "hfhg": "主客", "hfdh": "和主",
  390. "hfdd": "和和", "hfdg": "和客", "hfgh": "客主", "hfgd": "客和", "hfgg": "客客"}
  391. if half_fulls:
  392. for key, value in half_fulls.items():
  393. hash_str = p_code + key + '0' + full_dict[key] + str(value) + "hg3535" + str(match_id)
  394. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  395. odds_only = Helper.genearte_MD5(hash_str, pt)
  396. sole = Helper.genearte_MD5(sole_str, pt)
  397. half_fulls_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  398. "odds_only", "sole", "source", "type", "team"]
  399. half_fulls_value = [match_id, league_id, key, "0", 0, p_code, value, full_dict[key], odds_only,
  400. sole, "hg3535", "0", ""]
  401. half_fulls_data = dict(zip(half_fulls_key, half_fulls_value))
  402. data_list.append(half_fulls_data)
  403. # 波胆-------------------------------------------------------------------------------------------------------
  404. p_code = 'B'
  405. bodan_datas = item['bodan_data']
  406. # p_code, p_id = get_pcode(corner_ball, 'bodan')
  407. bodan_dict = {"b10": "1-0", "b20": "2-0", "b21": "2-1", "b30": "3-0", "b31": "3-1", "b32": "3-2",
  408. "b40": "4-0", "b41": "4-1", "b42": "4-2", "b43": "4-3", "b01": "0-1", "b02": "0-2",
  409. "b12": "1-2", "b03": "0-3", "b13": "1-3", "b23": "2-3", "b04": "0-4", "b14": "1-4",
  410. "b24": "2-4", "b34": "3-4", "b00": "0-0", "b11": "1-1", "b22": "2-2", "b33": "3-3",
  411. "b44": "4-4", "bo": "其他", "b10_h": "1-0", "b20_h": "2-0", "b21_h": "2-1", "b30_h": "3-0",
  412. "b31_h": "3-1", "b32_h": "3-2", "b01_h": "0-1", "b02_h": "0-2", "b12_h": "1-2", "b03_h": "0-3",
  413. "b13_h": "1-3", "b23_h": "2-3", "b00_h": "0-0", "b11_h": "1-1", "b22_h": "2-2", "b33_h": "3-3",
  414. "bo_h": "其他"}
  415. if bodan_datas:
  416. for key, value in bodan_datas.items():
  417. hash_str = p_code + key + '0' + bodan_dict[key] + str(value) + "hg3535" + str(match_id)
  418. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  419. odds_only = Helper.genearte_MD5(hash_str, pt)
  420. sole = Helper.genearte_MD5(sole_str, pt)
  421. bodan_dict_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  422. "odds_only", "sole", "source", "type", "team"]
  423. bodan_dict_value = [match_id, league_id, key, "0", 0, p_code, value, bodan_dict[key], odds_only,
  424. sole, "hg3535", "0", ""]
  425. bodan_dict_data = dict(zip(bodan_dict_key, bodan_dict_value))
  426. data_list.append(bodan_dict_data)
  427. # 最先进球/最后进球 -------------------------------------------------------------------------------------------
  428. first_last_balls = item['first_last_ball']
  429. p_code = 'FLB'
  430. first_last_dict = {"flbfh": "最先进球", "flbfg": "最先进球", "flblh": "最后进球", "flblg": "最后进球", "flbn": "没有进球"}
  431. if first_last_balls:
  432. for key, value in first_last_balls.items():
  433. hash_str = p_code + key + '0' + first_last_dict[key] + str(value) + "hg3535" + str(match_id)
  434. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  435. odds_only = Helper.genearte_MD5(hash_str, pt)
  436. sole = Helper.genearte_MD5(sole_str, pt)
  437. first_last_balls_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  438. "condition",
  439. "odds_only", "sole", "source", "type", "team"]
  440. first_last_balls_value = [match_id, league_id, key, "0", 0, p_code, value, first_last_dict[key],
  441. odds_only,
  442. sole, "hg3535", "0", ""]
  443. first_last_balls_data = dict(zip(first_last_balls_key, first_last_balls_value))
  444. data_list.append(first_last_balls_data)
  445. p_code = 'TB'
  446. # 球队得分全场,上半场
  447. full_dicts = item['full_data']
  448. half_dicts = item['half_data']
  449. full_dict_rules = item['full_data_rule']
  450. half_dict_rules = item['half_data_rule']
  451. if full_dicts:
  452. for key, value in full_dicts.items():
  453. hash_str = p_code + key + '0' + full_dict_rules[key] + str(value) + "hg3535" + str(match_id)
  454. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  455. odds_only = Helper.genearte_MD5(hash_str, pt)
  456. sole = Helper.genearte_MD5(sole_str, pt)
  457. full_dict_rules_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  458. "condition", "odds_only", "sole", "source", "type", "team"]
  459. full_dict_rules_value = [match_id, league_id, key, "0", 0, p_code, value, full_dict_rules[key],
  460. odds_only, sole, "hg3535", "0", ""]
  461. full_dict_rules_data = dict(zip(full_dict_rules_key, full_dict_rules_value))
  462. data_list.append(full_dict_rules_data)
  463. if half_dicts:
  464. for key, value in half_dicts.items():
  465. hash_str = p_code + key + '0' + half_dict_rules[key] + str(value) + "hg3535" + str(match_id)
  466. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  467. odds_only = Helper.genearte_MD5(hash_str, pt)
  468. sole = Helper.genearte_MD5(sole_str, pt)
  469. half_dicts_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  470. "condition", "odds_only", "sole", "source", "type", "team"]
  471. half_dicts_value = [match_id, league_id, key, "0", 0, p_code, value, half_dict_rules[key],
  472. odds_only, sole, "hg3535", "0", ""]
  473. half_dicts_data = dict(zip(half_dicts_key, half_dicts_value))
  474. data_list.append(half_dicts_data)
  475. p_code = 'CB'
  476. # 球队得分全场,上半场
  477. horn_ou_dict = item['horn_ou_dict']
  478. horn_ou_dict_rule = item['horn_ou_dict_rule']
  479. horn_oe_dict = item['horn_oe_dict']
  480. horn_oe_dict_rule = item['horn_oe_dict_rule']
  481. if horn_ou_dict:
  482. for key, value in horn_ou_dict.items():
  483. hash_str = p_code + key + '0' + horn_ou_dict_rule[key] + str(value) + "hg3535" + str(match_id)
  484. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  485. odds_only = Helper.genearte_MD5(hash_str, pt)
  486. sole = Helper.genearte_MD5(sole_str, pt)
  487. horn_ou_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  488. "condition", "odds_only", "sole", "source", "type", "team"]
  489. horn_ou_value = [match_id, league_id, key, "0", 0, p_code, value, horn_ou_dict_rule[key],
  490. odds_only, sole, "hg3535", "0", ""]
  491. horn_ou_data = dict(zip(horn_ou_key, horn_ou_value))
  492. data_list.append(horn_ou_data)
  493. if horn_oe_dict:
  494. for key, value in horn_oe_dict.items():
  495. hash_str = p_code + key + '0' + horn_oe_dict_rule[key] + str(value) + "hg3535" + str(match_id)
  496. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  497. odds_only = Helper.genearte_MD5(hash_str, pt)
  498. sole = Helper.genearte_MD5(sole_str, pt)
  499. horn_oe_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  500. "condition", "odds_only", "sole", "source", "type", "team"]
  501. horn_oe_value = [match_id, league_id, key, "0", 0, p_code, value, horn_oe_dict_rule[key],
  502. odds_only, sole, "hg3535", "0", ""]
  503. horn_oe_data = dict(zip(horn_oe_key, horn_oe_value))
  504. data_list.append(horn_oe_data)
  505. odds_key = ["game_code", "title", "match_id", "lg_id", "data", "source", "odds_only", "tag", "uuid",
  506. "is_stringscene", "utime", "pt"]
  507. odds_value = ["zq", "odds", match_id, league_id, data_list, "hg3535", odds_onlys, number, uuid,
  508. 0, utime, pt]
  509. odds_dict = dict(zip(odds_key, odds_value))
  510. if data_list:
  511. res = Helper.async_post(ODDS_URL, odds_dict)
  512. if res:
  513. if "成功" in res:
  514. logger.info('足球滚球详细赔率提交成功, {}'.format(res))
  515. logger.info(odds_dict)
  516. else:
  517. logger.warning('足球滚球详细赔率提交失败, {}'.format(res))
  518. logger.warning(odds_dict)
  519. else:
  520. logger.warning('足球滚球详细赔率接口异常,提交失败, {}'.format(res))
  521. logger.warning(odds_dict)
  522. else:
  523. logger.info('足球滚球详细赔率列表为空')
  524. data_list = []
  525. zq_rball = {"home_team": team_home, "guest_team": team_guest,
  526. "lg_id": league_id, "home_rate": 0,
  527. "guest_rate": 0, "home_score": score_home,
  528. "guest_score": score_guest, "all_goal": all_goal, "status": 1,
  529. "first_score": "", "last_score": "", "match_score": match_score, "uuid": uuid,
  530. "match_winer": "", "match_time": time_game,
  531. "match_process": half_way, "tag": number,
  532. "match_id": match_id, "p_code": ""}
  533. data_list.append(zq_rball)
  534. r_data_dict = {
  535. "game_code": "zq",
  536. "title": "match_result_r",
  537. "source": "hg3535",
  538. "data": data_list
  539. }
  540. if data_list:
  541. try:
  542. res = Helper.async_post(MATCH_RESULT, r_data_dict)
  543. if res:
  544. if "成功" in res:
  545. logger.info('足球滚球结果记录提交成功, {}'.format(res))
  546. logger.info(r_data_dict)
  547. else:
  548. logger.warning('足球滚球结果记录提交失败, {}'.format(res))
  549. logger.warning(r_data_dict)
  550. else:
  551. logger.warning('足球滚球结果记录接口异常,提交失败, {}'.format(res))
  552. logger.warning(r_data_dict)
  553. except Exception as e:
  554. logger.warning('滚球数据接口异常,提交失败, {}'.format(e))
  555. # 角球分割处理--------------------------------------------------------------------------------------------------
  556. if horn_team:
  557. team_home = horn_team['horn_home']
  558. team_guest = horn_team['horn_guest']
  559. horn_scoreh = horn_team['horn_scoreh']
  560. horn_scoreg = horn_team['horn_scoreg']
  561. all_goal = int(horn_scoreh) + int(horn_scoreg)
  562. match_id = horn_team['horn_id']
  563. # half_way = item['half_way']
  564. match_score = "{}:{}".format(horn_scoreh, horn_scoreg)
  565. if self.db.zq_competition35.find({"match_id": match_id, 'is_rollball': 1}).count() < 1:
  566. match_list = []
  567. match_dict = {"game_code": "zq", "title": "match", "source": "hg3535"}
  568. match_kay = ["home_team", "guest_team", "lg_id", "status", "match_id", "match_date", "match_time",
  569. "tag", "source", "is_rollball", "is_morningplate", "is_stringscene", "us_time", "uuid",
  570. "half_match_id", "is_today", "is_horn"]
  571. match_value = [team_home, team_guest, league_id, 1, match_id, match_date, '00:00', number,
  572. "hg3535", 1, 0, 0, utime, uuid, 0, 0, 1]
  573. match_data = dict(zip(match_kay, match_value))
  574. match_list.append(match_data)
  575. match_dict['data'] = match_list
  576. res = Helper.async_post(MATCH_URL, match_dict)
  577. if res:
  578. if "成功" in res:
  579. self.db.zq_competition35.insert(match_data)
  580. logger.info('足球滚球角球, 赛事提交成功, {}'.format(res))
  581. logger.info(match_data)
  582. else:
  583. logger.warning('足球滚球赛事, 角球提交失败, {}'.format(res))
  584. logger.warning(match_data)
  585. else:
  586. logger.warning('足球滚球赛事接口异常, 角球赛事提交失败, {}'.format(res))
  587. logger.warning(match_data)
  588. else:
  589. logger.info('足球滚球赛事已存在, 不提交')
  590. p_code = "GS"
  591. # 构建唯一索引
  592. half_size_guest = item["half_size_guest"]
  593. half_size_guest_rule = item["half_size_guest_rule"]
  594. half_size_home = item["half_size_home"]
  595. half_size_home_rule = item["half_size_home_rule"]
  596. data_list = []
  597. odds_onlys = []
  598. # half_size_guest
  599. for index, value in enumerate(half_size_guest):
  600. hash_str = p_code + "gss_h" + str(index) + str(half_size_guest_rule[index]) + str(
  601. value) + "hg3535" + str(match_id)
  602. sole_str = p_code + "gss_h" + str(index) + str(match_id) + "hg3535"
  603. odds_only = Helper.genearte_MD5(hash_str, pt)
  604. sole = Helper.genearte_MD5(sole_str, pt)
  605. half_size_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  606. "odds_only", "sole", "source", "type", "team"]
  607. condition = half_size_guest_rule[index]
  608. half_size_guest_value = [match_id, league_id, "gss_h", "0", index, p_code, value, condition,
  609. odds_only, sole, "hg3535", "0", ""]
  610. half_size_guest_data = dict(zip(half_size_guest_key, half_size_guest_value))
  611. data_list.append(half_size_guest_data)
  612. # half_size_home
  613. for index, value in enumerate(half_size_home):
  614. hash_str = p_code + "gsb_h" + str(index) + str(half_size_home_rule[index]) + str(
  615. value) + "hg3535" + str(match_id)
  616. sole_str = p_code + "gsb_h" + str(index) + str(match_id) + "hg3535"
  617. odds_only = Helper.genearte_MD5(hash_str, pt)
  618. sole = Helper.genearte_MD5(sole_str, pt)
  619. half_size_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  620. "odds_only", "sole", "source", "type", "team"]
  621. condition = half_size_home_rule[index]
  622. half_size_home_value = [match_id, league_id, "gsb_h", "0", index, p_code, value, condition,
  623. odds_only, sole, "hg3535", "0", ""]
  624. half_size_home_data = dict(zip(half_size_home_key, half_size_home_value))
  625. data_list.append(half_size_home_data)
  626. # 全场场大小
  627. size_guest = item["size_guest"]
  628. size_guest_rule = item["size_guest_rule"]
  629. size_home = item["size_home"]
  630. size_home_rule = item["size_home_rule"]
  631. # size_home
  632. for index, value in enumerate(size_home):
  633. hash_str = p_code + "gsb" + str(index) + str(size_home_rule[index]) + str(value) + "hg3535" + str(
  634. match_id)
  635. sole_str = p_code + "gsb" + str(index) + str(match_id) + "hg3535"
  636. odds_only = Helper.genearte_MD5(hash_str, pt)
  637. sole = Helper.genearte_MD5(sole_str, pt)
  638. size_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  639. "odds_only", "sole", "source", "type", "team"]
  640. condition = size_home_rule[index]
  641. size_home_value = [match_id, league_id, "gsb", "0", index, p_code, value, condition, odds_only,
  642. sole, "hg3535", "0", ""]
  643. size_home_data = dict(zip(size_home_key, size_home_value))
  644. data_list.append(size_home_data)
  645. # size_guest
  646. for index, value in enumerate(size_guest):
  647. hash_str = p_code + "gss" + str(index) + str(size_guest_rule[index]) + str(value) + "hg3535" + str(
  648. match_id)
  649. sole_str = p_code + "gss" + str(index) + str(match_id) + "hg3535"
  650. odds_only = Helper.genearte_MD5(hash_str, pt)
  651. sole = Helper.genearte_MD5(sole_str, pt)
  652. size_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  653. "odds_only", "sole", "source", "type", "team"]
  654. condition = size_guest_rule[index]
  655. size_guest_value = [match_id, league_id, "gss", "0", index, p_code, value, condition, odds_only,
  656. sole, "hg3535", "0", ""]
  657. size_home_data = dict(zip(size_guest_key, size_guest_value))
  658. data_list.append(size_home_data)
  659. p_code = 'CO'
  660. half_concede_home_rule = item["half_concede_home_rule"]
  661. half_concede_home = item["half_concede_home"]
  662. half_concede_guest_rule = item["half_concede_guest_rule"]
  663. half_concede_guest = item["half_concede_guest"]
  664. # half_concede_home
  665. for index, value in enumerate(half_concede_guest):
  666. hash_str = p_code + "cog_h" + str(index) + str(half_concede_guest_rule[index]) + str(
  667. value) + "hg3535" + str(match_id)
  668. sole_str = p_code + "cog_h" + str(index) + str(match_id) + "hg3535"
  669. odds_only = Helper.genearte_MD5(hash_str, pt)
  670. sole = Helper.genearte_MD5(sole_str, pt)
  671. half_concede_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  672. "odds_only", "sole", "source", "type", "team"]
  673. condition = half_concede_guest_rule[index]
  674. half_concede_guest_value = [match_id, league_id, "cog_h", "0", index, p_code, value, condition,
  675. odds_only, sole, "hg3535", "0", ""]
  676. half_concede_guest_data = dict(zip(half_concede_guest_key, half_concede_guest_value))
  677. data_list.append(half_concede_guest_data)
  678. # half_concede_home
  679. for index, value in enumerate(half_concede_home):
  680. hash_str = p_code + "coh_h" + str(index) + str(half_concede_home_rule[index]) + str(
  681. value) + "hg3535" + str(match_id)
  682. sole_str = p_code + "coh_h" + str(index) + str(match_id) + "hg3535"
  683. odds_only = Helper.genearte_MD5(hash_str, pt)
  684. sole = Helper.genearte_MD5(sole_str, pt)
  685. half_concede_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  686. "odds_only", "sole", "source", "type", "team"]
  687. condition = half_concede_home_rule[index]
  688. half_concede_home_value = [match_id, league_id, "coh_h", "0", index, p_code, value, condition,
  689. odds_only, sole, "hg3535", "0", ""]
  690. half_concede_home_data = dict(zip(half_concede_home_key, half_concede_home_value))
  691. data_list.append(half_concede_home_data)
  692. concede_guest = item["concede_guest"]
  693. concede_guest_rule = item["concede_guest_rule"]
  694. concede_home = item["concede_home"]
  695. concede_home_rule = item["concede_home_rule"]
  696. # concede_guest
  697. for index, value in enumerate(concede_guest):
  698. hash_str = p_code + "cog" + str(index) + str(concede_guest_rule[index]) + str(
  699. value) + "hg3535" + str(match_id)
  700. sole_str = p_code + "cog" + str(index) + str(match_id) + "hg3535"
  701. odds_only = Helper.genearte_MD5(hash_str, pt)
  702. sole = Helper.genearte_MD5(sole_str, pt)
  703. concede_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  704. "odds_only", "sole", "source", "type", "team"]
  705. condition = concede_guest_rule[index]
  706. concede_guest_value = [match_id, league_id, "cog", "0", index, p_code, value, condition,
  707. odds_only, sole, "hg3535", "0", ""]
  708. concede_guest_data = dict(zip(concede_guest_key, concede_guest_value))
  709. data_list.append(concede_guest_data)
  710. # concede_home
  711. for index, value in enumerate(concede_home):
  712. hash_str = p_code + "coh" + str(index) + str(concede_home_rule[index]) + str(
  713. value) + "hg3535" + str(match_id)
  714. sole_str = p_code + "coh" + str(index) + str(match_id) + "hg3535"
  715. odds_only = Helper.genearte_MD5(hash_str, pt)
  716. sole = Helper.genearte_MD5(sole_str, pt)
  717. concede_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  718. "odds_only", "sole", "source", "type", "team"]
  719. condition = concede_home_rule[index]
  720. concede_home_value = [match_id, league_id, "coh", "0", index, p_code, value, condition, odds_only,
  721. sole, "hg3535", "0", ""]
  722. concede_guest_data = dict(zip(concede_home_key, concede_home_value))
  723. data_list.append(concede_guest_data)
  724. # 独赢-------------------------------------------------------------------------------------------------------
  725. p_code = 'C'
  726. half_capot_home = item["half_capot_home"]
  727. half_capot_guest = item["half_capot_guest"]
  728. half_capot_dogfall = item["half_capot_dogfall"]
  729. capot_home = item["capot_home"]
  730. capot_guest = item["capot_guest"]
  731. capot_dogfall = item["capot_dogfall"]
  732. # half_capot_home
  733. hash_str = p_code + "ch_h" + '0' + '1' + str(half_capot_home) + "hg3535" + str(match_id)
  734. sole_str = p_code + "ch_h" + '0' + str(match_id) + "hg3535"
  735. odds_only = Helper.genearte_MD5(hash_str, pt)
  736. sole = Helper.genearte_MD5(sole_str, pt)
  737. half_capot_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  738. "odds_only", "sole", "source", "type", "team"]
  739. half_capot_home_value = [match_id, league_id, "ch_h", "0", 0, p_code, half_capot_home, '1',
  740. odds_only, sole, "hg3535", "0", ""]
  741. half_capot_homet_data = dict(zip(half_capot_home_key, half_capot_home_value))
  742. data_list.append(half_capot_homet_data)
  743. # half_capot_guest
  744. hash_str = p_code + "cg_h" + '0' + '2' + str(half_capot_guest) + "hg3535" + str(match_id)
  745. sole_str = p_code + "cg_h" + '0' + str(match_id) + "hg3535"
  746. odds_only = Helper.genearte_MD5(hash_str, pt)
  747. sole = Helper.genearte_MD5(sole_str, pt)
  748. half_capot_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  749. "odds_only", "sole", "source", "type", "team"]
  750. half_capot_guest_value = [match_id, league_id, "cg_h", "0", 0, p_code, half_capot_guest, '2',
  751. odds_only, sole, "hg3535", "0", ""]
  752. half_capot_guest_data = dict(zip(half_capot_guest_key, half_capot_guest_value))
  753. data_list.append(half_capot_guest_data)
  754. # half_capot_dogfall
  755. hash_str = p_code + "cd_h" + '0' + 'X' + str(half_capot_dogfall) + "hg3535" + str(match_id)
  756. sole_str = p_code + "cd_h" + '0' + str(match_id) + "hg3535"
  757. odds_only = Helper.genearte_MD5(hash_str, pt)
  758. sole = Helper.genearte_MD5(sole_str, pt)
  759. half_capot_dogfall_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  760. "odds_only", "sole", "source", "type", "team"]
  761. half_capot_dogfall_value = [match_id, league_id, "cd_h", "0", 0, p_code, half_capot_dogfall, 'X',
  762. odds_only, sole, "hg3535", "0", ""]
  763. half_capot_dogfall_data = dict(zip(half_capot_dogfall_key, half_capot_dogfall_value))
  764. data_list.append(half_capot_dogfall_data)
  765. # capot_dogfall
  766. hash_str = p_code + "cd" + '0' + 'X' + str(capot_dogfall) + "hg3535" + str(match_id)
  767. sole_str = p_code + "cd" + '0' + str(match_id) + "hg3535"
  768. odds_only = Helper.genearte_MD5(hash_str, pt)
  769. sole = Helper.genearte_MD5(sole_str, pt)
  770. capot_dogfall_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  771. "odds_only", "sole", "source", "type", "team"]
  772. capot_dogfall_value = [match_id, league_id, "cd", "0", 0, p_code, capot_dogfall, 'X', odds_only,
  773. sole, "hg3535", "0", ""]
  774. capot_dogfall_data = dict(zip(capot_dogfall_key, capot_dogfall_value))
  775. data_list.append(capot_dogfall_data)
  776. # capot_home
  777. hash_str = p_code + "ch" + '0' + '1' + str(capot_home) + "hg3535" + str(match_id)
  778. sole_str = p_code + "ch" + '0' + str(match_id) + "hg3535"
  779. odds_only = Helper.genearte_MD5(hash_str, pt)
  780. sole = Helper.genearte_MD5(sole_str, pt)
  781. capot_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  782. "odds_only", "sole", "source", "type", "team"]
  783. capot_home_value = [match_id, league_id, "ch", "0", 0, p_code, capot_home, '1',
  784. odds_only, sole, "hg3535", "0", ""]
  785. capot_homet_data = dict(zip(capot_home_key, capot_home_value))
  786. data_list.append(capot_homet_data)
  787. # capot_guest
  788. hash_str = p_code + "cg" + '0' + '2' + str(capot_guest) + "hg3535" + str(match_id)
  789. sole_str = p_code + "cg" + '0' + str(match_id) + "hg3535"
  790. odds_only = Helper.genearte_MD5(hash_str, pt)
  791. sole = Helper.genearte_MD5(sole_str, pt)
  792. capot_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  793. "odds_only", "sole", "source", "type", "team"]
  794. capot_guest_value = [match_id, league_id, "cg", "0", 0, p_code, capot_guest, '2',
  795. odds_only, sole, "hg3535", "0", ""]
  796. capot_guest_data = dict(zip(capot_guest_key, capot_guest_value))
  797. data_list.append(capot_guest_data)
  798. # 入球数单双--------------------------------------------------------------------------------------------------
  799. p_code = 'TS'
  800. odd_even_odd = item["odd_even_odd"]
  801. odd_even_even = item["odd_even_even"]
  802. half_odd_even_odd = item["half_odd_even_odd"]
  803. half_odd_even_even = item["half_odd_even_even"]
  804. # odd_even_odd
  805. hash_str = p_code + "tss" + '0' + '单' + str(odd_even_odd) + "hg3535" + str(match_id)
  806. sole_str = p_code + "tss" + '0' + str(match_id) + "hg3535"
  807. odds_only = Helper.genearte_MD5(hash_str, pt)
  808. sole = Helper.genearte_MD5(sole_str, pt)
  809. single_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  810. "odds_only", "sole", "source", "type", "team"]
  811. single_value = [match_id, league_id, "tss", "0", 0, p_code, odd_even_odd, '单',
  812. odds_only, sole, "hg3535", "0", ""]
  813. single_data = dict(zip(single_key, single_value))
  814. data_list.append(single_data)
  815. # odd_even_even
  816. hash_str = p_code + "tsd" + '0' + '双' + str(odd_even_even) + "hg3535" + str(match_id)
  817. sole_str = p_code + "tsd" + '0' + str(match_id) + "hg3535"
  818. odds_only = Helper.genearte_MD5(hash_str, pt)
  819. sole = Helper.genearte_MD5(sole_str, pt)
  820. double_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  821. "odds_only", "sole", "source", "type", "team"]
  822. double_value = [match_id, league_id, "tsd", "0", 0, p_code, odd_even_even, '双',
  823. odds_only, sole, "hg3535", "0", ""]
  824. double_data = dict(zip(double_key, double_value))
  825. data_list.append(double_data)
  826. # half_odd_even_even
  827. hash_str = p_code + "tsd_h" + '0' + '双' + str(half_odd_even_even) + "hg3535" + str(match_id)
  828. sole_str = p_code + "tsd_h" + '0' + str(match_id) + "hg3535"
  829. odds_only = Helper.genearte_MD5(hash_str, pt)
  830. sole = Helper.genearte_MD5(sole_str, pt)
  831. half_double_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  832. "odds_only", "sole", "source", "type", "team"]
  833. half_double_value = [match_id, league_id, "tsd_h", "0", 0, p_code, half_odd_even_even, '双',
  834. odds_only, sole, "hg3535", "0", ""]
  835. half_double_data = dict(zip(half_double_key, half_double_value))
  836. data_list.append(half_double_data)
  837. # half_odd_even_odd
  838. hash_str = p_code + "tss_h" + '0' + '单' + str(half_odd_even_odd) + "hg3535" + str(match_id)
  839. sole_str = p_code + "tss_h" + '0' + str(match_id) + "hg3535"
  840. odds_only = Helper.genearte_MD5(hash_str, pt)
  841. sole = Helper.genearte_MD5(sole_str, pt)
  842. half_single_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  843. "odds_only", "sole", "source", "type", "team"]
  844. half_single_value = [match_id, league_id, "tss_h", "0", 0, p_code, half_odd_even_odd, '单', odds_only,
  845. sole, "hg3535", "0", ""]
  846. half_single_data = dict(zip(half_single_key, half_single_value))
  847. data_list.append(half_single_data)
  848. p_code = 'TG'
  849. # 总入球数 ---------------------------------------------------------------------------------------------------
  850. total_goals = item['total_goal']
  851. total_dict = {'tg0': '0-1', 'tg1': '2-3', 'tg2': '4-6', 'tg3': '7或以上', 'tg0_h': '0', "tg1_h": '1',
  852. "tg2_h": '2', "tg3_h": '3或以上'}
  853. # 全场入球数 单双
  854. for key, value in total_goals.items():
  855. hash_str = p_code + key + '0' + total_dict[key] + str(value) + "hg3535" + str(match_id)
  856. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  857. odds_only = Helper.genearte_MD5(hash_str, pt)
  858. sole = Helper.genearte_MD5(sole_str, pt)
  859. total_goals_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  860. "odds_only", "sole", "source", "type", "team"]
  861. total_goals_value = [match_id, league_id, key, "0", 0, p_code, value, total_dict[key], odds_only,
  862. sole, "hg3535", "0", ""]
  863. total_goals_data = dict(zip(total_goals_key, total_goals_value))
  864. data_list.append(total_goals_data)
  865. # 全场半场 ---------------------------------------------------------------------------------------------------
  866. half_fulls = item['half_full']
  867. # p_code, p_id = get_pcode(corner_ball, 'half_full')
  868. p_code = 'HF'
  869. full_dict = {"hfhh": "主主", "hfhd": "主和", "hfhg": "主客", "hfdh": "和主",
  870. "hfdd": "和和", "hfdg": "和客", "hfgh": "客主", "hfgd": "客和", "hfgg": "客客"}
  871. if half_fulls:
  872. for key, value in half_fulls.items():
  873. hash_str = p_code + key + '0' + full_dict[key] + str(value) + "hg3535" + str(match_id)
  874. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  875. odds_only = Helper.genearte_MD5(hash_str, pt)
  876. sole = Helper.genearte_MD5(sole_str, pt)
  877. half_fulls_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  878. "odds_only", "sole", "source", "type", "team"]
  879. half_fulls_value = [match_id, league_id, key, "0", 0, p_code, value, full_dict[key], odds_only,
  880. sole, "hg3535", "0", ""]
  881. half_fulls_data = dict(zip(half_fulls_key, half_fulls_value))
  882. data_list.append(half_fulls_data)
  883. # 波胆-------------------------------------------------------------------------------------------------------
  884. p_code = 'B'
  885. bodan_datas = item['bodan_data']
  886. # p_code, p_id = get_pcode(corner_ball, 'bodan')
  887. bodan_dict = {"b10": "1-0", "b20": "2-0", "b21": "2-1", "b30": "3-0", "b31": "3-1", "b32": "3-2",
  888. "b40": "4-0", "b41": "4-1", "b42": "4-2", "b43": "4-3", "b01": "0-1", "b02": "0-2",
  889. "b12": "1-2", "b03": "0-3", "b13": "1-3", "b23": "2-3", "b04": "0-4", "b14": "1-4",
  890. "b24": "2-4", "b34": "3-4", "b00": "0-0", "b11": "1-1", "b22": "2-2", "b33": "3-3",
  891. "b44": "4-4", "bo": "其他", "b10_h": "1-0", "b20_h": "2-0", "b21_h": "2-1", "b30_h": "3-0",
  892. "b31_h": "3-1", "b32_h": "3-2", "b01_h": "0-1", "b02_h": "0-2", "b12_h": "1-2", "b03_h": "0-3",
  893. "b13_h": "1-3", "b23_h": "2-3", "b00_h": "0-0", "b11_h": "1-1", "b22_h": "2-2", "b33_h": "3-3",
  894. "bo_h": "其他"}
  895. if bodan_datas:
  896. for key, value in bodan_datas.items():
  897. hash_str = p_code + key + '0' + bodan_dict[key] + str(value) + "hg3535" + str(match_id)
  898. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  899. odds_only = Helper.genearte_MD5(hash_str, pt)
  900. sole = Helper.genearte_MD5(sole_str, pt)
  901. bodan_dict_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  902. "odds_only", "sole", "source", "type", "team"]
  903. bodan_dict_value = [match_id, league_id, key, "0", 0, p_code, value, bodan_dict[key], odds_only,
  904. sole, "hg3535", "0", ""]
  905. bodan_dict_data = dict(zip(bodan_dict_key, bodan_dict_value))
  906. data_list.append(bodan_dict_data)
  907. # 最先进球/最后进球 -------------------------------------------------------------------------------------------
  908. first_last_balls = item['first_last_ball']
  909. p_code = 'FLB'
  910. first_last_dict = {"flbfh": "最先进球", "flbfg": "最先进球", "flblh": "最后进球", "flblg": "最后进球", "flbn": "没有进球"}
  911. if first_last_balls:
  912. for key, value in first_last_balls.items():
  913. hash_str = p_code + key + '0' + first_last_dict[key] + str(value) + "hg3535" + str(match_id)
  914. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  915. odds_only = Helper.genearte_MD5(hash_str, pt)
  916. sole = Helper.genearte_MD5(sole_str, pt)
  917. first_last_balls_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  918. "condition",
  919. "odds_only", "sole", "source", "type", "team"]
  920. first_last_balls_value = [match_id, league_id, key, "0", 0, p_code, value, first_last_dict[key],
  921. odds_only,
  922. sole, "hg3535", "0", ""]
  923. first_last_balls_data = dict(zip(first_last_balls_key, first_last_balls_value))
  924. data_list.append(first_last_balls_data)
  925. p_code = 'TB'
  926. # 球队得分全场,上半场
  927. full_dicts = item['full_data']
  928. half_dicts = item['half_data']
  929. full_dict_rules = item['full_data_rule']
  930. half_dict_rules = item['half_data_rule']
  931. if full_dicts:
  932. for key, value in full_dicts.items():
  933. hash_str = p_code + key + '0' + full_dict_rules[key] + str(value) + "hg3535" + str(match_id)
  934. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  935. odds_only = Helper.genearte_MD5(hash_str, pt)
  936. sole = Helper.genearte_MD5(sole_str, pt)
  937. full_dict_rules_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  938. "condition", "odds_only", "sole", "source", "type", "team"]
  939. full_dict_rules_value = [match_id, league_id, key, "0", 0, p_code, value, full_dict_rules[key],
  940. odds_only, sole, "hg3535", "0", ""]
  941. full_dict_rules_data = dict(zip(full_dict_rules_key, full_dict_rules_value))
  942. data_list.append(full_dict_rules_data)
  943. if half_dicts:
  944. for key, value in half_dicts.items():
  945. hash_str = p_code + key + '0' + half_dict_rules[key] + str(value) + "hg3535" + str(match_id)
  946. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  947. odds_only = Helper.genearte_MD5(hash_str, pt)
  948. sole = Helper.genearte_MD5(sole_str, pt)
  949. half_dicts_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  950. "condition", "odds_only", "sole", "source", "type", "team"]
  951. half_dicts_value = [match_id, league_id, key, "0", 0, p_code, value, half_dict_rules[key],
  952. odds_only, sole, "hg3535", "0", ""]
  953. half_dicts_data = dict(zip(half_dicts_key, half_dicts_value))
  954. data_list.append(half_dicts_data)
  955. p_code = 'CB'
  956. horn_ou_dict = item['horn_ou_dict']
  957. horn_ou_dict_rule = item['horn_ou_dict_rule']
  958. horn_oe_dict = item['horn_oe_dict']
  959. horn_oe_dict_rule = item['horn_oe_dict_rule']
  960. if horn_ou_dict:
  961. for key, value in horn_ou_dict.items():
  962. hash_str = p_code + key + '0' + horn_ou_dict_rule[key] + str(value) + "hg3535" + str(match_id)
  963. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  964. odds_only = Helper.genearte_MD5(hash_str, pt)
  965. sole = Helper.genearte_MD5(sole_str, pt)
  966. horn_ou_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  967. "condition", "odds_only", "sole", "source", "type", "team"]
  968. horn_ou_value = [match_id, league_id, key, "0", 0, p_code, value, horn_ou_dict_rule[key],
  969. odds_only, sole, "hg3535", "0", ""]
  970. horn_ou_data = dict(zip(horn_ou_key, horn_ou_value))
  971. data_list.append(horn_ou_data)
  972. if horn_oe_dict:
  973. for key, value in horn_oe_dict.items():
  974. hash_str = p_code + key + '0' + horn_oe_dict_rule[key] + str(value) + "hg3535" + str(match_id)
  975. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  976. odds_only = Helper.genearte_MD5(hash_str, pt)
  977. sole = Helper.genearte_MD5(sole_str, pt)
  978. horn_oe_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  979. "condition", "odds_only", "sole", "source", "type", "team"]
  980. horn_oe_value = [match_id, league_id, key, "0", 0, p_code, value, horn_oe_dict_rule[key],
  981. odds_only, sole, "hg3535", "0", ""]
  982. horn_oe_data = dict(zip(horn_oe_key, horn_oe_value))
  983. data_list.append(horn_oe_data)
  984. odds_key = ["game_code", "title", "match_id", "lg_id", "data", "source", "odds_only", "tag", "uuid",
  985. "is_stringscene", "utime", "pt"]
  986. odds_value = ["zq", "odds", match_id, league_id, data_list, "hg3535", odds_onlys, number, uuid,
  987. 0, utime, pt]
  988. odds_dict = dict(zip(odds_key, odds_value))
  989. if data_list:
  990. res = Helper.async_post(ODDS_URL, odds_dict)
  991. if res:
  992. if "成功" in res:
  993. logger.info('足球滚球, 角球详细赔率提交成功, {}'.format(res))
  994. logger.info(odds_dict)
  995. else:
  996. logger.warning('足球滚球, 角球详细赔率提交失败, {}'.format(res))
  997. logger.warning(odds_dict)
  998. else:
  999. logger.warning('足球滚球, 角球详细赔率接口异常,提交失败, {}'.format(res))
  1000. logger.warning(odds_dict)
  1001. else:
  1002. logger.info('足球滚球, 角球详细赔率列表为空')
  1003. data_list = []
  1004. zq_rball = {"home_team": team_home, "guest_team": team_guest,
  1005. "lg_id": league_id, "home_rate": 0,
  1006. "guest_rate": 0, "home_score": horn_scoreh,
  1007. "guest_score": horn_scoreg, "all_goal": all_goal, "status": 1,
  1008. "first_score": "", "last_score": "", "match_score": match_score, "uuid": uuid,
  1009. "match_winer": "", "match_time": time_game,
  1010. "match_process": half_way, "tag": number,
  1011. "match_id": match_id, "p_code": ""}
  1012. data_list.append(zq_rball)
  1013. r_data_dict = {
  1014. "game_code": "zq",
  1015. "title": "match_result_r",
  1016. "source": "hg3535",
  1017. "data": data_list
  1018. }
  1019. if data_list:
  1020. try:
  1021. res = Helper.async_post(MATCH_RESULT, r_data_dict)
  1022. if res:
  1023. if "成功" in res:
  1024. logger.info('足球滚球, 角球结果记录提交成功, {}'.format(res))
  1025. logger.info(r_data_dict)
  1026. else:
  1027. logger.warning('足球滚球, 角球结果记录提交失败, {}'.format(res))
  1028. logger.warning(r_data_dict)
  1029. else:
  1030. logger.warning('足球滚球, 角球结果记录接口异常,提交失败, {}'.format(res))
  1031. logger.warning(r_data_dict)
  1032. except Exception as e:
  1033. logger.warning('滚球数据接口异常, 角球结果提交失败, {}'.format(e))
  1034. reactor.callFromThread(out.callback, item)