def parse_expert(info, cla): """ :param info: 专家信息 :param cla: 0:足球专家 1:篮球专家 """ sql = Sql() expert = dict(table="expert") expert["avg_odds"] = info.get("avgOdds") # 平均赔率 expert["ball_rate"] = info.get("bAllRate") # 最近预测结果 expert["earning_rate"] = info.get("earningRate", 0) # 盈利率 expert["hit_rate"] = info.get("hitRate", 0) expert["max_win"] = info.get("maxWin") expert["nickname"] = info.get("nickname") # 昵称 expert["show_hit_rate"] = info.get("showHitRate") # ??? expert["slogan"] = info.get("slogan") # 职业 expert["trend"] = info.get("trend") # ??? expert["id"] = info.get("userId") # 用户id expert["weight"] = info.get("weight") # 体重 field = "foot" if cla == 0 else "basket" # 判断是足球专家还是篮球专家 expert[field] = 1 avatar_url = info.get("avatar") expert["avatar"] = str(expert.get("id")) + "." + avatar_url.split(".")[-1] ret = sql.save_if_not_exist(expert) if ret == 0: expert["table"] = "expert" sql.update(item=expert, field=field) else: avatar_path = cf.get("path", "avatar") avatar_url = info.get("avatar") # 头像 content = get_content_data(avatar_url) if content: save_pic( str(avatar_path + str(expert.get("id"))) + ".jpg", content)
def get_expert_league_articles(expert_id, league_id): url = cf.get("api", "expert_league_articles") url = url.replace("expertid", str(expert_id)).replace("leagueid", str(league_id)) data = get_json_data(url).get("data").get("threadList") print(json.dumps(data, ensure_ascii=False)) for a in data: sql = Sql() print(json.dumps(a, ensure_ascii=False)) article = dict(table="articles") article["id"] = a.get("threadId") article["title"] = a.get("threadTitle") article["expert_id"] = expert_id article["lottery_category_id"] = a.get("lotteryCategoryId") article["lottery_category_name"] = a.get("lotteryCategoryName") article["is_win"] = a.get("isWin") article["publish_time"] = a.get("publishTime") article["price"] = a.get("price") article["league_id"] = league_id for m in a.get("matchList"): match = dict(table="matches") match["category_id"] = m.get("categoryId") match["category_name"] = m.get("categoryName") match["info_id"] = m.get("matchInfoId") match["match_status"] = m.get("matchStatus") if match.get("match_status") == 3: match["status"] = "完" else: match["status"] = "未" match_time = m.get("matchTime") match_time = match_time.replace("/", "-").replace("/", "-") if not re.search("\d{4}", match_time): match_time = str(datetime.date.today().year) + "-" + match_time print(match_time) match["match_time"] = match_time league = dict(table="leaguematch") league_id = m.get("leagueId") league_name = m.get("leagueName") league["id"] = league_id league["name"] = league_name sql.save_if_not_exist(league) match["league_id"] = league_id match["league_name"] = league_name match["guest_name"] = m.get("guestName") match["guest_score"] = m.get("guestScore") match["home_name"] = m.get("homeName") match["home_score"] = m.get("homeScore") sql.save_if_not_exist(match, "info_id") article_match = dict(table="article_match") article_match["article_id"] = article["id"] article_match["info_id"] = match["info_id"] if not sql.is_exists_by_tow(article_match, "article_id", "info_id"): sql.save(article_match) ret = sql.save_if_not_exist(article) if ret == 0: article["table"] = "articles" sql.update(article, "league_id") sql.close()