zuqiu.py 65 KB

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