[gnome-maps/wip/mlundblad/wikidata: 1/2] WIP: wikipedia: Add function to fetch article from Wikidata
- From: Marcus Lundblad <mlundblad src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps/wip/mlundblad/wikidata: 1/2] WIP: wikipedia: Add function to fetch article from Wikidata
- Date: Tue, 4 Oct 2022 21:37:12 +0000 (UTC)
commit e198244928be2d5c69c9c9857a990a249bc75f7f
Author: Marcus Lundblad <ml dfupdate se>
Date: Tue Oct 4 23:23:49 2022 +0200
WIP: wikipedia: Add function to fetch article from Wikidata
src/wikipedia.js | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
---
diff --git a/src/wikipedia.js b/src/wikipedia.js
index 80ad3a7d..95d592e6 100644
--- a/src/wikipedia.js
+++ b/src/wikipedia.js
@@ -155,6 +155,29 @@ export function fetchArticleInfo(wiki, size, metadataCb, thumbnailCb) {
});
}
+export function fetchArticleForWikidata(wikidata, callback) {
+ let uri = 'https://www.wikidata.org/w/api.php';
+ let encodedForm = Soup.form_encode_hash({ action: 'wbgetentities',
+ ids: wikidata,
+ 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, null,
+ (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));
+
+ Utils.debug('entities: ' + JSON.stringify(response, '', 2));
+ });
+}
+
function _onMetadataFetched(wiki, page, size, metadataCb, thumbnailCb) {
/* Try to get a thumbnail *before* following language links--the primary
article probably has the best thumbnail image */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]