From c3d6c2e7ddd7f10fb9c1e909c91a3e2d40baec0b Mon Sep 17 00:00:00 2001 From: Ada Werefox Date: Sat, 19 Apr 2025 15:20:45 -0700 Subject: [PATCH] Initial commit, basic debugging. --- .gitignore | 7 ++++++ README.md | 3 +++ mylarp-api.py | 56 ++++++++++++++++++++++++++++++++++++++++++++++++ requirements.txt | 8 +++++++ 4 files changed, 74 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100755 mylarp-api.py create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a506235 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +# Ignore virtual environments +**/.venv/* + +# Ignore python dev files +**/*.pyc +**/__pycache__/* +**/.python-version diff --git a/README.md b/README.md new file mode 100644 index 0000000..f874757 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# MyLARP Web API + +A parser and REST API for using https://mylarp.dev/ \ No newline at end of file diff --git a/mylarp-api.py b/mylarp-api.py new file mode 100755 index 0000000..07810a3 --- /dev/null +++ b/mylarp-api.py @@ -0,0 +1,56 @@ +#!/bin/env python + +from argparse import ArgumentParser +from logging import info, debug, error, basicConfig, DEBUG +from requests import get, HTTPError + +# import bs4 + +ROOT_URL = "https://cpularp.mylarp.dev/" + + +def build_arguent_parser() -> ArgumentParser: + """A function to build the argument parser. + + Returns: + ArgumentParser: The initialized argument parser object. + """ + + parser = ArgumentParser( + prog="mylarp-api", description="A python API for mylarp", epilog="" + ) + parser.add_argument( + "-u", + "--uri", + help="The uri of the mylarp page to parse.", + ) + parser.add_argument( + "-v", + "--verbose", + help="Output debug information.", + action="store_true", + ) + return parser + + +def parse_mylarp_page(uri: str): + info(f"Attempting to parse from {uri}") + try: + response = get(f"{ROOT_URL}{uri}") + except HTTPError as e: + error(f"Error attempting to request from uri: {e}") + debug(response.text) + return + + +def main(): + return + + +if __name__ == "__main__": + parser = build_arguent_parser() + args = parser.parse_args() + if args.verbose: + basicConfig(level=DEBUG) + parse_mylarp_page(args.uri) + main() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..4a6dd77 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,8 @@ +beautifulsoup4==4.13.4 +certifi==2025.1.31 +charset-normalizer==3.4.1 +idna==3.10 +requests==2.32.3 +soupsieve==2.6 +typing_extensions==4.13.2 +urllib3==2.4.0