summaryrefslogtreecommitdiff
path: root/Toronto Star.js
blob: 4662c7f5846a54936fe43cea6d342370e095677e (plain)
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
{
	"translatorID": "6b0b11a6-9b77-4b49-b768-6b715792aa37",
	"label": "Toronto Star",
	"creator": "Adam Crymble, Avram Lyon",
	"target": "^https?://www\\.thestar\\.com",
	"minVersion": "3.0",
	"maxVersion": "",
	"priority": 100,
	"inRepository": true,
	"translatorType": 4,
	"browserSupport": "gcsibv",
	"lastUpdated": "2014-04-04 10:01:02"
}

function detectWeb(doc, url) {
	if (url.indexOf("search") != -1 && url.indexOf("classifieds") == -1) {
		return "multiple";
	} else if (ZU.xpathText(doc, '//div[@class="article-headline"]/h2|//div[@class="article-headline"]/h1')) {
		return "newspaperArticle";
	} else if (ZU.xpathText(doc, '//div[@class="blog-headline"]/strong', doc)){
		return "blogPost"
	}
}

//Toronto Star translator. code by Adam Crymble

function scrape(doc, url) {
	var newItem = new Zotero.Item(detectWeb(doc, url));
	if (newItem.itemType == "newspaperArticle"){
			var date = ZU.xpathText(doc, '//span[@class="published-date"]');
	if(date) {
		newItem.date = date.replace(/Published on/,'').replace(/[,\n\t\s]*$/, "").trim();
	}
	
	newItem.abstractNote = ZU.xpathText(doc, '//meta[@name="description"]/@content');
	var comma = false;
	var authorNode = ZU.xpathText(doc, '//div[@class="article-authors"]/span[@class="credit"]');
	if (authorNode) authorNode = authorNode.split(/\s*,\s*/);
	var authorNode2 =ZU.xpathText(doc, '//span[@class="columnistLabel"]/a');
	if (authorNode2) {
		authorNode = authorNode2.split(/\s*[;,]\s*/);
		 comma = false;}
	var author;
	if (authorNode){
			for(var i=0, n=authorNode.length; i<n; i++) {
			author = authorNode[i];
			newItem.creators.push(ZU.cleanAuthor(author, "author", comma));
		}
	}
	newItem.title = ZU.xpathText(doc, '//div[@class="article-headline"]/h2');
	if (!newItem.title) newItem.title = ZU.xpathText(doc, '//div[@class="article-headline"]/h1');

	// The section is the first listed keyword
	var keywords = ZU.xpath(doc, '//meta[@name="Keywords"][@content]')[0];
	if (keywords) newItem.section = keywords.textContent.split(',')[0];


	newItem.publicationTitle = "The Toronto Star";
	newItem.ISSN = "0319-0781";
	
	}
	else{
		newItem.title = ZU.xpathText(doc, '//div[@class="blog-headline"]/strong');
		newItem.date = ZU.xpathText(doc, '//div[@class="blog-entry-top"]/span[@class="date"]');
		var authors = ZU.xpath(doc, '//div[@class="blog-entry-top"]/span[@class="blog-tags"]/a');
		for (var i=0; i<authors.length; i++){
			newItem.creators.push(ZU.cleanAuthor(authors[i].textContent, "author"));
		}
		newItem.publicationTitle = "Toronto Star Blogs - " + ZU.xpathText(doc, '//div[@class="logo"]/strong[@class="heading"]') ;
	}
	newItem.url = url;
	newItem.attachments.push({document:doc, title:"Toronto Star Snapshot", mimeType:'text/html'});
	newItem.complete();
}

function doWeb(doc, url) {
	if (detectWeb(doc, url) == "multiple") {
		var items = ZU.getItemArray(doc, ZU.xpath(doc, '//div[contains(@class, "article-list")]'), /thestar\.com/);
		Zotero.selectItems(items, function(selectedItems) {
			if(!selectedItems) return true;
			var articles = new Array();
			for (var i in selectedItems) {
				articles.push(i);
			}
			ZU.processDocuments(articles, scrape);
		});
	} else {
		scrape(doc, url);
	}
}

