From 45b6f4e5d23ddae41a4ad7d26792903ade70554a Mon Sep 17 00:00:00 2001 From: syeopite Date: Sun, 23 May 2021 06:58:31 -0700 Subject: [PATCH] Finalize for release --- .gitignore | 1 - README.md | 7 ++++++- main.py | 23 ++++++++++++++++++++--- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 509d7ac..2e62100 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ venv .idea __pycache__ -*.log diff --git a/README.md b/README.md index af49b5f..d48af06 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,9 @@ -# [WIP] Quic proxy built in Python for the Invidious project. +# Quic proxy built in Python for the Invidious project. + +## Installation +1. Clone the repository +2. Create a python virtual environment +3. Install dependencies through pip `pip install -r requirements.txt` ## Usage diff --git a/main.py b/main.py index 560366b..92bef2c 100644 --- a/main.py +++ b/main.py @@ -1,5 +1,6 @@ import pathlib import logging +import argparse import asyncio import pytomlpp @@ -9,8 +10,6 @@ from aiohttp import web import quicclient -logging.basicConfig(filename="test.log", level=logging.INFO) - APP_NAME = "QUICProxy" APP_AUTHOR = "syeopite" @@ -28,6 +27,24 @@ if not config: routes = web.RouteTableDef() +def process_cli_args(): + # Taken from https://stackoverflow.com/a/20663028 + parser = argparse.ArgumentParser() + parser.add_argument( + '-d', '--debug', + help="Print lots of debugging statements", + action="store_const", dest="loglevel", const=logging.DEBUG, + default=logging.WARNING, + ) + parser.add_argument( + '-v', '--verbose', + help="Be verbose", + action="store_const", dest="loglevel", const=logging.INFO, + ) + args = parser.parse_args() + logging.basicConfig(level=args.loglevel) + + @routes.post("/") async def post(request): arguments = await request.json() @@ -59,6 +76,6 @@ async def main(): request_processor = quicclient.RequestProcessor() - if __name__ == '__main__': + process_cli_args() web.run_app(main(), port=config.get("port", 7912), host=config.get("host", "0.0.0.0"))