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