-
Notifications
You must be signed in to change notification settings - Fork 1
/
fetchRss.gs
62 lines (44 loc) · 1.52 KB
/
fetchRss.gs
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
function parseXml() {
let xml = UrlFetchApp.fetch(BLOG_RSS_URL).getContentText();
let document = XmlService.parse(xml);
let root = document.getRootElement();
let channel = root.getChild('channel');
let items = channel.getChildren('item');
let summationList = []
items.forEach(item => {
summationList.push({
pubDate:new Date(item.getChild('pubDate').getText()),
title : item.getChild('title').getText(),
description : item.getChild('description').getText().replace(/<[^>]+>/g, ""),
link : item.getChild('link').getText(),
imageURL:getImageUrls(item.getChild('description').getText())
})
});
return summationList.filter(item=>DateFilter(item.pubDate))
}
function getImageUrls(html) {
var imageUrls = [];
// Regular expression to find image URLs
var regex = /<img[^>]+src=["']([^"']+)["']/g;
// Match all occurrences of the regex in the HTML
var matches = html.match(regex);
if (matches) {
// Extract the URLs from the matches
for (var i = 0; i < matches.length; i++) {
var match = matches[i];
var urlMatch = /src=["']([^"']+)["']/g.exec(match);
if (urlMatch && urlMatch.length > 1) {
var imageUrl = urlMatch[1];
imageUrls.push(imageUrl);
}
}
return imageUrls[0]
}
return null
}
function DateFilter(inputDate){
const eventDate = new Date(inputDate).getTime()
const dateNow = new Date().getTime()
const dateInterval = (eventDate-dateNow)/86400000
return dateInterval>=-1 && dateInterval<=0
}