fix: Fix bug introduced by fixing another bug (adding head to search())

Signed-off-by: Skylar "The Cobra" Widulski <cobra@vern.cc>
This commit is contained in:
Skylar "The Cobra" Widulski 2023-06-10 13:01:13 -04:00
parent c8f041cf36
commit 8a958bcc19
Signed by: cobra
GPG Key ID: 4FD8F812083FF6F9
1 changed files with 20 additions and 14 deletions

34
main.py
View File

@ -108,17 +108,24 @@ def search(path, head, args, query='*', teachers=False):
search_url = f"https://www.instructables.com/api_proxy/search/collections/projects/documents/search?q={query}&query_by=title%2CstepBody%2CscreenName&page={page}&sort_by={sort_by}%3Adesc&include_fields=title%2CurlString%2CcoverImageUrl%2CscreenName%2Cfavorites%2Cviews%2CprimaryClassification%2CfeatureFlag%2CprizeLevel%2CIMadeItCount"
category = f"{'category' if not teachers else 'teachers'}%3A%3D" + split_path[1] \
category = f"{'category' if not teachers else 'teachers'}%3A%3D" + split_path[1].title() \
if len(split_path) > 1 and \
split_path[1] != '' and \
split_path[1] != 'projects' and \
not split_path[1].startswith("?x") \
not split_path[1].startswith("?") \
else ''
if not type_ == '':
category = "+%26%26+" + category
channel = f"{'channel' if not teachers else 'teachers'}%3A%20" + quote(head) \
if head != '' \
and (head != "Circuits" and \
head != "Workshop" and \
head != "Craft" and \
head != "Cooking" and \
head != "Living" and \
head != "Outside" and \
head != "Teachers") \
else ''
if not type_ == '' or not category == '':
channel = "+%26%26+" + channel
@ -126,7 +133,6 @@ def search(path, head, args, query='*', teachers=False):
search_url += f"&filter_by={type_}{category}{channel}&per_page=60"
search_data = requests.get(search_url, headers={"X-Typesense-API-Key": typesense_key})
print(search_data.text)
if search_data.status_code != 200:
return Response(render_template(str(search_data.status_code) + ".html"), status=search_data.status_code)
@ -396,39 +402,39 @@ def get_channel_name(channel):
@app.route('/<category>/<channel>/projects/')
def route_channel_projects(category, channel):
return project_list(f"/{category}/{channel}/projects/?x", get_channel_name(channel), request.args, request.full_path)
return project_list(f"/{category}/{channel}/projects/", get_channel_name(channel), request.args, request.full_path)
@app.route('/<category>/projects/')
def route_category_projects(category):
return project_list(f"/{category}/projects/?x", category.title(), request.args, request.full_path)
return project_list(f"/{category}/projects/", category.title(), request.args, request.full_path)
@app.route('/projects/')
def route_projects():
return project_list("/projects/?x", '', request.args, request.full_path)
return project_list("/projects/", '', request.args, request.full_path)
@app.route('/circuits/')
def route_circuits():
return project_list("/circuits/?x", "Circuits", request.args, request.full_path)
return project_list("/circuits/", "Circuits", request.args, request.full_path)
@app.route('/workshop/')
def route_workshop():
return project_list("/workshop/?x", "Workshop", request.args, request.full_path)
return project_list("/workshop/", "Workshop", request.args, request.full_path)
@app.route('/craft/')
def route_craft():
return project_list("/craft/?x", "Craft", request.args, request.full_path)
return project_list("/craft/", "Craft", request.args, request.full_path)
@app.route('/cooking/')
def route_cooking():
return project_list("/cooking/?x", "Cooking", request.args, request.full_path)
return project_list("/cooking/", "Cooking", request.args, request.full_path)
@app.route('/living/')
def route_living():
return project_list("/living/?x", "Living", request.args, request.full_path)
return project_list("/living/", "Living", request.args, request.full_path)
@app.route('/outside/')
def route_outside():
return project_list("/outside/?x", "Outside", request.args, request.full_path)
return project_list("/outside/", "Outside", request.args, request.full_path)
@app.route('/teachers/')
def route_teachers():
@ -436,11 +442,11 @@ def route_teachers():
@app.route('/teachers/projects/')
def route_teachers_projects():
return project_list("/teachers/projects/?x", "Teachers", request.args, request.full_path, True)
return project_list("/teachers/projects/", "Teachers", request.args, request.full_path, True)
@app.route('/teachers/<category>/projects/')
def route_teachers_category_projects(category):
return project_list(f"/teachers/{category}/projects/?x", "Teachers", request.args, request.full_path, True)
return project_list(f"/teachers/{category}/projects/", "Teachers", request.args, request.full_path, True)
@app.route('/member/<member>/instructables/')
def route_member_instructables(member):