-
Notifications
You must be signed in to change notification settings - Fork 786
/
Copy pathNewsnetTamedia.js
509 lines (480 loc) · 14.3 KB
/
NewsnetTamedia.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
{
"translatorID": "caecaea0-5d06-11df-a08a-0800200c9a66",
"label": "Newsnet/Tamedia",
"creator": "Philipp Zumstein",
"target": "^https?://((www\\.)?(tagesanzeiger|(bo\\.)?bernerzeitung|bazonline|derbund|lematin|24heures|landbote|zuonline|zsz|tdg|letemps)\\.ch/.)",
"minVersion": "3.0",
"maxVersion": "",
"priority": 100,
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsibv",
"lastUpdated": "2018-04-29 11:03:04"
}
/*
***** BEGIN LICENSE BLOCK *****
Copyright © 2016 Philipp Zumstein
This file is part of Zotero.
Zotero is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Zotero is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Zotero. If not, see <http://www.gnu.org/licenses/>.
***** END LICENSE BLOCK *****
*/
function detectWeb(doc, url) {
if (url.includes("/story/")) {
return "newspaperArticle";
} else if (url.includes("letemps.ch") && ZU.xpathText(doc, '//meta[@property="og:type"]/@content')) {
return "newspaperArticle";
} else if (url.includes("suche.html?") && getSearchResults(doc, true)) {
return "multiple";
}
}
function getSearchResults(doc, checkOnly) {
var items = {};
var found = false;
var rows = ZU.xpath(doc, '//div[@id="panelArticleItems"]//h3/a[contains(@href, "/story/")]');
for (var i=0; i<rows.length; i++) {
var href = rows[i].href;
var title = ZU.trimInternal(rows[i].textContent);
if (!href || !title) continue;
if (checkOnly) return true;
found = true;
items[href] = title;
}
return found ? items : false;
}
function doWeb(doc, url) {
if (detectWeb(doc, url) == "multiple") {
Zotero.selectItems(getSearchResults(doc, false), function (items) {
if (!items) {
return true;
}
var articles = [];
for (var i in items) {
articles.push(i);
}
ZU.processDocuments(articles, scrape);
});
} else {
scrape(doc, url);
}
}
function scrape(doc, url) {
var translator = Zotero.loadTranslator('web');
// Embedded Metadata
translator.setTranslator('951c027d-74ac-47d4-a107-9c3069ab7b48');
//translator.setDocument(doc);
translator.setHandler('itemDone', function (obj, item) {
var authors = ZU.xpath(doc, '//div[@id="mainColLeft"]//div[contains(@class, "storyInfo")]/span[contains(@class, "author")]/a[1]');
if (!authors || authors.length===0) authors = ZU.xpath(doc, '//div[@id="mainColLeft"]//div[contains(@class, "storyInfo")]/span[contains(@class, "author")]');
if (!authors || authors.length===0) authors = ZU.xpath(doc, '(//section[contains(@class, "article-info")])[1]//a[contains(@class, "article-author")]');
if (authors) {
for (let i=0; i<authors.length; i++) {
// Delete "Par" = From in authors name
let author = authors[i].textContent.replace(/^Par /, '');
item.creators.push(ZU.cleanAuthor(author, "author"));
}
}
var date = ZU.xpathText(doc, '//div[@id="mainColLeft"]//div[contains(@class, "storyInfo")]/time/span') ||
ZU.xpathText(doc, '//div[@id="mainColLeft"]//div[contains(@class, "storyInfo")]/time');
if (date) {
item.date = ZU.strToISO(date);
}
item.section = ZU.xpathText(doc, '//div[@id="mainNav"]/ul/li/a[contains(@class, "active")]');
var newspaperName = ZU.xpathText(doc, '(//img[@id="mainLogo"]/@alt)[1]');
if (newspaperName) {
item.publicationTitle = newspaperName;
}
if (url.includes("24heures.ch")
|| url.includes("lematin.ch")
|| url.includes("tdg.ch")
|| url.includes("letemps.ch")) {
item.language = "fr";
} else {
item.language = "de";
}
if (item.url && item.url.slice(0,2) == "//") {
item.url = "https:" + item.url;
}
item.ISSN = issnMapping(url);
var tags = ZU.xpath(doc, '//span[contains(@class, "tagWrapper")]');
if (tags) {
for (let i=0; i<tags.length; i++) {
item.tags.push(tags[i].textContent.trim());
}
}
item.complete();
});
translator.getTranslatorObject(function(trans) {
trans.itemType = "newspaperArticle";
trans.doWeb(doc, url);
});
}
function issnMapping(url) {
if (url.includes("tagesanzeiger.ch")) return "1422-9994";
if (url.includes("bernerzeitung.ch")) return "1424-1021";
if (url.includes("bazonline.ch")) return "1420-3006";
if (url.includes("derbund.ch")) return "0774-6156";
if (url.includes("lematin.ch")) return "1018-3736";
if (url.includes("24heures.ch")) return "1424-4039";
if (url.includes("tdg.ch")) return "1010-2248";
if (url.includes("letemps.ch")) return "1423-3967";
}/** BEGIN TEST CASES **/
var testCases = [
{
"type": "web",
"url": "https://www.tagesanzeiger.ch/wissen/natur/Duestere-Fakten-zum-Klimawandel/story/13137025",
"items": [
{
"itemType": "newspaperArticle",
"title": "Düstere Fakten zum Klimawandel",
"creators": [],
"date": "2011-11-10",
"ISSN": "1422-9994",
"abstractNote": "Der neueste Bericht der Internationalen Energieagentur ist besorgniserregend. Das Klima könnte sich noch viel stärker erwärmen als bisher erwartet.",
"language": "de",
"libraryCatalog": "www.tagesanzeiger.ch",
"publicationTitle": "Tages-Anzeiger",
"section": "Wissen",
"url": "https://www.tagesanzeiger.ch/wissen/natur/Duestere-Fakten-zum-Klimawandel/story/13137025",
"attachments": [
{
"title": "Snapshot"
}
],
"tags": [
{
"tag": "IEA"
},
{
"tag": "Klimaschutz"
}
],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "https://www.tagesanzeiger.ch/service/suche/suche.html?date=alle&order=date&key=arbeitsmarkt",
"items": "multiple"
},
{
"type": "web",
"url": "https://www.bernerzeitung.ch/schweiz/wie-praegt-uns-die-reformation-heute-noch/story/28184086",
"items": [
{
"itemType": "newspaperArticle",
"title": "Wie prägt uns die Reformation heute noch?",
"creators": [
{
"firstName": "Christoph",
"lastName": "Aebischer",
"creatorType": "author"
}
],
"date": "2016-12-28",
"ISSN": "1424-1021",
"abstractNote": "Vor bald 500 Jahren ging ein Ruck durch Europa. Martin Luthers Thesen erschütterten die Kirchenwelt. Nun sucht die reformierte Kirche der Schweiz im Jubiläumsjahr neue Thesen, die sie heute voranbringen.",
"language": "de",
"libraryCatalog": "www.bernerzeitung.ch",
"publicationTitle": "Berner Zeitung",
"section": "Schweiz",
"url": "https://www.bernerzeitung.ch/schweiz/wie-praegt-uns-die-reformation-heute-noch/story/28184086",
"attachments": [
{
"title": "Snapshot"
}
],
"tags": [],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "https://bazonline.ch/wirtschaft/konjunktur/warum-die-nationalbank-zurueckhaltung-ueben-kann/story/15326375",
"items": [
{
"itemType": "newspaperArticle",
"title": "Drei Gründe, warum sich SNB-Jordan entspannen kann",
"creators": [
{
"firstName": "Markus Diem",
"lastName": "Meier",
"creatorType": "author"
}
],
"date": "2016-12-28",
"ISSN": "1420-3006",
"abstractNote": "Devisen-Berg und Negativzinsen: Hat der Notenbanker-Albtraum der letzten Jahre den Tiefpunkt überwunden?",
"language": "de",
"libraryCatalog": "bazonline.ch",
"publicationTitle": "Basler Zeitung",
"section": "Wirtschaft",
"url": "https://bazonline.ch/wirtschaft/konjunktur/warum-die-nationalbank-zurueckhaltung-ueben-kann/story/15326375",
"attachments": [
{
"title": "Snapshot"
}
],
"tags": [
{
"tag": "Franken"
}
],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "https://www.derbund.ch/bern/stadt/der-letzte-stapi-geht/story/21950637",
"items": [
{
"itemType": "newspaperArticle",
"title": "Der letzte Stapi geht",
"creators": [
{
"firstName": "Simon",
"lastName": "Preisig",
"creatorType": "author"
}
],
"date": "2016-12-28",
"ISSN": "0774-6156",
"abstractNote": "Ob Wyss oder von Graffenried: Mit dem Rücktritt von Alexander Tschäppät geht in Bern – ja, in der Schweiz – eine Ära zu Ende. Die neue Generation von Stadtpräsidenten zählt mehr Manager als Charismatiker.",
"language": "de",
"libraryCatalog": "www.derbund.ch",
"publicationTitle": "Der Bund",
"section": "Bern",
"url": "https://www.derbund.ch/bern/stadt/der-letzte-stapi-geht/story/21950637",
"attachments": [
{
"title": "Snapshot"
}
],
"tags": [
{
"tag": "Alec von Graffenried"
},
{
"tag": "Alexander Tschäppät"
},
{
"tag": "Ursula Wyss"
}
],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "https://www.lematin.ch/monde/alep-prepare-reconstruction-titanesque/story/15949402",
"items": [
{
"itemType": "newspaperArticle",
"title": "Alep se prépare à une reconstruction titanesque",
"creators": [],
"date": "2016-12-28",
"ISSN": "1018-3736",
"abstractNote": "Les habitants attendent avec impatience les travaux de reconstruction dans ce qui était l'une des plus belles villes de Syrie avant la guerre.",
"language": "fr",
"libraryCatalog": "www.lematin.ch",
"publicationTitle": "Le Matin",
"url": "https://www.lematin.ch/monde/alep-prepare-reconstruction-titanesque/story/15949402",
"attachments": [
{
"title": "Snapshot"
}
],
"tags": [],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "https://www.zuonline.ch/front/ein-steuerstreit-weniger-fuer-die-zkb/story/31314504",
"items": [
{
"itemType": "newspaperArticle",
"title": "Ein Steuerstreit weniger für die ZKB",
"creators": [
{
"firstName": "Philipp",
"lastName": "Lenherr",
"creatorType": "author"
}
],
"date": "2016-12-28",
"abstractNote": "Die Zürcher Kantonalbank beendet den Steuerstreit mit Deutschland durch eine einmalige Zahlung von 5,7 Millionen Euro.",
"language": "de",
"libraryCatalog": "www.zuonline.ch",
"publicationTitle": "Zürcher Unterländer",
"url": "https://www.zuonline.ch/front/ein-steuerstreit-weniger-fuer-die-zkb/story/31314504",
"attachments": [
{
"title": "Snapshot"
}
],
"tags": [],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "https://www.zsz.ch/horgen/der-beste-elektroinstallateur-europas-kommt-aus-huetten/story/31921047",
"items": [
{
"itemType": "newspaperArticle",
"title": "Der beste Elektroinstallateur Europas kommt aus Hütten",
"creators": [
{
"firstName": "Reto",
"lastName": "Bächli",
"creatorType": "author"
}
],
"date": "2016-12-27",
"abstractNote": "Yvan Fässler gewann anfangs Dezember die Goldmedaille als bester Elektroinstallateur an den europäischen Berufsmeisterschaften in Göteborg. Es ist die Krönung nach Jahren intensiver Vorbereitung.",
"language": "de",
"libraryCatalog": "www.zsz.ch",
"publicationTitle": "Zürichsee-Zeitung",
"section": "Horgen",
"url": "https://www.zsz.ch/horgen/der-beste-elektroinstallateur-europas-kommt-aus-huetten/story/31921047",
"attachments": [
{
"title": "Snapshot"
}
],
"tags": [],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "https://www.tdg.ch/geneve/actu-genevoise/visite-pape-prepare-secret-geneve/story/24171745",
"items": [
{
"itemType": "newspaperArticle",
"title": "La visite du pape se prépare en secret à Genève",
"creators": [
{
"firstName": "Sébastien",
"lastName": "Jubin",
"creatorType": "author"
}
],
"date": "2018-04-18",
"ISSN": "1010-2248",
"abstractNote": "Dans 64 jours, le pape François sera en visite à Genève. Discrètement, sa garde rapprochée a repéré les lieux cette semaine.",
"language": "fr",
"libraryCatalog": "www.tdg.ch",
"publicationTitle": "TDG",
"section": "Genève",
"url": "https://www.tdg.ch/geneve/actu-genevoise/visite-pape-prepare-secret-geneve/story/24171745",
"attachments": [
{
"title": "Snapshot"
}
],
"tags": [],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "https://www.letemps.ch/suisse/cantons-alemaniques-veulent-raboter-montants-laide-sociale",
"items": [
{
"itemType": "newspaperArticle",
"title": "Des cantons alémaniques veulent raboter les montants de l’aide sociale",
"creators": [
{
"firstName": "Céline",
"lastName": "Zünd",
"creatorType": "author"
}
],
"date": "2018-04-17T18:33:00",
"ISSN": "1423-3967",
"abstractNote": "Le compromis intercantonal sur la définition du minimum vital est remis en question. Le sujet est au cœur de débats houleux dans plusieurs cantons, qui envisagent de réduire nettement les forfaits d’entretien",
"language": "fr",
"libraryCatalog": "www.letemps.ch",
"publicationTitle": "Le Temps",
"url": "https://www.letemps.ch/suisse/cantons-alemaniques-veulent-raboter-montants-laide-sociale",
"attachments": [
{
"title": "Snapshot"
}
],
"tags": [
{
"tag": "Economie suisse"
},
{
"tag": "Finances publiques"
},
{
"tag": "Impôts"
}
],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "https://www.tdg.ch/editorial/surveillance-assures-reveil-tardif/story/27369648",
"items": [
{
"itemType": "newspaperArticle",
"title": "Surveillance des assurés: un réveil tardif",
"creators": [
{
"firstName": "Sophie",
"lastName": "Simon",
"creatorType": "author"
}
],
"date": "2018-04-27",
"ISSN": "1010-2248",
"language": "fr",
"libraryCatalog": "www.tdg.ch",
"publicationTitle": "TDG",
"shortTitle": "Surveillance des assurés",
"url": "https://www.tdg.ch/editorial/surveillance-assures-reveil-tardif/story/27369648",
"attachments": [
{
"title": "Snapshot"
}
],
"tags": [],
"notes": [],
"seeAlso": []
}
]
}
]
/** END TEST CASES **/