-
Notifications
You must be signed in to change notification settings - Fork 0
/
embraport.js
78 lines (61 loc) · 1.82 KB
/
embraport.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
function postProcess(output, input) {
const parseMonth = (monthPT) => {
switch(monthPT) {
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, monthText, year, trash1, trash2;
[day, trash1, monthText, trash2, year] = date.split(" ");
let month = parseMonth(monthText.toLowerCase());
let currentDate = new Date();
let hoursAndMinutes = currentDate.getHours() + ':' + currentDate.getMinutes();
let formattedDate = `${month}/${day}/${year}`;
let formattedDateTime = `${formattedDate} ${hoursAndMinutes}`;
return new Date(formattedDateTime).toString();
}
return new Date().toString();
}
var processedArticles = output.data.articles.map(
article => {
if(!article.title || !article.link) {
return {valid: false}
}
let pubdate = parseDate(article.pubdate);
article.image = image[0];
article.pubdate = pubdate;
article.date = new Date().toString();
article.author = "Embraport / DP World Santos";
article.valid = true;
article.summary = article.description;
return article;
});
output.data.articles = processedArticles;
return output;
}