-
Notifications
You must be signed in to change notification settings - Fork 0
/
posttwitter.js
51 lines (43 loc) · 1.32 KB
/
posttwitter.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
var pubSubHubbub = require("pubsubhubbub");
//setting the date
var date=new Date();
var Twit = require('twit');
//setting up the configuration file
var config=require('./config');
//twitter api configuration keys
var T = new Twit(config);
console.log("started");
//receive notifications
var pubSubSubscriber = pubSubHubbub.createServer('https://cinema2.herokuapp.com');
var topic = "https://www.youtube.com/xml/feeds/videos.xml?channel_id=UCc2j-7dkYX1vjIKOjCO6zAw";
var hub = "http://pubsubhubbub.appspot.com/";
pubSubSubscriber.on("subscribe", function(data){
console.log(data.topic + " subscribed");
});
pubSubSubscriber.listen(process.env.PORT || 8080);
("listen", function(){
pubSubSubscriber.subscribe(topic, hub, function(err){
if(err){
console.log("Failed subscribing");
}
});
});
// fetch the recieved xml file and append the new url to the array
//code come here
url=['https://www.youtube.com/watch?v=ka_5cFW8kMU'];
//setting up the interval to tweet 1 hour
tweetit();
setInterval(tweetit, 1000*60*60);
function tweetit(){
var tweet={
status:'view the trailer '+url[0]+ date
}
T.post('statuses/update',tweet,tweeted);
function tweeted(err,data,response){
if(err){
console.log(err);
} else{
console.log("it worked");
}
}
}