Initial commit, basic debugging.
This commit is contained in:
commit
c3d6c2e7dd
4 changed files with 74 additions and 0 deletions
7
.gitignore
vendored
Normal file
7
.gitignore
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
# Ignore virtual environments
|
||||
**/.venv/*
|
||||
|
||||
# Ignore python dev files
|
||||
**/*.pyc
|
||||
**/__pycache__/*
|
||||
**/.python-version
|
3
README.md
Normal file
3
README.md
Normal file
|
@ -0,0 +1,3 @@
|
|||
# MyLARP Web API
|
||||
|
||||
A parser and REST API for using https://mylarp.dev/
|
56
mylarp-api.py
Executable file
56
mylarp-api.py
Executable file
|
@ -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()
|
8
requirements.txt
Normal file
8
requirements.txt
Normal file
|
@ -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
|
Loading…
Reference in a new issue