feat: Add /sitemap/projects/*/* endpoints

Signed-off-by: Skylar "The Cobra" Widulski <cobra@vern.cc>
This commit is contained in:
Skylar "The Cobra" Widulski 2023-06-10 12:02:47 -04:00
parent a47d40dcc2
commit 3f602c6342
Signed by: cobra
GPG Key ID: 4FD8F812083FF6F9
2 changed files with 40 additions and 0 deletions

18
main.py
View File

@ -248,6 +248,24 @@ def route_sitemap():
return render_template("sitemap.html", data=groups)
@app.route('/sitemap/projects/<category>/<channel>/')
def route_sitemap_projects(category, channel):
data = requests.get(f"https://www.instructables.com/sitemap/projects/{category}/{channel}/")
if data.status_code != 200:
return Response(render_template(str(data.status_code) + ".html"), status=data.status_code)
soup = BeautifulSoup(data.text, "html.parser")
main = soup.select("div.sitemap-content")[0]
articles = []
for li in main.select("ul.sitemap-listing li"):
article = li.a.text
article_link = li.a["href"]
articles.append([article, article_link])
return render_template("sitemap-projects.html", data=[category.title(), get_channel_name(channel), articles])
@app.route('/contest/archive/')
def route_contest_archive():
page = 1

View File

@ -0,0 +1,22 @@
<!DOCTYPE html>
<html>
<head>
<title>Sitemap - {{ data[1] }} {{ data[0] }} Projects - Destructables</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
{% include "style.html" %}
<link rel="icon" type="image/png" href="{{ url_for('static', filename='img/favicon.png') }}">
</head>
<body>
{% include "header.html" %}
<h1>Sitemap/{{ data[1] }} {{ data[0] }} Projects</h1>
<div class="sitemap">
<ul>
{% for article in data[2] %}
<li><a href="{{ article[1] }}">{{ article[0] }}</a></li>
{% endfor %}
</ul>
</div>
{% include "footer.html" %}
</body>
</html>