roll_zuqiu.py 69 KB

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