Skip to content

Commit a7c97a2

Browse files
committedDec 15, 2019
corrected missing character
1 parent ea8b035 commit a7c97a2

File tree

4 files changed

+114
-13
lines changed

4 files changed

+114
-13
lines changed
 

‎package-lock.json

+30-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎rest.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const { getImagesFromCommonsWithTitle } = require('./wikimedia-commons');
2828
const { getImagesFromFlickrWithTitle } = require('./flickr');
2929
const { getImagesCC } = require('./cc');
3030
const { getImagesEuropeana } = require('./europeana');
31+
const { getImagesYle } = require('./yle');
3132
const { getWikidata } = require('./wikidata');
3233
const { getWikidataByLatLon } = require('./wikidata-latlon');
3334
const { findWikidataItemFromWikipedia, getWikipediaData } = require('./wikipedia');
@@ -132,7 +133,8 @@ app.get('/images', asyncMiddleware(async function(req, res) {
132133
getImagesFromCommonsWithTitle(topic, req.query.commons_category),
133134
getImagesFromFlickrWithTitle(topic, req.query.lat, req.query.lon, req.query.maxradius),
134135
getImagesCC(topic),
135-
getImagesEuropeana(topic, language)
136+
getImagesEuropeana(topic, language),
137+
getImagesYle(topic, language)
136138
];
137139
const safeRequests = requests.map(promise => promise.catch(err => {
138140
console.error(err.stack);

‎wikimedia-commons.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ module.exports = {
2323
if (commonsCategory !== undefined) {
2424
requestConfig.params.generator = 'categorymembers';
2525
requestConfig.params.gcmtype = 'file';
26-
requestConfig.params.gcmtitl = 'Category:' + commonsCategory;
26+
requestConfig.params.gcmtitle = 'Category:' + commonsCategory;
2727
requestConfig.params.gcmlimit = 30;
2828
} else {
2929
requestConfig.params.generator = 'search';

‎yle.js

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
const axios = require('axios');
2+
const BASE_URL = "https://external.api.yle.fi";
3+
4+
module.exports = {
5+
async getImagesYle(topic) {
6+
7+
//construct query
8+
const requestConfig = {
9+
baseURL: BASE_URL + "/",
10+
url: "/v1/programs/items.json",
11+
method: "get",
12+
params: {
13+
app_id: "cac1239e",
14+
app_key: "71eab9be802dc9f2f142639673fc16f4",
15+
availability: "ondemand",
16+
mediaobject: "video",
17+
category: "5-130",
18+
order: "playcount.24h:desc",
19+
q: topic
20+
}
21+
}
22+
23+
const response = await axios.request(requestConfig);
24+
let images = [];
25+
26+
if (!response.data) {
27+
return [];
28+
}
29+
30+
for (var i = 0; i < response.data.length; i++) {
31+
var video = response.data[i];
32+
33+
//assign data to metadata properties
34+
var image = {
35+
actors: '',
36+
collection: '',
37+
creators: video.creator,
38+
datecreated: '',
39+
description: video.description,
40+
details: '',
41+
download_url: '',
42+
formats: '',
43+
geoLocations: '',
44+
id: '',
45+
imageRights: '',
46+
imageURL: '',
47+
infoURL: '',
48+
inscriptions: '',
49+
institutions: video.creator,
50+
inventoryNumber: '',
51+
language: video.language,
52+
license: '',
53+
license_id: '',
54+
license_link: '',
55+
license_version: '',
56+
materials: '',
57+
measurements: '',
58+
places: '',
59+
publisher: '',
60+
source: '',
61+
subjects: video.subject.title,
62+
thumbURL: '',
63+
title: video.title.fi,
64+
year: '',
65+
}
66+
67+
if (video.title) {
68+
image.title.push(video.title);
69+
}
70+
71+
images.push(image);
72+
}
73+
if(images.length > 30) { // Good practice
74+
images = images.slice(0, 30);
75+
}
76+
77+
78+
return images;
79+
}
80+
}

0 commit comments

Comments
 (0)
Please sign in to comment.