-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
37 lines (34 loc) · 1.03 KB
/
main.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
const URL = 'https://developers.google.com/apps-script/releases'
const CACHE_KEY = 'rss'
const getFeed = () => {
const cache = CacheService.getScriptCache()
const cached = cache.get(CACHE_KEY)
if (cached) {
return cached
}
const content = UrlFetchApp.fetch(URL).getContentText()
const $ = Cheerio.load(content)
const items = []
$('h3').each((i, elem) => {
const _date = $(elem).attr('data-text')
if (_date) {
const id = $(elem).attr('id')
const link = `${URL}#${id}`
const title = $(elem).next().text().split('\n').join()
const date =
Utilities.formatDate(new Date(_date), 'GMT', 'E, dd MMM YYYY') +
' 00:00:00 GMT'
items.push({ link, date, title })
}
})
const template = HtmlService.createTemplateFromFile('rss')
template.items = items
const feed = template.evaluate().getContent()
cache.put(CACHE_KEY, feed, 60 * 60)
return feed
}
const doGet = () => {
return ContentService.createTextOutput(getFeed()).setMimeType(
ContentService.MimeType.RSS
)
}