roll_zuqiu.py 69 KB

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