diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 00000000000..dc713679648 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,24 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "Launch proxy", + "type": "process", + "command": "${command:python.interpreterPath}", + "args": [ + "scripts${/}proxy_lp.py" + ], + "isBackground": true, + "presentation": { + "reveal": "always", + "panel": "dedicated" + }, + "problemMatcher": [], + "detail": "python3 scripts/proxy_lp.py", + "runOptions": { + "instanceLimit": 1, + "instancePolicy": "terminateOldest" + } + } + ] +} diff --git a/scripts/proxy_lp.py b/scripts/proxy_lp.py index 6c2ce075ad6..7ad85a82e6d 100644 --- a/scripts/proxy_lp.py +++ b/scripts/proxy_lp.py @@ -1,5 +1,9 @@ +import asyncio + from http import HTTPStatus -from mitmproxy import http + +from mitmproxy import addons, http, master +from mitmproxy.addons import dumper, errorcheck, keepserving, readfile class LiquipediaMapper: @@ -41,4 +45,21 @@ def __serve_local_js_resource(self, flow: http.HTTPFlow): ) -addons = [LiquipediaMapper()] +async def main(): + m = master.Master(None) + m.addons.add( + *addons.default_addons(), + LiquipediaMapper(), + dumper.Dumper(), + keepserving.KeepServing(), + readfile.ReadFileStdin(), + errorcheck.ErrorCheck(), + ) + try: + await m.run() + except asyncio.CancelledError: + await m.done() + + +if __name__ == "__main__": + asyncio.run(main())