/** BEGIN TEST CASES **/
var testCases = [
	{
		"type": "web",
		"url": "http://www.thestar.com/news/world/2010/01/26/france_should_ban_muslim_veils_commission_says.html",
		"items": [
			{
				"itemType": "newspaperArticle",
				"creators": [],
				"notes": [],
				"tags": [],
				"seeAlso": [],
				"attachments": [
					{
						"title": "Toronto Star Snapshot",
						"mimeType": "text/html"
					}
				],
				"date": "Tue Jan 26 2010",
				"abstractNote": "France's National Assembly should pass a resolution denouncing full Muslim face veils and then vote the strictest law possible to ban women from wearing them, a parliamentary commission proposed on Tuesday.",
				"title": "France's National Assembly should pass a resolution denouncing full Muslim face veils and then vote the strictest law possible to ban women from wearing them, a parliamentary commission proposed on Tuesday.",
				"url": "http://www.thestar.com/news/world/2010/01/26/france_should_ban_muslim_veils_commission_says.html",
				"publicationTitle": "The Toronto Star",
				"ISSN": "0319-0781",
				"libraryCatalog": "Toronto Star",
				"accessDate": "CURRENT_TIMESTAMP"
			}
		]
	},
	{
		"type": "web",
		"url": "http://www.thestar.com/business/tech_news/2011/07/29/hamilton_ontario_should_reconsider_offshore_wind.html",
		"items": [
			{
				"itemType": "newspaperArticle",
				"creators": [
					{
						"firstName": "Tyler",
						"lastName": "Hamilton",
						"creatorType": "author"
					}
				],
				"notes": [],
				"tags": [],
				"seeAlso": [],
				"attachments": [
					{
						"title": "Toronto Star Snapshot",
						"mimeType": "text/html"
					}
				],
				"date": "Fri Jul 29 2011",
				"abstractNote": "There&rsquo;s no reason why Ontario can&rsquo;t regain the momentum it once had.",
				"title": "There’s no reason why Ontario can’t regain the momentum it once had.",
				"url": "http://www.thestar.com/business/tech_news/2011/07/29/hamilton_ontario_should_reconsider_offshore_wind.html",
				"publicationTitle": "The Toronto Star",
				"ISSN": "0319-0781",
				"libraryCatalog": "Toronto Star",
				"accessDate": "CURRENT_TIMESTAMP"
			}
		]
	},
	{
		"type": "web",
		"url": "http://www.thestar.com/news/canada/2012/07/03/bev_oda_resigns_as_international_cooperation_minister_conservative_mp_for_durham.html",
		"items": [
			{
				"itemType": "newspaperArticle",
				"creators": [
					{
						"firstName": "Joanna",
						"lastName": "Smith",
						"creatorType": "author"
					},
					{
						"firstName": "Allan",
						"lastName": "Woods",
						"creatorType": "author"
					}
				],
				"notes": [],
				"tags": [],
				"seeAlso": [],
				"attachments": [
					{
						"title": "Toronto Star Snapshot",
						"mimeType": "text/html"
					}
				],
				"date": "Tue Jul 03 2012",
				"abstractNote": "Bev Oda will leave politics later this month following a series of scandals over her travel expenses and funding decisions.",
				"title": "Bev Oda will leave politics later this month following a series of scandals over her travel expenses and funding decisions.",
				"url": "http://www.thestar.com/news/canada/2012/07/03/bev_oda_resigns_as_international_cooperation_minister_conservative_mp_for_durham.html",
				"publicationTitle": "The Toronto Star",
				"ISSN": "0319-0781",
				"libraryCatalog": "Toronto Star",
				"accessDate": "CURRENT_TIMESTAMP"
			}
		]
	},
	{
		"type": "web",
		"url": "http://www.thestar.com/search.html?q=labor&contenttype=articles%2Cvideos%2Cslideshows",
		"items": "multiple"
	},
	{
		"type": "web",
		"url": "http://www.thestar.com/yourtoronto/education_blog/2014/03/toronto_tustee_misbehaviour_isn_t_anything_new.html#",
		"items": [
			{
				"itemType": "blogPost",
				"creators": [
					{
						"firstName": "Kristin",
						"lastName": "Rushowy",
						"creatorType": "author"
					}
				],
				"notes": [],
				"tags": [],
				"seeAlso": [],
				"attachments": [
					{
						"title": "Toronto Star Snapshot",
						"mimeType": "text/html"
					}
				],
				"title": "Toronto trustee misbehaviour isn't anything new",
				"date": "Tue Mar 18 2014",
				"publicationTitle": "Toronto Star Blogs - Learning Curve",
				"url": "http://www.thestar.com/yourtoronto/education_blog/2014/03/toronto_tustee_misbehaviour_isn_t_anything_new.html#",
				"libraryCatalog": "Toronto Star",
				"accessDate": "CURRENT_TIMESTAMP"
			}
		]
	}
]
/** END TEST CASES **/