[gnome-maps/wip/mlundblad/wikidata: 7/9] WIP: wikipedia: Add function to fetch Wikidata tag for an article
- From: Marcus Lundblad <mlundblad src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps/wip/mlundblad/wikidata: 7/9] WIP: wikipedia: Add function to fetch Wikidata tag for an article
- Date: Sat, 15 Oct 2022 21:52:27 +0000 (UTC)
commit f1910fd286a7fc3b8d3aaefaa3fe83c5a86ec81e
Author: Marcus Lundblad <ml dfupdate se>
Date: Tue Oct 11 23:09:16 2022 +0200
WIP: wikipedia: Add function to fetch Wikidata tag for an article
src/wikipedia.js | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
---
diff --git a/src/wikipedia.js b/src/wikipedia.js
index b5f17a15..be8c398a 100644
--- a/src/wikipedia.js
+++ b/src/wikipedia.js
@@ -225,6 +225,33 @@ export function fetchArticleInfoForWikidata(wikidata, defaultArticle,
});
}
+function fetchWikidataForArticle(wiki, cancellable, callback) {
+ let lang = getLanguage(wiki);
+ let title = getHtmlEntityEncodedArticle(wiki);
+ let uri = 'https://www.wikidata.org/w/api.php';
+ let encodedForm = Soup.form_encode_hash({ action: 'wbgetentities',
+ sites: lang + 'wiki',
+ title: title,
+ format: 'json' });
+ let msg = Soup.Message.new_from_encoded_form('GET', uri, encodedForm);
+ let session = _getSoupSession();
+
+ session.send_and_read_async(msg, GLib.PRIORIRY_DEFAULT, cancellable,
+ (source, res) => {
+ if (msg.get_status() !== Soup.Status.OK) {
+ log("Failed to request Wikidata entities: " + msg.reason_phrase);
+ callback(null);
+ return;
+ }
+
+ let buffer = session.send_and_read_finish(res).get_data();
+ let response = JSON.parse(Utils.getBufferText(buffer));
+ let id = Object.values(response.entities ?? [])?.[0]?.id;
+
+ callback(id);
+ });
+}
+
function _onWikidataFetched(wikidata, defaultArticle, response, size,
metadataCb, thumbnailCb) {
let sitelinks = response?.entities?.[wikidata]?.sitelinks;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]