zuqiu.py 65 KB

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