def main(): parser = ArgumentParser(description=__doc__) parser.add_argument("infile", nargs="?", type=FileType("r"), default=sys.stdin, help="the input replay data") args = parser.parse_args() with os.fdopen(sys.stdout.fileno(), "wb", closefd=False) as outfile: annotate_replay(args.infile, outfile)
def main(): parser = ArgumentParser(description=__doc__) parser.add_argument( "infile", nargs="?", type=FileType("r"), default=sys.stdin, help="the input replay data" ) parser.add_argument( "outfile", nargs="?", help="the annotated replay data" ) args = parser.parse_args() annotate_replay(args.infile, open(args.outfile, "wb"))
def get(self, request, shortid): from hsreplay.utils import annotate_replay from io import BytesIO replay = GameReplay.objects.find_by_short_id(shortid) if not replay or replay.is_deleted: raise Http404("Replay not found.") replay_xml = replay.replay_xml.open() annotated_replay = BytesIO() annotate_replay(replay_xml, annotated_replay) response = HttpResponse(annotated_replay.getvalue()) response["Content-Type"] = "application/xml" return response
def get(self, request, shortid): # throttle using DRF's throttles if (not ViewReplayBurstRateThrottle().allow_request(request, None) or not ViewReplaySustainedRateThrottle().allow_request( request, None)): return HttpResponse(status=429) from hsreplay.utils import annotate_replay from io import BytesIO replay = GameReplay.objects.find_by_short_id(shortid) if not replay or replay.is_deleted: raise Http404("Replay not found.") replay_xml = replay.replay_xml.open() annotated_replay = BytesIO() annotate_replay(replay_xml, annotated_replay) response = HttpResponse(annotated_replay.getvalue()) response["Content-Type"] = "application/xml" return response