-
Notifications
You must be signed in to change notification settings - Fork 28
/
new_post.js
48 lines (40 loc) · 1.2 KB
/
new_post.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
// -*- mode: js; indent-tabs-mode: nil; js-basic-offset: 4 -*-
//
// Copyright 2016 Shloka Desai <shloka@stanford.edu>
// Giovanni Campagna <gcampagn@cs.stanford.edu>
//
// See LICENSE for details
const Tp = require('thingpedia');
module.exports = new Tp.ChannelClass({
Name: 'GenericRSSPollingTrigger',
Extends: Tp.RSSPollingTrigger,
RequiredCapabilities: ['channel-state'],
interval: 3 * 3600 * 1000, // 3 hours
_init: function(engine, state, device) {
this.parent(engine, state, device);
this.url = this.device.url;
},
formatEvent(event) {
var title = event[0];
var link = event[1];
var img = event[2];
return [title, {
type: 'picture',
url: img
}];
},
_emit(entry) {
var title = entry[0];
var link = entry[1];
var xml = entry[2];
var updated = entry[4];
var regex = /<img.+src="([^"]+)"/g;
var match = regex.exec(xml.description[0]);
if (match === null) {
console.error('Failed to scrape PhdComics');
return;
}
var img = match[1];
this.emitEvent([title, link, img]);
}
});