roll_zuqiu.py 68 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116
  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. # half_size_guest
  612. for index, value in enumerate(half_size_guest):
  613. hash_str = p_code + "gss_h" + str(index) + str(half_size_guest_rule[index]) + str(
  614. value) + "hg3535" + str(match_id)
  615. sole_str = p_code + "gss_h" + str(index) + str(match_id) + "hg3535"
  616. odds_only = Helper.genearte_MD5(hash_str, pt)
  617. sole = Helper.genearte_MD5(sole_str, pt)
  618. half_size_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  619. "odds_only", "sole", "source", "type", "team"]
  620. condition = half_size_guest_rule[index]
  621. half_size_guest_value = [match_id, league_id, "gss_h", "0", index, p_code, value, condition,
  622. odds_only, sole, "hg3535", "0", ""]
  623. half_size_guest_data = dict(zip(half_size_guest_key, half_size_guest_value))
  624. data_list.append(half_size_guest_data)
  625. # half_size_home
  626. for index, value in enumerate(half_size_home):
  627. hash_str = p_code + "gsb_h" + str(index) + str(half_size_home_rule[index]) + str(
  628. value) + "hg3535" + str(match_id)
  629. sole_str = p_code + "gsb_h" + str(index) + str(match_id) + "hg3535"
  630. odds_only = Helper.genearte_MD5(hash_str, pt)
  631. sole = Helper.genearte_MD5(sole_str, pt)
  632. half_size_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  633. "odds_only", "sole", "source", "type", "team"]
  634. condition = half_size_home_rule[index]
  635. half_size_home_value = [match_id, league_id, "gsb_h", "0", index, p_code, value, condition,
  636. odds_only, sole, "hg3535", "0", ""]
  637. half_size_home_data = dict(zip(half_size_home_key, half_size_home_value))
  638. data_list.append(half_size_home_data)
  639. # 全场场大小
  640. size_guest = item["size_guest"]
  641. size_guest_rule = item["size_guest_rule"]
  642. size_home = item["size_home"]
  643. size_home_rule = item["size_home_rule"]
  644. # size_home
  645. for index, value in enumerate(size_home):
  646. hash_str = p_code + "gsb" + str(index) + str(size_home_rule[index]) + str(value) + "hg3535" + str(
  647. match_id)
  648. sole_str = p_code + "gsb" + str(index) + str(match_id) + "hg3535"
  649. odds_only = Helper.genearte_MD5(hash_str, pt)
  650. sole = Helper.genearte_MD5(sole_str, pt)
  651. size_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  652. "odds_only", "sole", "source", "type", "team"]
  653. condition = size_home_rule[index]
  654. size_home_value = [match_id, league_id, "gsb", "0", index, p_code, value, condition, odds_only,
  655. sole, "hg3535", "0", ""]
  656. size_home_data = dict(zip(size_home_key, size_home_value))
  657. data_list.append(size_home_data)
  658. # size_guest
  659. for index, value in enumerate(size_guest):
  660. hash_str = p_code + "gss" + str(index) + str(size_guest_rule[index]) + str(value) + "hg3535" + str(
  661. match_id)
  662. sole_str = p_code + "gss" + str(index) + str(match_id) + "hg3535"
  663. odds_only = Helper.genearte_MD5(hash_str, pt)
  664. sole = Helper.genearte_MD5(sole_str, pt)
  665. size_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  666. "odds_only", "sole", "source", "type", "team"]
  667. condition = size_guest_rule[index]
  668. size_guest_value = [match_id, league_id, "gss", "0", index, p_code, value, condition, odds_only,
  669. sole, "hg3535", "0", ""]
  670. size_home_data = dict(zip(size_guest_key, size_guest_value))
  671. data_list.append(size_home_data)
  672. p_code = 'CO'
  673. half_concede_home_rule = item["half_concede_home_rule"]
  674. half_concede_home = item["half_concede_home"]
  675. half_concede_guest_rule = item["half_concede_guest_rule"]
  676. half_concede_guest = item["half_concede_guest"]
  677. # half_concede_home
  678. for index, value in enumerate(half_concede_guest):
  679. hash_str = p_code + "cog_h" + str(index) + str(half_concede_guest_rule[index]) + str(
  680. value) + "hg3535" + str(match_id)
  681. sole_str = p_code + "cog_h" + str(index) + str(match_id) + "hg3535"
  682. odds_only = Helper.genearte_MD5(hash_str, pt)
  683. sole = Helper.genearte_MD5(sole_str, pt)
  684. half_concede_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  685. "odds_only", "sole", "source", "type", "team"]
  686. condition = half_concede_guest_rule[index]
  687. half_concede_guest_value = [match_id, league_id, "cog_h", "0", index, p_code, value, condition,
  688. odds_only, sole, "hg3535", "0", ""]
  689. half_concede_guest_data = dict(zip(half_concede_guest_key, half_concede_guest_value))
  690. data_list.append(half_concede_guest_data)
  691. # half_concede_home
  692. for index, value in enumerate(half_concede_home):
  693. hash_str = p_code + "coh_h" + str(index) + str(half_concede_home_rule[index]) + str(
  694. value) + "hg3535" + str(match_id)
  695. sole_str = p_code + "coh_h" + str(index) + str(match_id) + "hg3535"
  696. odds_only = Helper.genearte_MD5(hash_str, pt)
  697. sole = Helper.genearte_MD5(sole_str, pt)
  698. half_concede_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  699. "odds_only", "sole", "source", "type", "team"]
  700. condition = half_concede_home_rule[index]
  701. half_concede_home_value = [match_id, league_id, "coh_h", "0", index, p_code, value, condition,
  702. odds_only, sole, "hg3535", "0", ""]
  703. half_concede_home_data = dict(zip(half_concede_home_key, half_concede_home_value))
  704. data_list.append(half_concede_home_data)
  705. concede_guest = item["concede_guest"]
  706. concede_guest_rule = item["concede_guest_rule"]
  707. concede_home = item["concede_home"]
  708. concede_home_rule = item["concede_home_rule"]
  709. # concede_guest
  710. for index, value in enumerate(concede_guest):
  711. hash_str = p_code + "cog" + str(index) + str(concede_guest_rule[index]) + str(
  712. value) + "hg3535" + str(match_id)
  713. sole_str = p_code + "cog" + str(index) + str(match_id) + "hg3535"
  714. odds_only = Helper.genearte_MD5(hash_str, pt)
  715. sole = Helper.genearte_MD5(sole_str, pt)
  716. concede_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  717. "odds_only", "sole", "source", "type", "team"]
  718. condition = concede_guest_rule[index]
  719. concede_guest_value = [match_id, league_id, "cog", "0", index, p_code, value, condition,
  720. odds_only, sole, "hg3535", "0", ""]
  721. concede_guest_data = dict(zip(concede_guest_key, concede_guest_value))
  722. data_list.append(concede_guest_data)
  723. # concede_home
  724. for index, value in enumerate(concede_home):
  725. hash_str = p_code + "coh" + str(index) + str(concede_home_rule[index]) + str(
  726. value) + "hg3535" + str(match_id)
  727. sole_str = p_code + "coh" + str(index) + str(match_id) + "hg3535"
  728. odds_only = Helper.genearte_MD5(hash_str, pt)
  729. sole = Helper.genearte_MD5(sole_str, pt)
  730. concede_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  731. "odds_only", "sole", "source", "type", "team"]
  732. condition = concede_home_rule[index]
  733. concede_home_value = [match_id, league_id, "coh", "0", index, p_code, value, condition, odds_only,
  734. sole, "hg3535", "0", ""]
  735. concede_guest_data = dict(zip(concede_home_key, concede_home_value))
  736. data_list.append(concede_guest_data)
  737. # 独赢-------------------------------------------------------------------------------------------------------
  738. p_code = 'C'
  739. half_capot_home = item["half_capot_home"]
  740. half_capot_guest = item["half_capot_guest"]
  741. half_capot_dogfall = item["half_capot_dogfall"]
  742. capot_home = item["capot_home"]
  743. capot_guest = item["capot_guest"]
  744. capot_dogfall = item["capot_dogfall"]
  745. # half_capot_home
  746. hash_str = p_code + "ch_h" + '0' + '1' + str(half_capot_home) + "hg3535" + str(match_id)
  747. sole_str = p_code + "ch_h" + '0' + str(match_id) + "hg3535"
  748. odds_only = Helper.genearte_MD5(hash_str, pt)
  749. sole = Helper.genearte_MD5(sole_str, pt)
  750. half_capot_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  751. "odds_only", "sole", "source", "type", "team"]
  752. half_capot_home_value = [match_id, league_id, "ch_h", "0", 0, p_code, half_capot_home, '1',
  753. odds_only, sole, "hg3535", "0", ""]
  754. half_capot_homet_data = dict(zip(half_capot_home_key, half_capot_home_value))
  755. data_list.append(half_capot_homet_data)
  756. # half_capot_guest
  757. hash_str = p_code + "cg_h" + '0' + '2' + str(half_capot_guest) + "hg3535" + str(match_id)
  758. sole_str = p_code + "cg_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_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  762. "odds_only", "sole", "source", "type", "team"]
  763. half_capot_guest_value = [match_id, league_id, "cg_h", "0", 0, p_code, half_capot_guest, '2',
  764. odds_only, sole, "hg3535", "0", ""]
  765. half_capot_guest_data = dict(zip(half_capot_guest_key, half_capot_guest_value))
  766. data_list.append(half_capot_guest_data)
  767. # half_capot_dogfall
  768. hash_str = p_code + "cd_h" + '0' + 'X' + str(half_capot_dogfall) + "hg3535" + str(match_id)
  769. sole_str = p_code + "cd_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_dogfall_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  773. "odds_only", "sole", "source", "type", "team"]
  774. half_capot_dogfall_value = [match_id, league_id, "cd_h", "0", 0, p_code, half_capot_dogfall, 'X',
  775. odds_only, sole, "hg3535", "0", ""]
  776. half_capot_dogfall_data = dict(zip(half_capot_dogfall_key, half_capot_dogfall_value))
  777. data_list.append(half_capot_dogfall_data)
  778. # capot_dogfall
  779. hash_str = p_code + "cd" + '0' + 'X' + str(capot_dogfall) + "hg3535" + str(match_id)
  780. sole_str = p_code + "cd" + '0' + str(match_id) + "hg3535"
  781. odds_only = Helper.genearte_MD5(hash_str, pt)
  782. sole = Helper.genearte_MD5(sole_str, pt)
  783. capot_dogfall_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  784. "odds_only", "sole", "source", "type", "team"]
  785. capot_dogfall_value = [match_id, league_id, "cd", "0", 0, p_code, capot_dogfall, 'X', odds_only,
  786. sole, "hg3535", "0", ""]
  787. capot_dogfall_data = dict(zip(capot_dogfall_key, capot_dogfall_value))
  788. data_list.append(capot_dogfall_data)
  789. # capot_home
  790. hash_str = p_code + "ch" + '0' + '1' + str(capot_home) + "hg3535" + str(match_id)
  791. sole_str = p_code + "ch" + '0' + str(match_id) + "hg3535"
  792. odds_only = Helper.genearte_MD5(hash_str, pt)
  793. sole = Helper.genearte_MD5(sole_str, pt)
  794. capot_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  795. "odds_only", "sole", "source", "type", "team"]
  796. capot_home_value = [match_id, league_id, "ch", "0", 0, p_code, capot_home, '1',
  797. odds_only, sole, "hg3535", "0", ""]
  798. capot_homet_data = dict(zip(capot_home_key, capot_home_value))
  799. data_list.append(capot_homet_data)
  800. # capot_guest
  801. hash_str = p_code + "cg" + '0' + '2' + str(capot_guest) + "hg3535" + str(match_id)
  802. sole_str = p_code + "cg" + '0' + str(match_id) + "hg3535"
  803. odds_only = Helper.genearte_MD5(hash_str, pt)
  804. sole = Helper.genearte_MD5(sole_str, pt)
  805. capot_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  806. "odds_only", "sole", "source", "type", "team"]
  807. capot_guest_value = [match_id, league_id, "cg", "0", 0, p_code, capot_guest, '2',
  808. odds_only, sole, "hg3535", "0", ""]
  809. capot_guest_data = dict(zip(capot_guest_key, capot_guest_value))
  810. data_list.append(capot_guest_data)
  811. # 入球数单双--------------------------------------------------------------------------------------------------
  812. p_code = 'TS'
  813. odd_even_odd = item["odd_even_odd"]
  814. odd_even_even = item["odd_even_even"]
  815. half_odd_even_odd = item["half_odd_even_odd"]
  816. half_odd_even_even = item["half_odd_even_even"]
  817. # odd_even_odd
  818. hash_str = p_code + "tss" + '0' + '单' + str(odd_even_odd) + "hg3535" + str(match_id)
  819. sole_str = p_code + "tss" + '0' + str(match_id) + "hg3535"
  820. odds_only = Helper.genearte_MD5(hash_str, pt)
  821. sole = Helper.genearte_MD5(sole_str, pt)
  822. single_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  823. "odds_only", "sole", "source", "type", "team"]
  824. single_value = [match_id, league_id, "tss", "0", 0, p_code, odd_even_odd, '单',
  825. odds_only, sole, "hg3535", "0", ""]
  826. single_data = dict(zip(single_key, single_value))
  827. data_list.append(single_data)
  828. # odd_even_even
  829. hash_str = p_code + "tsd" + '0' + '双' + str(odd_even_even) + "hg3535" + str(match_id)
  830. sole_str = p_code + "tsd" + '0' + str(match_id) + "hg3535"
  831. odds_only = Helper.genearte_MD5(hash_str, pt)
  832. sole = Helper.genearte_MD5(sole_str, pt)
  833. double_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  834. "odds_only", "sole", "source", "type", "team"]
  835. double_value = [match_id, league_id, "tsd", "0", 0, p_code, odd_even_even, '双',
  836. odds_only, sole, "hg3535", "0", ""]
  837. double_data = dict(zip(double_key, double_value))
  838. data_list.append(double_data)
  839. # half_odd_even_even
  840. hash_str = p_code + "tsd_h" + '0' + '双' + str(half_odd_even_even) + "hg3535" + str(match_id)
  841. sole_str = p_code + "tsd_h" + '0' + str(match_id) + "hg3535"
  842. odds_only = Helper.genearte_MD5(hash_str, pt)
  843. sole = Helper.genearte_MD5(sole_str, pt)
  844. half_double_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  845. "odds_only", "sole", "source", "type", "team"]
  846. half_double_value = [match_id, league_id, "tsd_h", "0", 0, p_code, half_odd_even_even, '双',
  847. odds_only, sole, "hg3535", "0", ""]
  848. half_double_data = dict(zip(half_double_key, half_double_value))
  849. data_list.append(half_double_data)
  850. # half_odd_even_odd
  851. hash_str = p_code + "tss_h" + '0' + '单' + str(half_odd_even_odd) + "hg3535" + str(match_id)
  852. sole_str = p_code + "tss_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_single_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  856. "odds_only", "sole", "source", "type", "team"]
  857. half_single_value = [match_id, league_id, "tss_h", "0", 0, p_code, half_odd_even_odd, '单', odds_only,
  858. sole, "hg3535", "0", ""]
  859. half_single_data = dict(zip(half_single_key, half_single_value))
  860. data_list.append(half_single_data)
  861. p_code = 'TG'
  862. # 总入球数 ---------------------------------------------------------------------------------------------------
  863. total_goals = item['total_goal']
  864. total_dict = {'tg0': '0-1', 'tg1': '2-3', 'tg2': '4-6', 'tg3': '7或以上', 'tg0_h': '0', "tg1_h": '1',
  865. "tg2_h": '2', "tg3_h": '3或以上'}
  866. # 全场入球数 单双
  867. for key, value in total_goals.items():
  868. hash_str = p_code + key + '0' + total_dict[key] + str(value) + "hg3535" + str(match_id)
  869. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  870. odds_only = Helper.genearte_MD5(hash_str, pt)
  871. sole = Helper.genearte_MD5(sole_str, pt)
  872. total_goals_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  873. "odds_only", "sole", "source", "type", "team"]
  874. total_goals_value = [match_id, league_id, key, "0", 0, p_code, value, total_dict[key], odds_only,
  875. sole, "hg3535", "0", ""]
  876. total_goals_data = dict(zip(total_goals_key, total_goals_value))
  877. data_list.append(total_goals_data)
  878. # 全场半场 ---------------------------------------------------------------------------------------------------
  879. half_fulls = item['half_full']
  880. # p_code, p_id = get_pcode(corner_ball, 'half_full')
  881. p_code = 'HF'
  882. full_dict = {"hfhh": "主主", "hfhd": "主和", "hfhg": "主客", "hfdh": "和主",
  883. "hfdd": "和和", "hfdg": "和客", "hfgh": "客主", "hfgd": "客和", "hfgg": "客客"}
  884. if half_fulls:
  885. for key, value in half_fulls.items():
  886. hash_str = p_code + key + '0' + full_dict[key] + str(value) + "hg3535" + str(match_id)
  887. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  888. odds_only = Helper.genearte_MD5(hash_str, pt)
  889. sole = Helper.genearte_MD5(sole_str, pt)
  890. half_fulls_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  891. "odds_only", "sole", "source", "type", "team"]
  892. half_fulls_value = [match_id, league_id, key, "0", 0, p_code, value, full_dict[key], odds_only,
  893. sole, "hg3535", "0", ""]
  894. half_fulls_data = dict(zip(half_fulls_key, half_fulls_value))
  895. data_list.append(half_fulls_data)
  896. # 波胆-------------------------------------------------------------------------------------------------------
  897. p_code = 'B'
  898. bodan_datas = item['bodan_data']
  899. # p_code, p_id = get_pcode(corner_ball, 'bodan')
  900. bodan_dict = {"b10": "1-0", "b20": "2-0", "b21": "2-1", "b30": "3-0", "b31": "3-1", "b32": "3-2",
  901. "b40": "4-0", "b41": "4-1", "b42": "4-2", "b43": "4-3", "b01": "0-1", "b02": "0-2",
  902. "b12": "1-2", "b03": "0-3", "b13": "1-3", "b23": "2-3", "b04": "0-4", "b14": "1-4",
  903. "b24": "2-4", "b34": "3-4", "b00": "0-0", "b11": "1-1", "b22": "2-2", "b33": "3-3",
  904. "b44": "4-4", "bo": "其他", "b10_h": "1-0", "b20_h": "2-0", "b21_h": "2-1", "b30_h": "3-0",
  905. "b31_h": "3-1", "b32_h": "3-2", "b01_h": "0-1", "b02_h": "0-2", "b12_h": "1-2", "b03_h": "0-3",
  906. "b13_h": "1-3", "b23_h": "2-3", "b00_h": "0-0", "b11_h": "1-1", "b22_h": "2-2", "b33_h": "3-3",
  907. "bo_h": "其他"}
  908. if bodan_datas:
  909. for key, value in bodan_datas.items():
  910. hash_str = p_code + key + '0' + bodan_dict[key] + str(value) + "hg3535" + str(match_id)
  911. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  912. odds_only = Helper.genearte_MD5(hash_str, pt)
  913. sole = Helper.genearte_MD5(sole_str, pt)
  914. bodan_dict_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  915. "odds_only", "sole", "source", "type", "team"]
  916. bodan_dict_value = [match_id, league_id, key, "0", 0, p_code, value, bodan_dict[key], odds_only,
  917. sole, "hg3535", "0", ""]
  918. bodan_dict_data = dict(zip(bodan_dict_key, bodan_dict_value))
  919. data_list.append(bodan_dict_data)
  920. # 最先进球/最后进球 -------------------------------------------------------------------------------------------
  921. first_last_balls = item['first_last_ball']
  922. p_code = 'FLB'
  923. first_last_dict = {"flbfh": "最先进球", "flbfg": "最先进球", "flblh": "最后进球", "flblg": "最后进球", "flbn": "没有进球"}
  924. if first_last_balls:
  925. for key, value in first_last_balls.items():
  926. hash_str = p_code + key + '0' + first_last_dict[key] + str(value) + "hg3535" + str(match_id)
  927. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  928. odds_only = Helper.genearte_MD5(hash_str, pt)
  929. sole = Helper.genearte_MD5(sole_str, pt)
  930. first_last_balls_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  931. "condition",
  932. "odds_only", "sole", "source", "type", "team"]
  933. first_last_balls_value = [match_id, league_id, key, "0", 0, p_code, value, first_last_dict[key],
  934. odds_only,
  935. sole, "hg3535", "0", ""]
  936. first_last_balls_data = dict(zip(first_last_balls_key, first_last_balls_value))
  937. data_list.append(first_last_balls_data)
  938. p_code = 'TB'
  939. # 球队得分全场,上半场
  940. full_dicts = item['full_data']
  941. half_dicts = item['half_data']
  942. full_dict_rules = item['full_data_rule']
  943. half_dict_rules = item['half_data_rule']
  944. if full_dicts:
  945. for key, value in full_dicts.items():
  946. hash_str = p_code + key + '0' + full_dict_rules[key] + str(value) + "hg3535" + str(match_id)
  947. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  948. odds_only = Helper.genearte_MD5(hash_str, pt)
  949. sole = Helper.genearte_MD5(sole_str, pt)
  950. full_dict_rules_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  951. "condition", "odds_only", "sole", "source", "type", "team"]
  952. full_dict_rules_value = [match_id, league_id, key, "0", 0, p_code, value, full_dict_rules[key],
  953. odds_only, sole, "hg3535", "0", ""]
  954. full_dict_rules_data = dict(zip(full_dict_rules_key, full_dict_rules_value))
  955. data_list.append(full_dict_rules_data)
  956. if half_dicts:
  957. for key, value in half_dicts.items():
  958. hash_str = p_code + key + '0' + half_dict_rules[key] + str(value) + "hg3535" + str(match_id)
  959. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  960. odds_only = Helper.genearte_MD5(hash_str, pt)
  961. sole = Helper.genearte_MD5(sole_str, pt)
  962. half_dicts_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  963. "condition", "odds_only", "sole", "source", "type", "team"]
  964. half_dicts_value = [match_id, league_id, key, "0", 0, p_code, value, half_dict_rules[key],
  965. odds_only, sole, "hg3535", "0", ""]
  966. half_dicts_data = dict(zip(half_dicts_key, half_dicts_value))
  967. data_list.append(half_dicts_data)
  968. p_code = 'CB'
  969. horn_ou_dict = item['horn_ou_dict']
  970. horn_ou_dict_rule = item['horn_ou_dict_rule']
  971. horn_oe_dict = item['horn_oe_dict']
  972. horn_oe_dict_rule = item['horn_oe_dict_rule']
  973. if horn_ou_dict:
  974. for key, value in horn_ou_dict.items():
  975. hash_str = p_code + key + '0' + horn_ou_dict_rule[key] + str(value) + "hg3535" + str(match_id)
  976. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  977. odds_only = Helper.genearte_MD5(hash_str, pt)
  978. sole = Helper.genearte_MD5(sole_str, pt)
  979. horn_ou_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  980. "condition", "odds_only", "sole", "source", "type", "team"]
  981. horn_ou_value = [match_id, league_id, key, "0", 0, p_code, value, horn_ou_dict_rule[key],
  982. odds_only, sole, "hg3535", "0", ""]
  983. horn_ou_data = dict(zip(horn_ou_key, horn_ou_value))
  984. data_list.append(horn_ou_data)
  985. if horn_oe_dict:
  986. for key, value in horn_oe_dict.items():
  987. hash_str = p_code + key + '0' + horn_oe_dict_rule[key] + str(value) + "hg3535" + str(match_id)
  988. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  989. odds_only = Helper.genearte_MD5(hash_str, pt)
  990. sole = Helper.genearte_MD5(sole_str, pt)
  991. horn_oe_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  992. "condition", "odds_only", "sole", "source", "type", "team"]
  993. horn_oe_value = [match_id, league_id, key, "0", 0, p_code, value, horn_oe_dict_rule[key],
  994. odds_only, sole, "hg3535", "0", ""]
  995. horn_oe_data = dict(zip(horn_oe_key, horn_oe_value))
  996. data_list.append(horn_oe_data)
  997. odds_key = ["game_code", "title", "match_id", "lg_id", "data", "source", "odds_only", "tag", "uuid",
  998. "is_stringscene", "utime", "pt"]
  999. odds_value = ["zq", "odds", match_id, league_id, data_list, "hg3535", odds_onlys, number, uuid,
  1000. 0, utime, pt]
  1001. odds_dict = dict(zip(odds_key, odds_value))
  1002. if data_list:
  1003. res = Helper.async_post(ODDS_URL, odds_dict)
  1004. if res:
  1005. if res.get('status') == 1:
  1006. logger.info('足球滚球, 角球详细赔率提交成功, {}'.format(res))
  1007. logger.info(odds_dict)
  1008. else:
  1009. logger.warning('足球滚球, 角球详细赔率提交失败, {}'.format(res))
  1010. logger.warning(odds_dict)
  1011. else:
  1012. logger.warning('足球滚球, 角球详细赔率接口异常,提交失败, {}'.format(res))
  1013. logger.warning(odds_dict)
  1014. else:
  1015. logger.info('足球滚球, 角球详细赔率列表为空')
  1016. data_list = []
  1017. zq_rball = {"home_team": team_home, "guest_team": team_guest,
  1018. "lg_id": league_id, "home_rate": 0,
  1019. "guest_rate": 0, "home_score": horn_scoreh,
  1020. "guest_score": horn_scoreg, "all_goal": all_goal, "status": 1,
  1021. "first_score": "", "last_score": "", "match_score": match_score, "uuid": uuid,
  1022. "match_winer": "", "match_time": time_game,
  1023. "match_process": half_way, "tag": number,
  1024. "match_id": match_id, "p_code": ""}
  1025. data_list.append(zq_rball)
  1026. r_data_dict = {
  1027. "game_code": "zq",
  1028. "title": "match_result_r",
  1029. "source": "hg3535",
  1030. "data": data_list
  1031. }
  1032. if data_list:
  1033. try:
  1034. res = Helper.async_post(MATCH_RESULT, r_data_dict)
  1035. if res:
  1036. if res.get('status') == 1:
  1037. logger.info('足球滚球, 角球结果记录提交成功, {}'.format(res))
  1038. self.db.zq_match_result35.insert(zq_rball)
  1039. logger.info(r_data_dict)
  1040. else:
  1041. logger.warning('足球滚球, 角球结果记录提交失败, {}'.format(res))
  1042. logger.warning(r_data_dict)
  1043. else:
  1044. logger.warning('足球滚球, 角球结果记录接口异常,提交失败, {}'.format(res))
  1045. logger.warning(r_data_dict)
  1046. except Exception as e:
  1047. logger.warning('滚球数据接口异常, 角球结果提交失败, {}'.format(e))
  1048. reactor.callFromThread(out.callback, item)