From 2a0635783af509bef84ce0d5c08d06ae461554c9 Mon Sep 17 00:00:00 2001 From: magmaus3 Date: Sun, 30 Oct 2022 11:40:18 +0100 Subject: [PATCH] . --- iwm_browser/main.py | 38 +++++++++++++-------- iwm_browser/tags.py | 43 +++++++++++++++++++++++ iwm_browser/templates/levelInfo.html | 51 ++++++++++++++++++++++++++++ iwm_browser/utils.py | 13 +++++++ 4 files changed, 130 insertions(+), 15 deletions(-) create mode 100644 iwm_browser/tags.py create mode 100644 iwm_browser/templates/levelInfo.html create mode 100644 iwm_browser/utils.py diff --git a/iwm_browser/main.py b/iwm_browser/main.py index fc8bd31..45c561a 100644 --- a/iwm_browser/main.py +++ b/iwm_browser/main.py @@ -33,10 +33,10 @@ async def root(): @app.get("/search", response_class=HTMLResponse) async def search( q: Union[str, None] = None, - p: Union[int, None] = None, - sort: Union[str, None] = None, - dir: Union[str, None] = None, - date: Union[int, None] = None + p: int = 0, + sort: str = "average_Rating", + dir: str = "desc", + date: int = -1 ): template = template_env.get_template("search.html") limit = 10 @@ -60,17 +60,6 @@ async def search( except httpx.ReadTimeout: return "Server timed out" else: - - # Check sort types - if sort is None: - sort = "average_rating" - - if dir is None: - dir = "desc" - - if date is None: - date = -1 - order = {"Dir": dir, "Name": sort} if date == -1: last_x_hours = {} @@ -109,6 +98,25 @@ async def search( entryNumber=entryNumber ) +@app.get("/level/{level_id}", response_class=HTMLResponse) +async def showLevel(level_id: int): + template = template_env.get_template("levelInfo.html") + + try: + rq = httpx.get(BASE_URL + "/api/v1/map/" + str(level_id), timeout=10) + searchResults = rq.json() + print(rq.url) + except httpx.ReadTimeout: + return "Server timed out" + + + + return template.render( + map=searchResults, + THUMB_URL=THUMB_URL, + ) + + def start(): diff --git a/iwm_browser/tags.py b/iwm_browser/tags.py new file mode 100644 index 0000000..cf834f0 --- /dev/null +++ b/iwm_browser/tags.py @@ -0,0 +1,43 @@ +""" +Tag names and corresponding IDs (Shown in the original order) + +0: Adventure/Variety +6: Gimmick +7: Trap/Troll +3: Joke/Meme +2: Needle +5: Puzzle +1: Boss/Avoidance +9: Art +8: Music +4: Auto + +(Yes, if you select all tags, +the required_tags argument will be in that order.) +""" + +ids_to_names = { + 0: "Adventure/Variety", + 6: "Gimmick", + 7: "Trap/Troll", + 3: "Joke/Meme", + 2: "Needle", + 5: "Puzzle", + 1: "Boss/Avoidance", + 9: "Art", + 8: "Music", + 4: "Auto", +} + +names_to_ids = { + "Adventure/Variety": 0, + "Gimmick": 6, + "Trap/Troll": 7, + "Joke/Meme": 3, + "Needle": 2, + "Puzzle": 5, + "Boss/Avoidance": 1, + "Art": 9, + "Music": 8, + "Auto": 4, +} diff --git a/iwm_browser/templates/levelInfo.html b/iwm_browser/templates/levelInfo.html new file mode 100644 index 0000000..40e5e3e --- /dev/null +++ b/iwm_browser/templates/levelInfo.html @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + diff --git a/iwm_browser/utils.py b/iwm_browser/utils.py new file mode 100644 index 0000000..a1f4cfe --- /dev/null +++ b/iwm_browser/utils.py @@ -0,0 +1,13 @@ +def convert_times(time): + # Not sure if it's the right way to do that, but it seems to work. + time_seconds = ((time % 60000) / 100) * 2 + + minutes, seconds = divmod(time_seconds, 60) + hours, minutes = divmod(minutes, 60) + + hours = str(round(hours)).zfill(2) + minutes = str(round(minutes)).zfill(2) + + seconds = "{0:,.2f}".format(seconds).zfill(5) + + return (hours,minutes,seconds)