-
Notifications
You must be signed in to change notification settings - Fork 756
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added translator for The Saturday Paper #3099
Open
jpwarren
wants to merge
3
commits into
zotero:master
Choose a base branch
from
jpwarren:saturday-paper
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,287 @@ | ||
{ | ||
"translatorID": "051797f9-02fa-4ca4-bd33-ddfa68114aed", | ||
"label": "The Saturday Paper Australia", | ||
"creator": "Justin Warren", | ||
"target": "https?://(www\\.)?thesaturdaypaper\\.com\\.au/", | ||
"minVersion": "5.0", | ||
"maxVersion": "", | ||
"priority": 100, | ||
"inRepository": true, | ||
"translatorType": 4, | ||
"browserSupport": "gcsibv", | ||
"lastUpdated": "2023-08-05 02:26:58" | ||
} | ||
|
||
/* | ||
***** BEGIN LICENSE BLOCK ***** | ||
|
||
Copyright © 2023 Justin Warren | ||
|
||
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) { | ||
var articlePageTitle = doc.querySelector('div.content > div > div.article-page > div.article-page__header > h1'); | ||
if (articlePageTitle) { | ||
return 'newspaperArticle'; | ||
} | ||
|
||
else if (getSearchResults(doc, true)) { | ||
return 'multiple'; | ||
} | ||
return false; | ||
} | ||
|
||
function getSearchResults(doc, checkOnly) { | ||
var items = {}; | ||
var found = false; | ||
var rows = doc.querySelectorAll('div.article'); | ||
for (let row of rows) { | ||
// TODO: check and maybe adjust | ||
let href = row.href; | ||
// TODO: check and maybe adjust | ||
let title = ZU.trimInternal(row.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') { | ||
let items = Zotero.selectItems(getSearchResults(doc, false)); | ||
if (!items) return; | ||
for (let url of Object.keys(items)) { | ||
scrape(requestDocument(url)); | ||
} | ||
} | ||
else if (detectWeb(doc, url)) { | ||
scrape(doc, url); | ||
} | ||
} | ||
|
||
function scrape(doc, url = doc.location.href) { | ||
let item = new Zotero.Item('newspaperArticle'); | ||
item.publicationTitle = "The Saturday Paper"; | ||
item.title = attr(doc, 'meta[name="dcterms.title"]', 'content'); | ||
item.date = ZU.strToISO(attr(doc, 'meta[name="dcterms.date"]', 'content')); | ||
item.abstractNote = attr(doc, 'meta[name="dcterms.description"]', 'content'); | ||
item.creators.push(ZU.cleanAuthor(attr(doc, 'meta[name="dcterms.creator"]', 'content'), "author")); | ||
item.language = "en-AU"; | ||
item.url = url; | ||
// The section name is the first part of the path after the FQDN in the url | ||
let pattern = /https?:\/\/(www\.)?thesaturdaypaper.com.au\/(\w+)/; | ||
var m = url.match(pattern); | ||
if (m) { | ||
item.section = ZU.capitalizeTitle(m[2], true); | ||
} | ||
let editionRaw = doc.querySelector('p.issue-nav__current').textContent; | ||
var em = editionRaw.match(/.*No\.\s(\d+)/); | ||
if (em) { | ||
item.edition = em[1]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we sure "edition" is the appropriate field? I think this refers to editions of a book, or in the context of newspapers, the different "prints" or versions of a particular day's issue, due to intra-day updates (edits). |
||
} | ||
item.attachments.push({ | ||
title: "Snapshot", | ||
document: doc | ||
}); | ||
item.complete(); | ||
} | ||
|
||
/** BEGIN TEST CASES **/ | ||
var testCases = [ | ||
{ | ||
"type": "web", | ||
"url": "https://www.thesaturdaypaper.com.au/comment/topic/2023/08/05/morrisons-strong-welfare-cop-out", | ||
"detectedItemType": "newspaperArticle", | ||
"items": [ | ||
{ | ||
"itemType": "newspaperArticle", | ||
"title": "Morrison’s strong welfare cop-out", | ||
"creators": [ | ||
{ | ||
"firstName": "Paul", | ||
"lastName": "Bongiorno", | ||
"creatorType": "author" | ||
} | ||
], | ||
"date": "2023-08-05", | ||
"abstractNote": "For a while, late on Monday afternoon in the house of representatives, you could be forgiven for thinking the Peter Dutton-led opposition had finally cast itself adrift from Scott Morrison. As the former prime minister rose, on indulgence from the speaker, to give his first public response to the excoriating findings of the Royal Commission into the Robodebt Scheme, you could hear a pin drop. Not because what Morrison was saying was riveting, but because the chamber was almost completely deserted.", | ||
"edition": "461", | ||
"language": "en-AU", | ||
"libraryCatalog": "The Saturday Paper Australia", | ||
"publicationTitle": "The Saturday Paper", | ||
"section": "Comment", | ||
"url": "https://www.thesaturdaypaper.com.au/comment/topic/2023/08/05/morrisons-strong-welfare-cop-out", | ||
"attachments": [ | ||
{ | ||
"title": "Snapshot", | ||
"mimeType": "text/html" | ||
} | ||
], | ||
"tags": [], | ||
"notes": [], | ||
"seeAlso": [] | ||
} | ||
] | ||
}, | ||
{ | ||
"type": "web", | ||
"url": "https://www.thesaturdaypaper.com.au/life/environment/2023/07/01/underwater-sculptures-preserving-the-great-barrier-reef", | ||
"detectedItemType": "newspaperArticle", | ||
"items": [ | ||
{ | ||
"itemType": "newspaperArticle", | ||
"title": "Underwater sculptures preserving the Great Barrier Reef", | ||
"creators": [ | ||
{ | ||
"firstName": "Mark", | ||
"lastName": "Dapin", | ||
"creatorType": "author" | ||
} | ||
], | ||
"date": "2023-07-01", | ||
"abstractNote": "On the day he and I do not take a catamaran to Queensland’s Museum of Underwater Art (MOUA), sculptor Jason deCaires Taylor is sipping a cold beer at a table in the Longboard Bar and Grill overlooking the Coral Sea. It’s a warm afternoon in Townsville, but the wind is too strong for our planned sail out to the reef to view his newly installed Ocean Sentinels – eight hybrid human and marine sculptures fixed on the seabed at a depth of four to six metres.", | ||
"edition": "456", | ||
"language": "en-AU", | ||
"libraryCatalog": "The Saturday Paper Australia", | ||
"publicationTitle": "The Saturday Paper", | ||
"section": "Life", | ||
"url": "https://www.thesaturdaypaper.com.au/life/environment/2023/07/01/underwater-sculptures-preserving-the-great-barrier-reef", | ||
"attachments": [ | ||
{ | ||
"title": "Snapshot", | ||
"mimeType": "text/html" | ||
} | ||
], | ||
"tags": [], | ||
"notes": [], | ||
"seeAlso": [] | ||
} | ||
] | ||
}, | ||
{ | ||
"type": "web", | ||
"url": "https://www.thesaturdaypaper.com.au/culture/the-influence/2023/08/03/laura-woollett", | ||
"detectedItemType": "newspaperArticle", | ||
"items": [ | ||
{ | ||
"itemType": "newspaperArticle", | ||
"title": "Laura Woollett", | ||
"creators": [ | ||
{ | ||
"firstName": "Neha", | ||
"lastName": "Kale", | ||
"creatorType": "author" | ||
} | ||
], | ||
"date": "2023-08-05", | ||
"abstractNote": "Laura Elizabeth Woollett is known for the short story collection The Love of a Bad Man and the novels The Newcomer and Beautiful Revolutionary. The latter, a gripping work inspired by Jim Jones’s Peoples Temple, was shortlisted for the 2019 Prime Minister’s Literary Award for Fiction and the Australian Literature Society Gold Medal.", | ||
"edition": "461", | ||
"language": "en-AU", | ||
"libraryCatalog": "The Saturday Paper Australia", | ||
"publicationTitle": "The Saturday Paper", | ||
"section": "Culture", | ||
"url": "https://www.thesaturdaypaper.com.au/culture/the-influence/2023/08/03/laura-woollett", | ||
"attachments": [ | ||
{ | ||
"title": "Snapshot", | ||
"mimeType": "text/html" | ||
} | ||
], | ||
"tags": [], | ||
"notes": [], | ||
"seeAlso": [] | ||
} | ||
] | ||
}, | ||
{ | ||
"type": "web", | ||
"url": "https://www.thesaturdaypaper.com.au/news/education/2023/08/05/exclusive-unsw-referred-icac", | ||
"detectedItemType": "newspaperArticle", | ||
"items": [ | ||
{ | ||
"itemType": "newspaperArticle", | ||
"title": "Exclusive: UNSW referred to ICAC", | ||
"creators": [ | ||
{ | ||
"firstName": "Rick", | ||
"lastName": "Morton", | ||
"creatorType": "author" | ||
} | ||
], | ||
"date": "2023-08-05", | ||
"abstractNote": "The manner in which Professor Attila Brungs was appointed to his $1 million-a-year role as vice-chancellor at UNSW Sydney, and the alleged retaliation against executives who raised concerns about the process, has been referred to the New South Wales Independent Commission Against Corruption by the state’s outgoing Tertiary Education minister.", | ||
"edition": "461", | ||
"language": "en-AU", | ||
"libraryCatalog": "The Saturday Paper Australia", | ||
"publicationTitle": "The Saturday Paper", | ||
"section": "News", | ||
"shortTitle": "Exclusive", | ||
"url": "https://www.thesaturdaypaper.com.au/news/education/2023/08/05/exclusive-unsw-referred-icac", | ||
"attachments": [ | ||
{ | ||
"title": "Snapshot", | ||
"mimeType": "text/html" | ||
} | ||
], | ||
"tags": [], | ||
"notes": [], | ||
"seeAlso": [] | ||
} | ||
] | ||
}, | ||
{ | ||
"type": "web", | ||
"url": "https://www.thesaturdaypaper.com.au/sport/soccer/2023/06/17/emily-van-egmonds-high-hopes-the-world-cup#hrd", | ||
"detectedItemType": "newspaperArticle", | ||
"items": [ | ||
{ | ||
"itemType": "newspaperArticle", | ||
"title": "Emily van Egmond’s high hopes for the World Cup", | ||
"creators": [ | ||
{ | ||
"firstName": "Sarah", | ||
"lastName": "Krasnostein", | ||
"creatorType": "author" | ||
} | ||
], | ||
"date": "2023-06-17", | ||
"abstractNote": "Matildas centurion Emily van Egmond speaks as rapidly and decisively as she responds on the pitch. It’s 7.30am in wintry Melbourne but 2.30pm in sunny San Diego, where the 29-year-old midfielder – who’s played her club soccer with San Diego Wave since January last year – chats via Zoom before heading home for the FIFA Women’s World Cup, which begins on July 20.", | ||
"edition": "454", | ||
"language": "en-AU", | ||
"libraryCatalog": "The Saturday Paper Australia", | ||
"publicationTitle": "The Saturday Paper", | ||
"section": "Sport", | ||
"url": "https://www.thesaturdaypaper.com.au/sport/soccer/2023/06/17/emily-van-egmonds-high-hopes-the-world-cup#hrd", | ||
"attachments": [ | ||
{ | ||
"title": "Snapshot", | ||
"mimeType": "text/html" | ||
} | ||
], | ||
"tags": [], | ||
"notes": [], | ||
"seeAlso": [] | ||
} | ||
] | ||
} | ||
] | ||
/** END TEST CASES **/ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, I think it suffices to make use of the 'Embedded Metadata' translator (such as by using the template code from Scaffold -> Tools menu -> Templates) for the majority of these fields. The EM translator will take care of these
<meta>
fields, and any improvements to EM translator will be automatically picked up by the translators that use it.