-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatoil.js
82 lines (67 loc) · 1.97 KB
/
statoil.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
function postProcess(output, input) {
const baseUrl = 'https://www.statoil.com.br';
const currentDateObj = new Date();
const currentDate = currentDateObj.toString();
const hoursAndMinutes = currentDateObj.getHours() + ':' + currentDateObj.getMinutes();
const parseMonth = (monthPT) => {
switch(monthPT.toLowerCase()) {
case 'janeiro':
return 1;
case 'fevereiro':
return 2;
case 'março':
return 3;
case 'abril':
return 4;
case 'maio':
return 5;
case 'junho':
return 6;
case 'julho':
return 7;
case 'agosto':
return 8;
case 'setembro':
return 9;
case 'outubro':
return 10;
case 'novembro':
return 11;
case 'dezembro':
return 12;
default:
return 1 + new Date().getMonth();
}
}
const parseDate = (date) => {
if(date) {
let day, month,year;
[day, month, year] = date.split(' de ');
let formattedDate = `${parseMonth(month)}/${day}/${year}`;
let formattedDateTime = `${formattedDate} ${hoursAndMinutes} GMT-0200`;
return new Date(formattedDateTime).toString();
}
return currentDate
}
var processedArticles = output.data.articles.map(
article => {
if(!article.title || !article.endpoint) {
return {valid: false}
}
let pubdate = parseDate(article.pubdate);
let link = `${baseUrl}${article.endpoint}`;
let description = article.description || "";
let image = `${baseUrl}${article.image}` || "";
article.pubdate = pubdate;
article.date = currentDate;
article.author = "Statoil Brasil";
article.valid = true;
article.summary = description;
article.description = description;
article.image = image;
article.link = link;
return article;
});
output.data.articles = processedArticles;
return output;
}