refactor
This commit is contained in:
parent
5f8900a47a
commit
b1f402e1f9
|
@ -147,7 +147,7 @@ class Article:
|
|||
|
||||
def __init__(self, enwiki: str) -> None:
|
||||
"""Make a new Article object."""
|
||||
self.enwiki = enwiki
|
||||
self.enwiki = enwiki.replace("_", " ")
|
||||
|
||||
self.links = get_article_links(enwiki)
|
||||
|
||||
|
|
22
web_view.py
22
web_view.py
|
@ -3,6 +3,7 @@
|
|||
import inspect
|
||||
import json
|
||||
import re
|
||||
from typing import Optional
|
||||
|
||||
import flask
|
||||
import lxml.html
|
||||
|
@ -123,16 +124,23 @@ def save(enwiki: str) -> Response | str:
|
|||
)
|
||||
|
||||
|
||||
def redirect_if_needed(enwiki: str) -> Optional[Response]:
|
||||
"""Check if there are spaces in the article name and redirect."""
|
||||
return (
|
||||
flask.redirect(
|
||||
flask.url_for(flask.request.endpoint, enwiki=enwiki.replace(" ", "_"))
|
||||
)
|
||||
if " " in enwiki
|
||||
else None
|
||||
)
|
||||
|
||||
|
||||
@app.route("/enwiki/<path:enwiki>")
|
||||
def article_page(enwiki: str) -> Response:
|
||||
"""Article Page."""
|
||||
enwiki_orig = enwiki
|
||||
enwiki = enwiki.replace("_", " ")
|
||||
enwiki_underscore = enwiki.replace(" ", "_")
|
||||
if " " in enwiki_orig:
|
||||
return flask.redirect(
|
||||
flask.url_for(flask.request.endpoint, enwiki=enwiki_underscore)
|
||||
)
|
||||
redirect = redirect_if_needed(enwiki)
|
||||
if redirect:
|
||||
return redirect
|
||||
|
||||
article = wikipedia.Article(enwiki)
|
||||
article.load()
|
||||
|
|
Loading…
Reference in a new issue