diff --git a/.gitignore b/.gitignore
index 613f75e..0dcd64f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,4 +2,3 @@ __pycache__
.mypy_cache/
node_modules
package-lock.json
-static/bootstrap
diff --git a/add_links/wikidata_oauth.py b/add_links/wikidata_oauth.py
index 9b4de72..d91b66e 100644
--- a/add_links/wikidata_oauth.py
+++ b/add_links/wikidata_oauth.py
@@ -1,10 +1,7 @@
-"""Wikipedia OAuth."""
-
import typing
import urllib
from typing import cast
-import requests
from flask import current_app, session
from requests_oauthlib import OAuth1Session
@@ -12,12 +9,6 @@ wiki_hostname = "en.wikipedia.org"
api_url = f"https://{wiki_hostname}/w/api.php"
-class LoginNeeded(Exception):
- """Not logged in."""
-
- pass
-
-
def get_edit_proxy() -> dict[str, str]:
"""Retrieve proxy information from config."""
edit_proxy = current_app.config.get("EDIT_PROXY")
@@ -27,7 +18,7 @@ def get_edit_proxy() -> dict[str, str]:
return {}
-def api_post_request(params: dict[str, str | int]) -> requests.Response:
+def api_post_request(params: dict[str, str | int]):
"""HTTP Post using Oauth."""
app = current_app
# url = "https://www.wikidata.org/w/api.php"
@@ -43,14 +34,12 @@ def api_post_request(params: dict[str, str | int]) -> requests.Response:
return oauth.post(api_url, data=params, timeout=4, proxies=proxies)
-def raw_request(params: typing.Mapping[str, str | int]) -> requests.Response:
+def raw_request(params: typing.Mapping[str, str | int]):
"""Low-level API request."""
app = current_app
# url = "https://www.wikidata.org/w/api.php?" + urlencode(params)
client_key = app.config["CLIENT_KEY"]
client_secret = app.config["CLIENT_SECRET"]
- if "owner_key" not in session or "owner_secret" not in session:
- raise LoginNeeded
oauth = OAuth1Session(
client_key,
client_secret=client_secret,
diff --git a/templates/article.html b/templates/article.html
index 55d05b0..ec3d3e4 100644
--- a/templates/article.html
+++ b/templates/article.html
@@ -1,48 +1,56 @@
{% extends "base.html" %}
-{% block title %}Link '{{ title }}' in '{{ hit_title }}'{% endblock %}
+{% block title %}{{ title }}{% endblock %}
{% block style %}
-
+
{% endblock %}
{% block content %}
-
Link '{{ title }}' in '{{ hit_title }}'
-
-
-
Username: {{ g.user }}
-
-
-
-
-
-
total: {{ total }}
-
with link: {{ with_link }}
-
ratio: {{ "{:.1%}".format(with_link / total) }}
- {#
hit: {{ hit }}
#}
-
replacement: {{ found.replacement }}
-
section: {{ found.section }}
-
-
-
-
- {% for hit in hits %}
- {% set url = url_for("article_page", url_title=url_title, title=hit.title) %}
- - {{ hit.title }} – {{ hit.snippet | safe }}
- {% endfor %}
-
+
+
+
+
+
+
{% endblock %}
diff --git a/templates/article2.html b/templates/article2.html
new file mode 100644
index 0000000..e6ef74c
--- /dev/null
+++ b/templates/article2.html
@@ -0,0 +1,41 @@
+{% extends "base.html" %}
+
+{% block title %}Link '{{ title }}' in '{{ hit.title }}'{% endblock %}
+
+{% block style %}
+
+{% endblock %}
+
+{% block content %}
+
+
Link '{{ title }}' in '{{ hit.title }}'
+
+
+
Username: {{ g.user }}
+
+
+
+
+
+
total: {{ total }}
+
with link: {{ with_link }}
+
ratio: {{ "{:.1%}".format(with_link / total) }}
+ {#
hit: {{ hit }}
#}
+
replacement: {{ found.replacement }}
+
section: {{ found.section }}
+
+
+
+{% endblock %}
+
diff --git a/templates/article_old.html b/templates/article_old.html
deleted file mode 100644
index ec3d3e4..0000000
--- a/templates/article_old.html
+++ /dev/null
@@ -1,56 +0,0 @@
-{% extends "base.html" %}
-
-{% block title %}{{ title }}{% endblock %}
-
-{% block style %}
-
-{% endblock %}
-
-{% block content %}
-
-
{{ self.title() }}
-
-
-
-
-
-
-
-
-{% endblock %}
-
diff --git a/web_view.py b/web_view.py
index 436307a..5e1e507 100755
--- a/web_view.py
+++ b/web_view.py
@@ -236,7 +236,7 @@ def match_type(q: str, snippet: str) -> str | None:
class NoGoodHit(Exception):
- """No good hit."""
+ pass
def get_best_hit(title: str, hits: list[Hit]) -> tuple[Hit, dict[str, typing.Any]]:
@@ -266,47 +266,35 @@ def article_page(url_title: str) -> str | Response:
if flask.request.method == "POST":
hit_title = flask.request.form["hit"]
- try:
- do_save(from_title, hit_title)
- except wikidata_oauth.LoginNeeded:
- return flask.redirect(flask.url_for("start_oauth"))
+ do_save(from_title, hit_title)
return flask.redirect(
flask.url_for("article_page", url_title=url_title, after=hit_title)
)
- article_title = flask.request.args.get("title")
-
total = search_count(from_title)
with_link = search_count_with_link(from_title)
no_link_count, hits = search_no_link(from_title)
- by_title = {hit["title"]: hit for hit in hits}
+ after = flask.request.args.get("after")
+ if after:
+ print(after)
+ hits_iter = itertools.dropwhile(lambda hit: hit["title"] != after, hits)
+ skip = next(hits_iter, None)
+ if skip:
+ hits = list(hits_iter)
- if article_title in by_title:
- hit = by_title[article_title]
- found = get_diff(from_title, hit["title"], None)
- else:
- after = flask.request.args.get("after")
- if after:
- print(after)
- hits_iter = itertools.dropwhile(lambda hit: hit["title"] != after, hits)
- skip = next(hits_iter, None)
- if skip:
- hits = list(hits_iter)
-
- try:
- hit, found = get_best_hit(from_title, hits)
- except NoGoodHit:
- return flask.render_template("all_done.html")
+ try:
+ hit, found = get_best_hit(from_title, hits)
+ except NoGoodHit:
+ return flask.render_template("all_done.html")
return flask.render_template(
- "article.html",
+ "article2.html",
title=from_title,
total=total,
with_link=with_link,
- hit_title=hit["title"],
- hits=hits,
+ hit=hit,
replacement=found["replacement"],
diff=found["diff"],
found=found,