.
This commit is contained in:
parent
8b79863393
commit
2a0635783a
4 changed files with 130 additions and 15 deletions
|
@ -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():
|
||||
|
|
43
iwm_browser/tags.py
Normal file
43
iwm_browser/tags.py
Normal file
|
@ -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,
|
||||
}
|
51
iwm_browser/templates/levelInfo.html
Normal file
51
iwm_browser/templates/levelInfo.html
Normal file
|
@ -0,0 +1,51 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title></title>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="stylesheet" href="/static/index.css">
|
||||
<link rel="stylesheet" href="/static/main.css">
|
||||
<link rel="stylesheet" href="/static/search/search.css">
|
||||
<link rel="stylesheet" href="/static/search/searchResults.css">
|
||||
<!-- Optional features -->
|
||||
<script>
|
||||
function copy(obj) {
|
||||
// copies the contents of the
|
||||
// input field to clipboard, and
|
||||
// adds the "copied" css class
|
||||
navigator.clipboard.writeText(obj.value);
|
||||
alert("Level code copied")
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="Search">
|
||||
<div class="contentBox_">
|
||||
<div class="header">Search</div>
|
||||
<div class="splitter"></div>
|
||||
<div class="searchResults">
|
||||
<div class="searchResultCard full">
|
||||
<div class="thumbnail"><img src="{{ THUMB_URL }}/{{ map['ID'] }}.png"></div>
|
||||
<div class="details">
|
||||
<div class="basic">
|
||||
<div class="levelTitle">{{ map['Name'] }}</div>
|
||||
<div class="levelDifficulty"><span>Difficulty: {{ '▲' * map['AverageUserDifficulty']|int }}</span></div>
|
||||
<div class="creatorName">by <b>{{ map['CreatorName'] }}</b></div>
|
||||
<div class="levelRating">{{ map['NumThumbsUp'] }} 👍 {{ map['NumThumbsDown'] }} 👎</div>
|
||||
<div class="levelCode">Code: <input type="text" onclick="copy(this)" readonly=1 value="{{ map['MapCode'] }}" /></div>
|
||||
</div>
|
||||
<div class="times">
|
||||
<div class="FirstClear">First Clear: <b>{{ map['FirstClearUsername'] }}</b> </div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
13
iwm_browser/utils.py
Normal file
13
iwm_browser/utils.py
Normal file
|
@ -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)
|
Loading…
Reference in a new issue