zuqiu.py 40 KB

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