def bpApi(**kw): uid = kw.get('osuid') mode = kw.get('mode', 0) limit = kw.get('limit', 10) pyh = ppyHandler.ppyHandler() ret = pyh.getOsuUserBp(uid, mode, limit) return json.dumps(ret)
def apiv2me(**kw): qqid = request.form.get('qqid') groupid = request.form.get('groupid') atqq = request.form.get('atqq') queryid = qqid if atqq: base = baseHandler.baseHandler() rs = base.checkTokenPermission(atqq, groupid) if rs.isdigit(): queryid = atqq else: return rs url = "http://inter4.com/osubot/v2me" data = {"qqid": queryid, "groupid": groupid} r = requests.post(url, timeout=10, data=data) try: rdata = json.loads(r.text) imgpath = ppyHandler.ppyHandler().drawRankLine(rdata, queryid) return "[CQ:image,cache=0,file=%s]" % imgpath except: logging.error(traceback.format_exc()) if len(r.text) < 50: return r.text else: return '异常' return '异常,懒得修了'
def recent(**kw): uid = kw.get('osuid') mode = kw.get('mode', 0) limit = kw.get('limit', 10) pyh = ppyHandler.ppyHandler() ret = pyh.getRecent(uid, mode, limit) return json.dumps(ret)
def chenckAndudpateUserToken(self, qq, groupid, access_token, refresh_token): """检查加绑定操作 Returns: -1 数据库操作异常 -2 v2信息获取失败 """ db = interMysql.Connect('osu2') checkSql = ''' SELECT count(1) c FROM user WHERE qq=%s and groupid=%s ''' checkArgs = [qq, groupid] checkRet = db.query(checkSql, checkArgs) if not checkRet[0]["c"]: rs = self.insertUser(qq, groupid) if not rs: return -1 # 取一次用户信息 b = ppyHandler.ppyHandler() status, ret = b.autov2Req2(qq, groupid, "me", access_token, refresh_token) if status < 0: return -2 osuid = ret["id"] osuname = ret["username"] # 批量更新操作 upRet = self.udpateUsersInfo(qq, access_token, refresh_token, osuid, osuname) if upRet < 0: return -1 return 1
def getScores(**kw): uid = kw.get('osuid') bid = kw.get('bid') limit = kw.get('limit', 10) pyh = ppyHandler.ppyHandler() ret = pyh.getScores(uid, bid, limit) return json.dumps(ret)
def save_rec_by_rec(uid, groupid, rec, hid=1, limit=1): o = ppyHandler.ppyHandler() bids = [rec[0]["beatmap_id"]] # 提取rec inRec = score.check_rec(bids, rec, uid) if not inRec: logging.info('无新成绩!') return '你还要再刚一点.JPG' # 从库中过滤bids inbids = [r['beatmap_id'] for r in inRec] inbids = score.filter_beatmapid(inbids) logging.info('查询bids列表:%s'%str(inbids)) if inbids: mapsinfo = [o.getOsuBeatMapInfo(b) for b in inbids] map_args = score.args_format('map', mapsinfo) score.map2db(map_args) rec_args = score.args_format('rec', inRec) score.rec2db(rec_args) rec1 = copy.deepcopy(inRec) rec2 = copy.deepcopy(inRec) # 总榜临时处理 score.map_rank(rec1, groupid, hid=1, rtype=1) score.map_rank(rec2, groupid, hid=1, rtype=2) return 'upload success!'
def stat(**kw): b = ppyHandler.ppyHandler() atqq = kw['atqq'] if atqq: base = baseHandler.baseHandler() rs = base.checkTokenPermission(atqq, kw['groupid']) if rs.isdigit(): rs = b.osuV2stat(atqq, kw['groupid']) else: rs = b.osuV2stat(kw['qqid'], kw['groupid']) return rs
def updatemap(**kw): b = ppyHandler.ppyHandler() try: if not kw['iargs']: return "请输入bid!" bidstr = kw['iargs'][0] bids = bidstr.split(",") res = b.refresh_mapinfo2db(bids) return f"update res: {res}" except: logging.exception("") return "fail!"
def start(bid='847314', groupid='614892339', hid=1, mods=-1, uid='8505303'): mapjson, rankjson = draw_data.map_ranks_info(str(bid), groupid, hid, mods) ppyIns = ppyHandler.ppyHandler() # 历史问题导致遗漏的情况 if not mapjson: mapsinfo = [ppyIns.getOsuBeatMapInfo(bid)] map_args = score.args_format('map', mapsinfo) score.map2db(map_args) mapjson, rankjson = draw_data.map_ranks_info(str(bid), groupid, hid, mods) userjson = ppyIns.getOsuUserInfo(uid)[0] mapjson = ppyIns.getOsuBeatMapInfo(bid)[0] return drawR(mapjson, rankjson, userjson)
def rplaycount(**kw): qqid = request.form.get('qqid') groupid = request.form.get('groupid') url = "http://inter4.com/osubot/v2me" data = {"qqid": qqid, "groupid": groupid} r = requests.post(url, timeout=10, data=data) try: rdata = json.loads(r.text) imgpath = ppyHandler.ppyHandler().drawPlayCount(rdata, qqid) return "[CQ:image,cache=0,file=%s]" % imgpath except: logging.error(traceback.format_exc()) if len(r.text) < 50: return r.text else: return '异常' return '异常,懒得修了'
def osu_stats(self, osuname, days=0): try: ppyIns = ppyHandler.ppyHandler() result = ppyIns.getOsuUserInfo(osuname) if not result: return '' result = result[0] username = result['username'] osuid = result['user_id'] pp = result['pp_raw'] in_pp = float(pp) rank = result['pp_rank'] acc1 = round(float(result['accuracy']),2) acc = str(acc1) pc = result['playcount'] count300 = result['count300'] count100 = result['count100'] count50 = result['count50'] tth = eval(count300)+eval(count50)+eval(count100) tth_w = str(tth//10000) #与本地数据比较 u_db_info = self.get_user_fromDB(osuname, days) if u_db_info: info = u_db_info[0] add_pp = str(round(in_pp - float(info["pp"]),2)) add_rank = info["rank"] - int(rank) if add_rank >= 0: add_rank = '+'+str(add_rank) else: add_rank = str(add_rank) add_acc = round(acc1 - float(info["acc"]),2) if add_acc >=0.0: add_acc = '+'+str(add_acc) else: add_acc = str(add_acc) add_pc = str(int(pc) - int(info["pc"])) add_tth = str(tth - int(info["tth"])) times = info["time"].strftime('%Y-%m-%d') d = username+'\n'+pp+'pp(+'+add_pp+')\n'+'rank: '+rank+'('+add_rank+')\n'+'acc : '+acc+'%('+add_acc+')\n'+'pc : '+pc+'pc(+'+add_pc+')\n'+'tth : '+tth_w+'w(+'+add_tth+')\n'+times else: d = username+'\n'+pp+'pp(+0)\n'+'rank: '+rank+'(+0)\n'+'acc : '+acc+'%(+0)\n'+'pc : '+pc+'pc(+0)\n'+'tth : '+tth_w+'w(+0)\n'+str(datetime.date.today()) return d except: logging.exception("osu_stats error")
def insert_forday(self, ousernames=[]): """插入任务 """ logging.info('开始执行插入任务') if not ousernames: ousernames = self.get_user_list_fromDB() ppyIns = ppyHandler.ppyHandler() for uid in ousernames: try: res = ppyIns.getOsuUserInfo(uid) get_num = 0 while not res: if get_num < 5: get_num += 1 res = ppyIns.getOsuUserInfo(uid) else: break if not res: continue result = res if result: result = result[0] else: continue username = result['username'] osuid = result['user_id'] pp = result['pp_raw'] in_pp = float(pp) rank = result['pp_rank'] acc1 = round(float(result['accuracy']),2) pc = result['playcount'] count300 = result['count300'] count100 = result['count100'] count50 = result['count50'] tth = eval(count300)+eval(count50)+eval(count100) self.insert_user(username,in_pp,acc1,pc,rank,tth,osuid) logging.info('[%s]插入成功', uid) except: logging.exception('[%s]插入失败' % uid) logging.info('插入任务结束')
def upage(**kw): qqid = kw['qqid'] if not kw['atqq'] else kw['atqq'] if not kw['iargs']: x = 1 else: input0 = kw['iargs'][0] args0 = input0.replace(f'[CQ:at,qq={qqid}]', '') x = int(args0) if args0.isdigit() else 1 b = botHandler.botHandler() osuinfo = b.getOsuInfo2(qqid) if osuinfo: osuid = osuinfo['osuid'] osuname = osuinfo['osuname'] else: return "你倒是绑定啊.jpg" if int(x) < 0: x = 1 pyh = ppyHandler.ppyHandler() ret = pyh.get_user_page(osuid, osuname, x) return ret
def save_rec(uid, groupid, hid=1, limit=1): o = ppyHandler.ppyHandler() rec = o.getRecent(uid, limit=limit) if not rec: return '你想意念刚榜???' # 过滤bids bids = filter_rec(uid, rec) if not bids: logging.info('bids列表空!') return '你倒是打图啊.JPG' # 过滤rec newRec = autoRec(rec, bids) # 最新rec成绩优化 newRec = score.rec_highscore(newRec) # 提取rec inRec = score.check_rec(bids, newRec, uid) if not inRec: logging.info('无新成绩!') return '你还要再刚一点.JPG' # 从库中过滤bids inbids = [r['beatmap_id'] for r in inRec] inbids = score.filter_beatmapid(inbids) logging.info('查询bids列表:%s'%str(inbids)) if inbids: mapsinfo = [o.getOsuBeatMapInfo(b) for b in inbids] map_args = score.args_format('map', mapsinfo) score.map2db(map_args) rec_args = score.args_format('rec', inRec) score.rec2db(rec_args) rec1 = copy.deepcopy(inRec) rec2 = copy.deepcopy(inRec) # 总榜临时处理 score.map_rank(rec1, groupid, hid=1, rtype=1) score.map_rank(rec2, groupid, hid=1, rtype=2) return 'upload success!'
def getOsuUserInfo(**kw): uid = kw.get('osuid') pyh = ppyHandler.ppyHandler() ret = pyh.getOsuUserInfo(uid) return json.dumps(ret)
def stat(**kw): b = ppyHandler.ppyHandler() qqid = kw['atqq'] if kw.get("atqq") else kw['qqid'] rs = b.osuV2stat(qqid, kw['groupid']) return rs
def osuskillvs(**kw): osuname = kw.get('osuname') vsosuname = kw.get('vsosuname') pyh = ppyHandler.ppyHandler() ret = pyh.skillVsInfo(osuname, vsosuname) return ret
def osuskill(**kw): osuname = kw.get('osuname') pyh = ppyHandler.ppyHandler() ret = pyh.getSkillInfo(osuname) return ret
def beatmap(**kw): bid = kw.get('bid') pyh = ppyHandler.ppyHandler() ret = pyh.getOsuBeatMapInfo(bid) return json.dumps(ret)
def v2me(**kw): b = ppyHandler.ppyHandler() rs = b.getV2MyInfo(kw['qqid'], kw['groupid']) return rs
def ppplus(**kw): b = ppyHandler.ppyHandler() osuname = kw['autoOusInfoKey']['osuname'] res = b.get_pp_plus_info(osuname) return res
def friends(**kw): b = ppyHandler.ppyHandler() rs = b.getFriends(kw['qqid'], kw['groupid']) return rs