roll_zuqiu.py 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  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. # try:
  30. # data_game = item['data_game'].split("/")
  31. # month = str(data_game[1].strip())
  32. # day = str(data_game[0]).strip()
  33. # except Exception as e:
  34. # logger.warning(e)
  35. # data_game = item['data_game'].split(" ")
  36. # months = str(data_game[1].strip())
  37. # month_dict = {'Jan': '01', 'Feb': '02', 'Mar': '03', 'Apr': '04', 'May': '05', 'Jun': '06', 'Jul': '07',
  38. # 'Aug': '08', 'Sep': '09', 'Oct': '10', 'Nov': '11', 'Dec': '12'}
  39. # month = month_dict[months]
  40. # day = str(data_game[0]).strip()
  41. # us_date = '{}-{}-{}'.format(datetime.datetime.now().year, month, day)
  42. match_date = cdate.split(' ')[0]
  43. match_time = cdate.split(' ')[1]
  44. # 比赛id
  45. match_id = item['game_id']
  46. # 联赛id
  47. league_id = item['league_id']
  48. # 联赛name
  49. league_name = item['league_name']
  50. # 主队
  51. team_home = item['team_home']
  52. # 客队
  53. team_guest = item['team_guest']
  54. # number
  55. number = item['number']
  56. score_home = item['score_home']
  57. score_guest = item['score_guest']
  58. all_goal = int(score_home) + int(score_guest)
  59. half_way = item['half_way']
  60. match_score = "{}:{}".format(score_home, score_guest)
  61. last_time = '{}-12-31 23:59:59'.format(datetime.datetime.now().year)
  62. league_list = []
  63. uuid = Helper.genearte_uuid(league_name)
  64. # horn_team = item['horn_team']
  65. if self.db.zq_league35.find({'lg_id': league_id}).count() < 1:
  66. league_dict = {"game_code": "zq", "title": "league", "source": "hg3535"}
  67. league_key = ["name_chinese", "kind", "match_mode", "if_stop", "last_time", "lg_id", "source", "uuid"]
  68. league_value = [league_name, "1", "1", "0", last_time, league_id, "hg3535", uuid]
  69. league_data = dict(zip(league_key, league_value))
  70. league_list.append(league_data)
  71. league_dict['data'] = league_list
  72. res = Helper.async_post(LEAGUE_URL, league_dict)
  73. if res:
  74. if res.get('status') == 1:
  75. self.db.zq_league35.insert(league_data)
  76. logger.info('足球滚球联赛提交成功, {}'.format(res))
  77. logger.info(league_dict)
  78. else:
  79. logger.warning('足球滚球联赛提交失败, {}'.format(res))
  80. logger.warning(league_dict)
  81. else:
  82. logger.warning('足球滚球联赛接口异常提交失败, {}'.format(res))
  83. logger.warning(league_dict)
  84. else:
  85. logger.info('足球滚球联赛已存在, 不存在')
  86. match_identity = Helper.genearte_uuid(team_home + team_guest + match_date)
  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", 'match_identity']
  93. match_value = [team_home, team_guest, league_id, 1, match_id, match_date, match_time, number,
  94. "hg3535", 1, 0, 0, utime, uuid, 0, 0, 0, match_identity]
  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 res.get('status') == 1:
  101. self.db.zq_competition35.insert(match_data)
  102. logger.info('足球滚球赛事提交成功, {}'.format(res))
  103. # logger.info(match_data)
  104. else:
  105. logger.warning('足球滚球赛事,提交失败, {}'.format(res))
  106. # logger.warning(match_data)
  107. else:
  108. logger.warning('足球滚球赛事接口异常提交失败, {}'.format(res))
  109. # logger.warning(match_data)
  110. else:
  111. logger.info('足球滚球赛事已存在, 不提交')
  112. p_code = "GS"
  113. # 构建唯一索引
  114. half_size_guest = item["half_size_guest"]
  115. half_size_guest_rule = item["half_size_guest_rule"]
  116. half_size_home = item["half_size_home"]
  117. half_size_home_rule = item["half_size_home_rule"]
  118. data_list = []
  119. odds_onlys = []
  120. # half_size_guest
  121. for index, value in enumerate(half_size_guest):
  122. hash_str = p_code + "gss_h" + str(index) + str(half_size_guest_rule[index]) + str(
  123. value) + "hg3535" + str(match_id)
  124. sole_str = p_code + "gss_h" + str(index) + str(match_id) + "hg3535"
  125. odds_only = Helper.genearte_MD5(hash_str, pt)
  126. sole = Helper.genearte_MD5(sole_str, pt)
  127. half_size_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  128. "odds_only", "sole", "source", "type", "team"]
  129. condition = half_size_guest_rule[index]
  130. half_size_guest_value = [match_id, league_id, "gss_h", "0", index, p_code, value, condition,
  131. odds_only, sole, "hg3535", "0", ""]
  132. half_size_guest_data = dict(zip(half_size_guest_key, half_size_guest_value))
  133. data_list.append(half_size_guest_data)
  134. # half_size_home
  135. for index, value in enumerate(half_size_home):
  136. hash_str = p_code + "gsb_h" + str(index) + str(half_size_home_rule[index]) + str(
  137. value) + "hg3535" + str(match_id)
  138. sole_str = p_code + "gsb_h" + str(index) + str(match_id) + "hg3535"
  139. odds_only = Helper.genearte_MD5(hash_str, pt)
  140. sole = Helper.genearte_MD5(sole_str, pt)
  141. half_size_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  142. "odds_only", "sole", "source", "type", "team"]
  143. condition = half_size_home_rule[index]
  144. half_size_home_value = [match_id, league_id, "gsb_h", "0", index, p_code, value, condition,
  145. odds_only, sole, "hg3535", "0", ""]
  146. half_size_home_data = dict(zip(half_size_home_key, half_size_home_value))
  147. data_list.append(half_size_home_data)
  148. # 全场场大小
  149. size_guest = item["size_guest"]
  150. size_guest_rule = item["size_guest_rule"]
  151. size_home = item["size_home"]
  152. size_home_rule = item["size_home_rule"]
  153. # size_home
  154. for index, value in enumerate(size_home):
  155. hash_str = p_code + "gsb" + str(index) + str(size_home_rule[index]) + str(value) + "hg3535" + str(
  156. match_id)
  157. sole_str = p_code + "gsb" + str(index) + str(match_id) + "hg3535"
  158. odds_only = Helper.genearte_MD5(hash_str, pt)
  159. sole = Helper.genearte_MD5(sole_str, pt)
  160. size_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  161. "odds_only", "sole", "source", "type", "team"]
  162. condition = size_home_rule[index]
  163. size_home_value = [match_id, league_id, "gsb", "0", index, p_code, value, condition, odds_only,
  164. sole, "hg3535", "0", ""]
  165. size_home_data = dict(zip(size_home_key, size_home_value))
  166. data_list.append(size_home_data)
  167. # size_guest
  168. for index, value in enumerate(size_guest):
  169. hash_str = p_code + "gss" + str(index) + str(size_guest_rule[index]) + str(value) + "hg3535" + str(
  170. match_id)
  171. sole_str = p_code + "gss" + str(index) + str(match_id) + "hg3535"
  172. odds_only = Helper.genearte_MD5(hash_str, pt)
  173. sole = Helper.genearte_MD5(sole_str, pt)
  174. size_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  175. "odds_only", "sole", "source", "type", "team"]
  176. condition = size_guest_rule[index]
  177. size_guest_value = [match_id, league_id, "gss", "0", index, p_code, value, condition, odds_only,
  178. sole, "hg3535", "0", ""]
  179. size_home_data = dict(zip(size_guest_key, size_guest_value))
  180. data_list.append(size_home_data)
  181. p_code = 'CO'
  182. half_concede_home_rule = item["half_concede_home_rule"]
  183. half_concede_home = item["half_concede_home"]
  184. half_concede_guest_rule = item["half_concede_guest_rule"]
  185. half_concede_guest = item["half_concede_guest"]
  186. # half_concede_home
  187. for index, value in enumerate(half_concede_guest):
  188. hash_str = p_code + "cog_h" + str(index) + str(half_concede_guest_rule[index]) + str(
  189. value) + "hg3535" + str(match_id)
  190. sole_str = p_code + "cog_h" + str(index) + str(match_id) + "hg3535"
  191. odds_only = Helper.genearte_MD5(hash_str, pt)
  192. sole = Helper.genearte_MD5(sole_str, pt)
  193. half_concede_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  194. "odds_only", "sole", "source", "type", "team"]
  195. condition = half_concede_guest_rule[index]
  196. half_concede_guest_value = [match_id, league_id, "cog_h", "0", index, p_code, value, condition,
  197. odds_only, sole, "hg3535", "0", ""]
  198. half_concede_guest_data = dict(zip(half_concede_guest_key, half_concede_guest_value))
  199. data_list.append(half_concede_guest_data)
  200. # half_concede_home
  201. for index, value in enumerate(half_concede_home):
  202. hash_str = p_code + "coh_h" + str(index) + str(half_concede_home_rule[index]) + str(
  203. value) + "hg3535" + str(match_id)
  204. sole_str = p_code + "coh_h" + str(index) + str(match_id) + "hg3535"
  205. odds_only = Helper.genearte_MD5(hash_str, pt)
  206. sole = Helper.genearte_MD5(sole_str, pt)
  207. half_concede_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  208. "odds_only", "sole", "source", "type", "team"]
  209. condition = half_concede_home_rule[index]
  210. half_concede_home_value = [match_id, league_id, "coh_h", "0", index, p_code, value, condition,
  211. odds_only, sole, "hg3535", "0", ""]
  212. half_concede_home_data = dict(zip(half_concede_home_key, half_concede_home_value))
  213. data_list.append(half_concede_home_data)
  214. concede_guest = item["concede_guest"]
  215. concede_guest_rule = item["concede_guest_rule"]
  216. concede_home = item["concede_home"]
  217. concede_home_rule = item["concede_home_rule"]
  218. # concede_guest
  219. for index, value in enumerate(concede_guest):
  220. hash_str = p_code + "cog" + str(index) + str(concede_guest_rule[index]) + str(
  221. value) + "hg3535" + str(match_id)
  222. sole_str = p_code + "cog" + str(index) + str(match_id) + "hg3535"
  223. odds_only = Helper.genearte_MD5(hash_str, pt)
  224. sole = Helper.genearte_MD5(sole_str, pt)
  225. concede_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  226. "odds_only", "sole", "source", "type", "team"]
  227. condition = concede_guest_rule[index]
  228. concede_guest_value = [match_id, league_id, "cog", "0", index, p_code, value, condition,
  229. odds_only, sole, "hg3535", "0", ""]
  230. concede_guest_data = dict(zip(concede_guest_key, concede_guest_value))
  231. data_list.append(concede_guest_data)
  232. # concede_home
  233. for index, value in enumerate(concede_home):
  234. hash_str = p_code + "coh" + str(index) + str(concede_home_rule[index]) + str(
  235. value) + "hg3535" + str(match_id)
  236. sole_str = p_code + "coh" + str(index) + str(match_id) + "hg3535"
  237. odds_only = Helper.genearte_MD5(hash_str, pt)
  238. sole = Helper.genearte_MD5(sole_str, pt)
  239. concede_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  240. "odds_only", "sole", "source", "type", "team"]
  241. condition = concede_home_rule[index]
  242. concede_home_value = [match_id, league_id, "coh", "0", index, p_code, value, condition, odds_only,
  243. sole, "hg3535", "0", ""]
  244. concede_guest_data = dict(zip(concede_home_key, concede_home_value))
  245. data_list.append(concede_guest_data)
  246. # 独赢-------------------------------------------------------------------------------------------------------
  247. p_code = 'C'
  248. half_capot_home = item["half_capot_home"]
  249. half_capot_guest = item["half_capot_guest"]
  250. half_capot_dogfall = item["half_capot_dogfall"]
  251. capot_home = item["capot_home"]
  252. capot_guest = item["capot_guest"]
  253. capot_dogfall = item["capot_dogfall"]
  254. # half_capot_home
  255. hash_str = p_code + "ch_h" + '0' + '1' + str(half_capot_home) + "hg3535" + str(match_id)
  256. sole_str = p_code + "ch_h" + '0' + str(match_id) + "hg3535"
  257. odds_only = Helper.genearte_MD5(hash_str, pt)
  258. sole = Helper.genearte_MD5(sole_str, pt)
  259. half_capot_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  260. "odds_only", "sole", "source", "type", "team"]
  261. half_capot_home_value = [match_id, league_id, "ch_h", "0", 0, p_code, half_capot_home, '1',
  262. odds_only, sole, "hg3535", "0", ""]
  263. half_capot_homet_data = dict(zip(half_capot_home_key, half_capot_home_value))
  264. data_list.append(half_capot_homet_data)
  265. # half_capot_guest
  266. hash_str = p_code + "cg_h" + '0' + '2' + str(half_capot_guest) + "hg3535" + str(match_id)
  267. sole_str = p_code + "cg_h" + '0' + str(match_id) + "hg3535"
  268. odds_only = Helper.genearte_MD5(hash_str, pt)
  269. sole = Helper.genearte_MD5(sole_str, pt)
  270. half_capot_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  271. "odds_only", "sole", "source", "type", "team"]
  272. half_capot_guest_value = [match_id, league_id, "cg_h", "0", 0, p_code, half_capot_guest, '2',
  273. odds_only, sole, "hg3535", "0", ""]
  274. half_capot_guest_data = dict(zip(half_capot_guest_key, half_capot_guest_value))
  275. data_list.append(half_capot_guest_data)
  276. # half_capot_dogfall
  277. hash_str = p_code + "cd_h" + '0' + 'X' + str(half_capot_dogfall) + "hg3535" + str(match_id)
  278. sole_str = p_code + "cd_h" + '0' + str(match_id) + "hg3535"
  279. odds_only = Helper.genearte_MD5(hash_str, pt)
  280. sole = Helper.genearte_MD5(sole_str, pt)
  281. half_capot_dogfall_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  282. "odds_only", "sole", "source", "type", "team"]
  283. half_capot_dogfall_value = [match_id, league_id, "cd_h", "0", 0, p_code, half_capot_dogfall, 'X',
  284. odds_only, sole, "hg3535", "0", ""]
  285. half_capot_dogfall_data = dict(zip(half_capot_dogfall_key, half_capot_dogfall_value))
  286. data_list.append(half_capot_dogfall_data)
  287. # capot_dogfall
  288. hash_str = p_code + "cd" + '0' + 'X' + str(capot_dogfall) + "hg3535" + str(match_id)
  289. sole_str = p_code + "cd" + '0' + str(match_id) + "hg3535"
  290. odds_only = Helper.genearte_MD5(hash_str, pt)
  291. sole = Helper.genearte_MD5(sole_str, pt)
  292. capot_dogfall_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  293. "odds_only", "sole", "source", "type", "team"]
  294. capot_dogfall_value = [match_id, league_id, "cd", "0", 0, p_code, capot_dogfall, 'X', odds_only,
  295. sole, "hg3535", "0", ""]
  296. capot_dogfall_data = dict(zip(capot_dogfall_key, capot_dogfall_value))
  297. data_list.append(capot_dogfall_data)
  298. # capot_home
  299. hash_str = p_code + "ch" + '0' + '1' + str(capot_home) + "hg3535" + str(match_id)
  300. sole_str = p_code + "ch" + '0' + str(match_id) + "hg3535"
  301. odds_only = Helper.genearte_MD5(hash_str, pt)
  302. sole = Helper.genearte_MD5(sole_str, pt)
  303. capot_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  304. "odds_only", "sole", "source", "type", "team"]
  305. capot_home_value = [match_id, league_id, "ch", "0", 0, p_code, capot_home, '1',
  306. odds_only, sole, "hg3535", "0", ""]
  307. capot_homet_data = dict(zip(capot_home_key, capot_home_value))
  308. data_list.append(capot_homet_data)
  309. # capot_guest
  310. hash_str = p_code + "cg" + '0' + '2' + str(capot_guest) + "hg3535" + str(match_id)
  311. sole_str = p_code + "cg" + '0' + str(match_id) + "hg3535"
  312. odds_only = Helper.genearte_MD5(hash_str, pt)
  313. sole = Helper.genearte_MD5(sole_str, pt)
  314. capot_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  315. "odds_only", "sole", "source", "type", "team"]
  316. capot_guest_value = [match_id, league_id, "cg", "0", 0, p_code, capot_guest, '2',
  317. odds_only, sole, "hg3535", "0", ""]
  318. capot_guest_data = dict(zip(capot_guest_key, capot_guest_value))
  319. data_list.append(capot_guest_data)
  320. # 入球数单双--------------------------------------------------------------------------------------------------
  321. p_code = 'TS'
  322. odd_even_odd = item["odd_even_odd"]
  323. odd_even_even = item["odd_even_even"]
  324. half_odd_even_odd = item["half_odd_even_odd"]
  325. half_odd_even_even = item["half_odd_even_even"]
  326. # odd_even_odd
  327. hash_str = p_code + "tss" + '0' + '单' + str(odd_even_odd) + "hg3535" + str(match_id)
  328. sole_str = p_code + "tss" + '0' + str(match_id) + "hg3535"
  329. odds_only = Helper.genearte_MD5(hash_str, pt)
  330. sole = Helper.genearte_MD5(sole_str, pt)
  331. single_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  332. "odds_only", "sole", "source", "type", "team"]
  333. single_value = [match_id, league_id, "tss", "0", 0, p_code, odd_even_odd, '单',
  334. odds_only, sole, "hg3535", "0", ""]
  335. single_data = dict(zip(single_key, single_value))
  336. data_list.append(single_data)
  337. # odd_even_even
  338. hash_str = p_code + "tsd" + '0' + '双' + str(odd_even_even) + "hg3535" + str(match_id)
  339. sole_str = p_code + "tsd" + '0' + str(match_id) + "hg3535"
  340. odds_only = Helper.genearte_MD5(hash_str, pt)
  341. sole = Helper.genearte_MD5(sole_str, pt)
  342. double_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  343. "odds_only", "sole", "source", "type", "team"]
  344. double_value = [match_id, league_id, "tsd", "0", 0, p_code, odd_even_even, '双',
  345. odds_only, sole, "hg3535", "0", ""]
  346. double_data = dict(zip(double_key, double_value))
  347. data_list.append(double_data)
  348. # half_odd_even_even
  349. hash_str = p_code + "tsd_h" + '0' + '双' + str(half_odd_even_even) + "hg3535" + str(match_id)
  350. sole_str = p_code + "tsd_h" + '0' + str(match_id) + "hg3535"
  351. odds_only = Helper.genearte_MD5(hash_str, pt)
  352. sole = Helper.genearte_MD5(sole_str, pt)
  353. half_double_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  354. "odds_only", "sole", "source", "type", "team"]
  355. half_double_value = [match_id, league_id, "tsd_h", "0", 0, p_code, half_odd_even_even, '双',
  356. odds_only, sole, "hg3535", "0", ""]
  357. half_double_data = dict(zip(half_double_key, half_double_value))
  358. data_list.append(half_double_data)
  359. # half_odd_even_odd
  360. hash_str = p_code + "tss_h" + '0' + '单' + str(half_odd_even_odd) + "hg3535" + str(match_id)
  361. sole_str = p_code + "tss_h" + '0' + str(match_id) + "hg3535"
  362. odds_only = Helper.genearte_MD5(hash_str, pt)
  363. sole = Helper.genearte_MD5(sole_str, pt)
  364. half_single_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  365. "odds_only", "sole", "source", "type", "team"]
  366. half_single_value = [match_id, league_id, "tss_h", "0", 0, p_code, half_odd_even_odd, '单', odds_only,
  367. sole, "hg3535", "0", ""]
  368. half_single_data = dict(zip(half_single_key, half_single_value))
  369. data_list.append(half_single_data)
  370. p_code = 'TG'
  371. # 总入球数 ---------------------------------------------------------------------------------------------------
  372. total_goals = item['total_goal']
  373. total_dict = {'tg0': '0-1', 'tg1': '2-3', 'tg2': '4-6', 'tg3': '7或以上', 'tg0_h': '0', "tg1_h": '1',
  374. "tg2_h": '2', "tg3_h": '3或以上'}
  375. # 全场入球数 单双
  376. for key, value in total_goals.items():
  377. hash_str = p_code + key + '0' + total_dict[key] + str(value) + "hg3535" + str(match_id)
  378. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  379. odds_only = Helper.genearte_MD5(hash_str, pt)
  380. sole = Helper.genearte_MD5(sole_str, pt)
  381. total_goals_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  382. "odds_only", "sole", "source", "type", "team"]
  383. total_goals_value = [match_id, league_id, key, "0", 0, p_code, value, total_dict[key], odds_only,
  384. sole, "hg3535", "0", ""]
  385. total_goals_data = dict(zip(total_goals_key, total_goals_value))
  386. data_list.append(total_goals_data)
  387. # 全场半场 ---------------------------------------------------------------------------------------------------
  388. half_fulls = item['half_full']
  389. # p_code, p_id = get_pcode(corner_ball, 'half_full')
  390. p_code = 'HF'
  391. full_dict = {"hfhh": "主主", "hfhd": "主和", "hfhg": "主客", "hfdh": "和主",
  392. "hfdd": "和和", "hfdg": "和客", "hfgh": "客主", "hfgd": "客和", "hfgg": "客客"}
  393. if half_fulls:
  394. for key, value in half_fulls.items():
  395. hash_str = p_code + key + '0' + full_dict[key] + str(value) + "hg3535" + str(match_id)
  396. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  397. odds_only = Helper.genearte_MD5(hash_str, pt)
  398. sole = Helper.genearte_MD5(sole_str, pt)
  399. half_fulls_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  400. "odds_only", "sole", "source", "type", "team"]
  401. half_fulls_value = [match_id, league_id, key, "0", 0, p_code, value, full_dict[key], odds_only,
  402. sole, "hg3535", "0", ""]
  403. half_fulls_data = dict(zip(half_fulls_key, half_fulls_value))
  404. data_list.append(half_fulls_data)
  405. # 波胆-------------------------------------------------------------------------------------------------------
  406. p_code = 'B'
  407. bodan_datas = item['bodan_data']
  408. # p_code, p_id = get_pcode(corner_ball, 'bodan')
  409. bodan_dict = {"b10": "1-0", "b20": "2-0", "b21": "2-1", "b30": "3-0", "b31": "3-1", "b32": "3-2",
  410. "b40": "4-0", "b41": "4-1", "b42": "4-2", "b43": "4-3", "b01": "0-1", "b02": "0-2",
  411. "b12": "1-2", "b03": "0-3", "b13": "1-3", "b23": "2-3", "b04": "0-4", "b14": "1-4",
  412. "b24": "2-4", "b34": "3-4", "b00": "0-0", "b11": "1-1", "b22": "2-2", "b33": "3-3",
  413. "b44": "4-4", "bo": "其他", "b10_h": "1-0", "b20_h": "2-0", "b21_h": "2-1", "b30_h": "3-0",
  414. "b31_h": "3-1", "b32_h": "3-2", "b01_h": "0-1", "b02_h": "0-2", "b12_h": "1-2", "b03_h": "0-3",
  415. "b13_h": "1-3", "b23_h": "2-3", "b00_h": "0-0", "b11_h": "1-1", "b22_h": "2-2", "b33_h": "3-3",
  416. "bo_h": "其他"}
  417. if bodan_datas:
  418. for key, value in bodan_datas.items():
  419. hash_str = p_code + key + '0' + bodan_dict[key] + str(value) + "hg3535" + str(match_id)
  420. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  421. odds_only = Helper.genearte_MD5(hash_str, pt)
  422. sole = Helper.genearte_MD5(sole_str, pt)
  423. bodan_dict_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  424. "odds_only", "sole", "source", "type", "team"]
  425. bodan_dict_value = [match_id, league_id, key, "0", 0, p_code, value, bodan_dict[key], odds_only,
  426. sole, "hg3535", "0", ""]
  427. bodan_dict_data = dict(zip(bodan_dict_key, bodan_dict_value))
  428. data_list.append(bodan_dict_data)
  429. # 最先进球/最后进球 -------------------------------------------------------------------------------------------
  430. first_last_balls = item['first_last_ball']
  431. p_code = 'FLB'
  432. first_last_dict = {"flbfh": "最先进球", "flbfg": "最先进球", "flblh": "最后进球", "flblg": "最后进球", "flbn": "没有进球"}
  433. if first_last_balls:
  434. for key, value in first_last_balls.items():
  435. hash_str = p_code + key + '0' + first_last_dict[key] + str(value) + "hg3535" + str(match_id)
  436. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  437. odds_only = Helper.genearte_MD5(hash_str, pt)
  438. sole = Helper.genearte_MD5(sole_str, pt)
  439. first_last_balls_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  440. "condition",
  441. "odds_only", "sole", "source", "type", "team"]
  442. first_last_balls_value = [match_id, league_id, key, "0", 0, p_code, value, first_last_dict[key],
  443. odds_only,
  444. sole, "hg3535", "0", ""]
  445. first_last_balls_data = dict(zip(first_last_balls_key, first_last_balls_value))
  446. data_list.append(first_last_balls_data)
  447. p_code = 'TB'
  448. # 球队得分全场,上半场
  449. full_dicts = item['full_data']
  450. half_dicts = item['half_data']
  451. full_dict_rules = item['full_data_rule']
  452. half_dict_rules = item['half_data_rule']
  453. if full_dicts:
  454. for key, value in full_dicts.items():
  455. hash_str = p_code + key + '0' + full_dict_rules[key] + str(value) + "hg3535" + str(match_id)
  456. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  457. odds_only = Helper.genearte_MD5(hash_str, pt)
  458. sole = Helper.genearte_MD5(sole_str, pt)
  459. full_dict_rules_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  460. "condition", "odds_only", "sole", "source", "type", "team"]
  461. full_dict_rules_value = [match_id, league_id, key, "0", 0, p_code, value, full_dict_rules[key],
  462. odds_only, sole, "hg3535", "0", ""]
  463. full_dict_rules_data = dict(zip(full_dict_rules_key, full_dict_rules_value))
  464. data_list.append(full_dict_rules_data)
  465. if half_dicts:
  466. for key, value in half_dicts.items():
  467. hash_str = p_code + key + '0' + half_dict_rules[key] + str(value) + "hg3535" + str(match_id)
  468. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  469. odds_only = Helper.genearte_MD5(hash_str, pt)
  470. sole = Helper.genearte_MD5(sole_str, pt)
  471. half_dicts_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  472. "condition", "odds_only", "sole", "source", "type", "team"]
  473. half_dicts_value = [match_id, league_id, key, "0", 0, p_code, value, half_dict_rules[key],
  474. odds_only, sole, "hg3535", "0", ""]
  475. half_dicts_data = dict(zip(half_dicts_key, half_dicts_value))
  476. data_list.append(half_dicts_data)
  477. p_code = 'CB'
  478. # 球队得分全场,上半场
  479. horn_ou_dict = item['horn_ou_dict']
  480. horn_ou_dict_rule = item['horn_ou_dict_rule']
  481. horn_oe_dict = item['horn_oe_dict']
  482. horn_oe_dict_rule = item['horn_oe_dict_rule']
  483. if horn_ou_dict:
  484. for key, value in horn_ou_dict.items():
  485. hash_str = p_code + key + '0' + horn_ou_dict_rule[key] + str(value) + "hg3535" + str(match_id)
  486. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  487. odds_only = Helper.genearte_MD5(hash_str, pt)
  488. sole = Helper.genearte_MD5(sole_str, pt)
  489. horn_ou_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  490. "condition", "odds_only", "sole", "source", "type", "team"]
  491. horn_ou_value = [match_id, league_id, key, "0", 0, p_code, value, horn_ou_dict_rule[key],
  492. odds_only, sole, "hg3535", "0", ""]
  493. horn_ou_data = dict(zip(horn_ou_key, horn_ou_value))
  494. data_list.append(horn_ou_data)
  495. if horn_oe_dict:
  496. for key, value in horn_oe_dict.items():
  497. hash_str = p_code + key + '0' + horn_oe_dict_rule[key] + str(value) + "hg3535" + str(match_id)
  498. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  499. odds_only = Helper.genearte_MD5(hash_str, pt)
  500. sole = Helper.genearte_MD5(sole_str, pt)
  501. horn_oe_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  502. "condition", "odds_only", "sole", "source", "type", "team"]
  503. horn_oe_value = [match_id, league_id, key, "0", 0, p_code, value, horn_oe_dict_rule[key],
  504. odds_only, sole, "hg3535", "0", ""]
  505. horn_oe_data = dict(zip(horn_oe_key, horn_oe_value))
  506. data_list.append(horn_oe_data)
  507. odds_key = ["game_code", "title", "match_id", "lg_id", "data", "source", "odds_only", "tag", "uuid",
  508. "is_stringscene", "utime", "pt", 'match_identity']
  509. odds_value = ["zq", "odds", match_id, league_id, data_list, "hg3535", odds_onlys, number, uuid,
  510. 0, utime, pt, match_identity]
  511. odds_dict = dict(zip(odds_key, odds_value))
  512. if data_list:
  513. res = Helper.async_post(ODDS_URL, odds_dict)
  514. if res:
  515. if res.get('status') == 1:
  516. logger.info('足球滚球详细赔率提交成功, {}'.format(res))
  517. # logger.info(odds_dict)
  518. else:
  519. logger.warning('足球滚球详细赔率提交失败, {}'.format(res))
  520. # logger.warning(odds_dict)
  521. else:
  522. logger.warning('足球滚球详细赔率接口异常,提交失败, {}'.format(res))
  523. # logger.warning(odds_dict)
  524. else:
  525. logger.info('足球滚球详细赔率列表为空')
  526. data_list = []
  527. zq_rball = {"home_team": team_home, "guest_team": team_guest,
  528. "lg_id": league_id, "home_rate": 0,
  529. "guest_rate": 0, "home_score": score_home,
  530. "guest_score": score_guest, "all_goal": all_goal, "status": 1,
  531. "first_score": "", "last_score": "", "match_score": match_score, "uuid": uuid,
  532. "match_winer": "", "match_time": time_game, 'match_identity': match_identity,
  533. "match_process": half_way, "tag": number,
  534. "match_id": match_id, "p_code": ""}
  535. data_list.append(zq_rball)
  536. r_data_dict = {
  537. "game_code": "zq",
  538. "title": "match_result_r",
  539. "source": "hg3535",
  540. "data": data_list
  541. }
  542. if data_list:
  543. try:
  544. res = Helper.async_post(MATCH_RESULT, r_data_dict)
  545. if res:
  546. if res.get('status') == 1:
  547. logger.info('足球滚球结果记录提交成功, {}'.format(res))
  548. self.db.zq_match_result35.insert(zq_rball)
  549. # logger.info(r_data_dict)
  550. else:
  551. logger.warning('足球滚球结果记录提交失败, {}'.format(res))
  552. # logger.warning(r_data_dict)
  553. else:
  554. logger.warning('足球滚球结果记录接口异常,提交失败, {}'.format(res))
  555. # logger.warning(r_data_dict)
  556. except Exception as e:
  557. logger.warning('滚球数据接口异常,提交失败, {}'.format(e))
  558. # # 角球分割处理--------------------------------------------------------------------------------------------------
  559. # if horn_team:
  560. # team_home = horn_team['horn_home']
  561. # team_guest = horn_team['horn_guest']
  562. # horn_scoreh = horn_team['horn_scoreh']
  563. # horn_scoreg = horn_team['horn_scoreg']
  564. # all_goal = int(horn_scoreh) + int(horn_scoreg)
  565. # match_id = horn_team['horn_id']
  566. # # half_way = item['half_way']
  567. # match_score = "{}:{}".format(horn_scoreh, horn_scoreg)
  568. # match_identity = Helper.genearte_uuid(team_home + team_guest + us_date)
  569. # if self.db.zq_competition35.find({"match_identity": match_identity, 'is_rollball': 1}).count() < 1:
  570. # match_list = []
  571. # match_dict = {"game_code": "zq", "title": "match", "source": "hg3535"}
  572. # match_kay = ["home_team", "guest_team", "lg_id", "status", "match_id", "match_date", "match_time",
  573. # "tag", "source", "is_rollball", "is_morningplate", "is_stringscene", "us_time", "uuid",
  574. # "half_match_id", "is_today", "is_horn", 'match_identity']
  575. # match_value = [team_home, team_guest, league_id, 1, match_id, match_date, match_time, number,
  576. # "hg3535", 1, 0, 0, utime, uuid, 0, 0, 1, match_identity]
  577. # match_data = dict(zip(match_kay, match_value))
  578. # match_list.append(match_data)
  579. # match_dict['data'] = match_list
  580. # res = Helper.async_post(MATCH_URL, match_dict)
  581. # if res:
  582. # if res.get('status') == 1:
  583. # self.db.zq_competition35.insert(match_data)
  584. # logger.info('足球滚球角球, 赛事提交成功, {}'.format(res))
  585. # # logger.info(match_data)
  586. # else:
  587. # logger.warning('足球滚球赛事, 角球提交失败, {}'.format(res))
  588. # # logger.warning(match_data)
  589. # else:
  590. # logger.warning('足球滚球赛事接口异常, 角球赛事提交失败, {}'.format(res))
  591. # # logger.warning(match_data)
  592. # else:
  593. # logger.info('足球滚球赛事已存在, 不提交')
  594. # data_list = []
  595. # odds_onlys = []
  596. # p_code = 'CB'
  597. # horn_ou_dict = item['horn_ou_dict']
  598. # horn_ou_dict_rule = item['horn_ou_dict_rule']
  599. # horn_oe_dict = item['horn_oe_dict']
  600. # horn_oe_dict_rule = item['horn_oe_dict_rule']
  601. # if horn_ou_dict:
  602. # for key, value in horn_ou_dict.items():
  603. # hash_str = p_code + key + '0' + horn_ou_dict_rule[key] + str(value) + "hg3535" + str(match_id)
  604. # sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  605. # odds_only = Helper.genearte_MD5(hash_str, pt)
  606. # sole = Helper.genearte_MD5(sole_str, pt)
  607. # horn_ou_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  608. # "condition", "odds_only", "sole", "source", "type", "team"]
  609. # horn_ou_value = [match_id, league_id, key, "0", 0, p_code, value, horn_ou_dict_rule[key],
  610. # odds_only, sole, "hg3535", "0", ""]
  611. # horn_ou_data = dict(zip(horn_ou_key, horn_ou_value))
  612. # data_list.append(horn_ou_data)
  613. #
  614. # if horn_oe_dict:
  615. # for key, value in horn_oe_dict.items():
  616. # hash_str = p_code + key + '0' + horn_oe_dict_rule[key] + str(value) + "hg3535" + str(match_id)
  617. # sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  618. # odds_only = Helper.genearte_MD5(hash_str, pt)
  619. # sole = Helper.genearte_MD5(sole_str, pt)
  620. # horn_oe_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  621. # "condition", "odds_only", "sole", "source", "type", "team"]
  622. # horn_oe_value = [match_id, league_id, key, "0", 0, p_code, value, horn_oe_dict_rule[key],
  623. # odds_only, sole, "hg3535", "0", ""]
  624. # horn_oe_data = dict(zip(horn_oe_key, horn_oe_value))
  625. # data_list.append(horn_oe_data)
  626. #
  627. # odds_key = ["game_code", "title", "match_id", "lg_id", "data", "source", "odds_only", "tag", "uuid",
  628. # "is_stringscene", "utime", "pt", 'match_identity']
  629. # odds_value = ["zq", "odds", match_id, league_id, data_list, "hg3535", odds_onlys, number, uuid,
  630. # 0, utime, pt, match_identity]
  631. # odds_dict = dict(zip(odds_key, odds_value))
  632. # if data_list:
  633. # res = Helper.async_post(ODDS_URL, odds_dict)
  634. # if res:
  635. # if res.get('status') == 1:
  636. # logger.info('足球滚球, 角球详细赔率提交成功, {}'.format(res))
  637. # # logger.info(odds_dict)
  638. # else:
  639. # logger.warning('足球滚球, 角球详细赔率提交失败, {}'.format(res))
  640. # # logger.warning(odds_dict)
  641. # else:
  642. # logger.warning('足球滚球, 角球详细赔率接口异常,提交失败, {}'.format(res))
  643. # # logger.warning(odds_dict)
  644. # else:
  645. # logger.info('足球滚球, 角球详细赔率列表为空')
  646. # data_list = []
  647. # zq_rball = {"home_team": team_home, "guest_team": team_guest,
  648. # "lg_id": league_id, "home_rate": 0,
  649. # "guest_rate": 0, "home_score": horn_scoreh,
  650. # "guest_score": horn_scoreg, "all_goal": all_goal, "status": 1,
  651. # "first_score": "", "last_score": "", "match_score": match_score, "uuid": uuid,
  652. # "match_winer": "", "match_time": time_game,
  653. # "match_process": half_way, "tag": number,
  654. # "match_id": match_id, "p_code": "", 'match_identity': match_identity}
  655. # data_list.append(zq_rball)
  656. # r_data_dict = {
  657. # "game_code": "zq",
  658. # "title": "match_result_r",
  659. # "source": "hg3535",
  660. # "data": data_list
  661. # }
  662. # if data_list:
  663. # try:
  664. # res = Helper.async_post(MATCH_RESULT, r_data_dict)
  665. # if res:
  666. # if res.get('status') == 1:
  667. # logger.info('足球滚球, 角球结果记录提交成功, {}'.format(res))
  668. # self.db.zq_match_result35.insert(zq_rball)
  669. # # logger.info(r_data_dict)
  670. # else:
  671. # logger.warning('足球滚球, 角球结果记录提交失败, {}'.format(res))
  672. # # logger.warning(r_data_dict)
  673. # else:
  674. # logger.warning('足球滚球, 角球结果记录接口异常,提交失败, {}'.format(res))
  675. # # logger.warning(r_data_dict)
  676. # except Exception as e:
  677. # logger.warning('滚球数据接口异常, 角球结果提交失败, {}'.format(e))
  678. reactor.callFromThread(out.callback, item)