summaryrefslogtreecommitdiff
path: root/The Hindu.js
blob: e42abbe37dcfded88d77e1d7460cc64999faaf55 (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
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
{
    "translatorID": "06142d59-fa9c-48c3-982b-6e7c67d3d6b8",
    "label": "The Hindu",
    "creator": "Piyush Srivastava",
    "target": "https?://www\\.thehindu\\.com/.*ece",
    "minVersion": "1.0",
    "maxVersion": "",
    "priority": 100,
    "inRepository": true,
    "translatorType": 4,
    "browserSupport": "gcv",
    "lastUpdated": "2013-11-19 08:23:18"
}

/*****
   Copyright 2013, Piyush Srivastava.

   This program 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.

   This program 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 this program.  If not, see
   <http://www.gnu.org/licenses/>.

*****/

/**
The current Zotero translator for "The Hindu" interfaces only with the
newspaper's old website www.hindu.com (which is now used only for
archival purposes).  

This translator interfaces with www.thehindu.com, the current website
of the newspaper.

**/

function detectWeb(doc, url) {
    return "newspaperArticle";
}


function insertCreator(authorName, newItem){
    /*Check for some author name conventions unique to the Hindu*/
    /*Right now we are using the following: 
      
      1) PTI, a news agency, is often credited as an author on The
      Hindu articles.  We just change the author status to
      "contributor", and retain the capitalization.
      
      2) Some articles are bylined "Special Coresspondent".  Again, we
      change the author status to "contributor".
      
    */
    authorName = Zotero.Utilities.capitalizeTitle(authorName.toLowerCase(), true);
    authorStatus = "author";
    if (authorName == "Pti"){
	authorName = "PTI";
	authorStatus = "contributor";
	newItem.creators.push({lastName: authorName, 
			       creatorType: 'contributor', 
			       fieldMode: 1});
    } else if (authorName == "Special Correspondent"){
	authorStatus = "contributor";
	newItem.creators.push({lastName: "Correspondent", 
			       firstName: "Special", 
			       creatorType: 'contributor', 
			       fieldMode: 1});
    } else {
	newItem.creators.push(Zotero.Utilities.cleanAuthor(authorName, authorStatus));
    }
}

function scrape(doc, url){
    
    var newItem = new Zotero.Item('newspaperArticle');
    newItem.url = doc.location.href;
    newItem.language = "en-IN";
    
    
    newItem.publicationTitle = "The Hindu";
    newItem.ISSN = "0971-751X";
    
    //Get title of the news article via xpath
    var titleXPath = '//h1[@class="detail-title"]';
    var titleString = doc.evaluate(titleXPath, doc, null, XPathResult.ANY_TYPE, null).iterateNext().textContent;
    newItem.title = titleString;
    
    
    //Get author(s) of the article
    var authorXPath = '//span[@class="author"]';
    var authorListObject = doc.evaluate(authorXPath, doc, null, 
					XPathResult.ANY_TYPE, null);
    var authorObject = authorListObject.iterateNext();
    while (authorObject){
	insertCreator(authorObject.textContent, newItem);
	authorObject = authorListObject.iterateNext();
    }
    
    //date and Place
    var datePlaceXPath = '//span[@class="dateline"]';
    var placeXPath='//span[@class="dateline"]/span[@class="upper"]';
    var datePlaceString = doc.evaluate(datePlaceXPath, doc, null, XPathResult.ANY_TYPE, null).iterateNext().textContent;
    var placeString = doc.evaluate(placeXPath, doc, null, XPathResult.ANY_TYPE, null).iterateNext().textContent;
    var dateString = datePlaceString.replace(placeString, ""); //Remove place info from date
    dateString = dateString.replace(/^\s+|\s+$/g, '');
    placeString = placeString.replace(/^(\s|,)+|(\s|,)+$/g, '');
    newItem.place=Zotero.Utilities.capitalizeTitle(placeString, true);//remove trailing commans and whitespace;
    newItem.date=dateString;
    
    //keywords
    var keywordXPath='//div[@id="articleKeywords"]//a[@href="#"]';
    var keywordListObject  = doc.evaluate(keywordXPath, doc, null,
					  XPathResult.ANY_TYPE, null);
    var keywordObject = keywordListObject.iterateNext();
    while(keywordObject){
	newItem.tags.push(keywordObject.textContent);
	keywordObject = keywordListObject.iterateNext();
    }
    
    //Store a snapshot of the page
    newItem.attachments.push({
	title:"The Hindu Snapshot",
	document:doc});
    
    newItem.complete();
}


function doWeb(doc, url) {
    scrape(doc, url);
}
/** BEGIN TEST CASES **/
var testCases = [
	{
		"type": "web",
		"url": "http://www.thehindu.com/news/national/sincere-regrets-stop/article4914819.ece",
		"items": [
			{
				"itemType": "newspaperArticle",
				"creators": [
					{
						"firstName": "Shiv Sahay",
						"lastName": "Singh",
						"creatorType": "author"
					}
				],
				"notes": [],
				"tags": [
					"Telegram",
					"Telegraph service",
					"BSNL",
					"Telegram service discontinuation"
				],
				"seeAlso": [],
				"attachments": [
					{
						"title": "The Hindu Snapshot"
					}
				],
				"url": "http://www.thehindu.com/news/national/sincere-regrets-stop/article4914819.ece",
				"language": "en-IN",
				"publicationTitle": "The Hindu",
				"ISSN": "0971-751X",
				"title": "Telegram no more STOP 100 STOP",
				"place": "Kolkata",
				"date": "July 14, 2013",
				"libraryCatalog": "The Hindu",
				"accessDate": "CURRENT_TIMESTAMP"
			}
		]
	},
	{
		"type": "web",
		"url": "http://www.thehindu.com/features/once-favoured-now-forgotten/article4912011.ece?homepage=true",
		"items": [
			{
				"itemType": "newspaperArticle",
				"creators": [
					{
						"firstName": "Anusha",
						"lastName": "Parthasarathy",
						"creatorType": "author"
					},
					{
						"firstName": "Lakshmi",
						"lastName": "Krupa",
						"creatorType": "author"
					}
				],
				"notes": [],
				"tags": [
					"Transistor radio",
					"Cassette tapes",
					"Floppy discs",
					"VCR",
					"Pager",
					"Gramophone",
					"Typewriter",
					"Roll films",
					"Dial-up"
				],
				"seeAlso": [],
				"attachments": [
					{
						"title": "The Hindu Snapshot"
					}
				],
				"url": "http://www.thehindu.com/features/once-favoured-now-forgotten/article4912011.ece?homepage=true",
				"language": "en-IN",
				"publicationTitle": "The Hindu",
				"ISSN": "0971-751X",
				"title": "Once favoured, now forgotten",
				"place": "Chennai",
				"date": "July 14, 2013",
				"libraryCatalog": "The Hindu",
				"accessDate": "CURRENT_TIMESTAMP"
			}
		]
	},
	{
		"type": "web",
		"url": "http://www.thehindu.com/business/Economy/petrol-prices-to-go-up-by-rs-155-per-litre/article4914855.ece",
		"items": [
			{
				"itemType": "newspaperArticle",
				"creators": [
					{
						"lastName": "PTI",
						"creatorType": "contributor",
					        "fieldMode" : 1
					}
				],
				"notes": [],
				"tags": [
					"Petrol price hike",
					"oil marketing companies",
					"oil imports",
					"Rupee fall"
				],
				"seeAlso": [],
				"attachments": [
					{
						"title": "The Hindu Snapshot"
					}
				],
				"url": "http://www.thehindu.com/business/Economy/petrol-prices-to-go-up-by-rs-155-per-litre/article4914855.ece",
				"language": "en-IN",
				"publicationTitle": "The Hindu",
				"ISSN": "0971-751X",
				"title": "Petrol prices to go up by Rs. 1.55 per litre",
				"place": "New Delhi",
				"date": "July 14, 2013",
				"libraryCatalog": "The Hindu",
				"accessDate": "CURRENT_TIMESTAMP"
			}
		]
	},
	{
		"type": "web",
		"url": "http://www.thehindu.com/opinion/columns/Chandrasekhar/the-forgotten-software-boom/article4914571.ece",
		"items": [
			{
				"itemType": "newspaperArticle",
				"creators": [
					{
						"firstName": "C. P.",
						"lastName": "Chandrasekhar",
						"creatorType": "author"
					}
				],
				"notes": [],
				"tags": [
					"IT industry",
					"ITeS",
					"NASSCOM",
					"economic slowdown"
				],
				"seeAlso": [],
				"attachments": [
					{
						"title": "The Hindu Snapshot"
					}
				],
				"url": "http://www.thehindu.com/opinion/columns/Chandrasekhar/the-forgotten-software-boom/article4914571.ece",
				"language": "en-IN",
				"publicationTitle": "The Hindu",
				"ISSN": "0971-751X",
				"title": "The forgotten software boom",
				"date": "July 14, 2013",
				"libraryCatalog": "The Hindu",
				"accessDate": "CURRENT_TIMESTAMP"
			}
		]
	}
]
/** END TEST CASES **/