def handle(request): checksum = request.args.getlist("c") api_data = [] param_s = request.args.getlist("s") param_b = request.args.getlist("b") for param in param_s: data = api.call_api("get_beatmaps", s=param) AddListsUnique(api_data, data) for param in param_b: data = api.call_api("get_beatmaps", b=param) AddListsUnique(api_data, data) AddListsUnique(checksum, [x["file_md5"] for x in api_data]) checksum = "&c[]=".join(checksum) ppy_data = urllib.request.urlopen('http://osu.ppy.sh/web/osu-getdifficulty.php?c[]={}'.format(checksum)) ppy_str = ppy_data.read() if len(ppy_str) <= 0: return jsonify(None) data = ppyFormat.verticalSplit(ppy_str, ["checksum", "mode", "mods", "diff_unified"]) # Update status for api calls status.update(ext = 1) return jsonify(data)
def do_sudo_command(self, e, command): if command == 'open': status.update(True, e.source.nick) self.send_status() elif command == 'close': status.update(False, '') self.send_status()
def do_GET(self): print("path:", self.path) if self.path == "/status.json": data = { "api": "0.13", "space": "Stratum 0", "logo": "https:\/\/stratum0.org\/mediawiki\/images\/thumb\/c\/c6\/Sanduhr-twitter-avatar-black.svg\/240px-Sanduhr-twitter-avatar-black.svg.png", "url": "https:\/\/stratum0.org", "location": { "address": "Hamburger Strasse 273a, 38114 Braunschweig, Germany", "lon": 10.5211247, "lat": 52.2785658, }, "state": { "open": status.space["open"], "lastchange": status.space["last_change"], "trigger_person": status.space["by"], "icon": { "open": "http:\/\/status.stratum0.org\/open_square.png", "closed": "http:\/\/status.stratum0.org\/closed_square.png", }, "ext_since": status.space["since"], }, "contact": { "phone": "+4953128769245", "twitter": "@stratum0", "ml": "*****@*****.**", "issue-mail": "cm9oaWViK3NwYWNlYXBpLWlzc3Vlc0Byb2hpZWIubmFtZQ==", "irc": "irc:\/\/irc.freenode.net\/#stratum0", }, "issue_report_channels": ["issue-mail"], } data_string = json.dumps(data) self.send_response(200) self.send_header("Content-type", "application/json") self.end_headers() self.wfile.write(data_string) self.wfile.write("\n") elif self.path.startswith("/update?"): queryurl = urlparse(self.path) params = parse_qs(queryurl.query) if len(params) > 0: by = "" if "by" in params: by = params["by"][0] status.update(params["open"][0] == "true", by) callbacks["send_status"]() self.send_response(200) else: self.send_response(400) else: self.send_response(404)
def call_api(endpoint, **kwargs): query = "?k={}".format(glob.config["api-key"]) if kwargs is not None and len(kwargs) is not 0: args = [] for key, value in kwargs.items(): args.append("{}={}".format(key, value)) query += "&" + "&".join(args) endcall = endpoint + query ppy_data = urllib.request.urlopen( 'http://osu.ppy.sh/api/{}'.format(endcall)) # Update status for api calls status.update(api=1) return json.loads(ppy_data.read().decode("utf-8"))
def run(self): if config.debug_memory: self.dump_mem_summary() self.reply_queue.process() self.stream_manager.process() # Disable regular maintenance, let ACM take care of things #self.maintain_list.process() # If comments are in queue, then don't update status or sleep, just # return out so we can process them immediately if len(self.stream_manager) > 0: return # Do a status update, but only if the backlog is totally resolved. # Often, the stream queue will be empty but the backlog hasn't really # finished being processed so we aren't actually done updating. if not self.is_backlogged(): status.update() # calculate the next time we need to do something st = self.get_sleep_time() if st > 0: # Put the thread to sleep, timing out after st seconds or breaking # out immediately if the stream manager notifies of a new entry logging.debug( "Main thread idling for {:.3f}s or until notified".format(st)) # reset the event's status self.stream_event.clear() # signal the ACM subthread that it can start maintaining comments self.acm_event.set() logging.debug("Main thread triggers acm_event.") # make this thread wait until a stream subthread signals this # thread to go, or until sleep time has elapsed self.stream_event.wait(timeout=st) # operation has continued, so clear the ACM flag so the subthread # knows to stop at the next reasonable stopping point self.acm_event.clear() logging.debug("Main thread clears acm_event.")
def handle(request): ppy_data = urllib.request.urlopen( 'http://osu.ppy.sh/web/osu-gethashes.php?s={}'.format( request.args.get("s"))) ppy_str = ppy_data.read() if len(ppy_str) > 3: data = ppyFormat.verticalSplit(ppy_str, ["_", "body_hash", "header_hash"]) if len(data["body_hash"]) + len(data["header_hash"]) == 0: data = None else: data["body_hash"] = data["body_hash"].lower() data["header_hash"] = data["header_hash"].lower() else: data = None # Update status for api calls status.update(ext=1) return jsonify(data)