-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvidditcron.js
More file actions
112 lines (103 loc) · 3.49 KB
/
Copy pathvidditcron.js
File metadata and controls
112 lines (103 loc) · 3.49 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
var cronJob = require('cron').CronJob;
var jsdom = require('jsdom');
var job = new cronJob({
cronTime: '00 00 12 * * 0-6',
onTick: function() {
jsdom.env({
html: 'http://reddit.com/domain/youtube.com',
scripts: ['http://code.jquery.com/jquery.js'],
done: (function (errors, window) {
var $ = window.$;
var title1 = $.map($('#siteTable .thing:eq(1)'), function (thing) {
return{
title: $('a.title', thing).text(),
}
});
var title2 = $.map($('#siteTable .thing:eq(2)'), function (thing) {
return{
title: $('a.title', thing).text(),
}
});
var title3 = $.map($('#siteTable .thing:eq(3)'), function (thing) {
return{
title: $('a.title', thing).text(),
}
});
var href1 = $.map($('#siteTable .thing:eq(1)'), function (thing) {
return{
href: $('a.title', thing).attr('href'),
}
});
var href2 = $.map($('#siteTable .thing:eq(2)'), function (thing) {
return{
href: $('a.title', thing).attr('href'),
}
});
var href3 = $.map($('#siteTable .thing:eq(3)'), function (thing) {
return{
href: $('a.title', thing).attr('href'),
}
});
var permalink1 = $.map($('#siteTable .thing:eq(1)'), function (thing) {
return{
permalink: $('a.comments', thing).attr('href'),
}
});
var permalink2 = $.map($('#siteTable .thing:eq(2)'), function (thing) {
return{
permalink: $('a.comments', thing).attr('href'),
}
});
var permalink3 = $.map($('#siteTable .thing:eq(3)'), function (thing) {
return{
permalink: $('a.comments', thing).attr('href'),
}
});
var title1 = title1[0].title
var title2 = title2[0].title
var title3 = title3[0].title
var href1 = href1[0].href
//var href1a = 'http://www.youtube.com/embed/'+href1.substring(31,href1.length);
var href2 = href2[0].href
var href3 = href3[0].href
var permalink1 = permalink1[0].permalink
var permalink2 = permalink2[0].permalink
var permalink3 = permalink3[0].permalink
var currentdate = new Date();
var datetime = + (currentdate.getMonth()+1) + "/"
+currentdate.getDate() + "/"
+ currentdate.getFullYear() + " at "
+ currentdate.getHours() + ":"
+ currentdate.getMinutes();
//once you have the info to send the email. write the
var Sendgrid = require("sendgrid-web");
var sendgrid = new Sendgrid({
user: "",
key: ""
});
var html = '<body><font color="black"><h1><center><br><br>Here are the top videos on Reddit for '+datetime+'!</center></h1></font><br><br><br><br><font color="black"><h1><center>'+title1+'</center></h1></font><center>'+href1+'</center><br><center><a href='+permalink1+'>View Comments on Reddit</a></center><br><br><br><br><font color="black"><h1><center>'+title2+'</center></h1></font><center>'+href2+'</center><br><center><a href='+permalink2+'>View Comments on Reddit</a></center><br><br><br><br><font color="black"><h1><center>'+title3+'</center></h1></font><center>'+href3+'</center><br><center><a href='+permalink3+'>View Comments on Reddit</a></center><br><br><br><br></body>'
sendgrid.send({
to: '',
from: 'hackruviddit@gmail.com',
subject: 'Your Top Reddit Videos',
html: html
}, function (err) {
if (err) {
console.log(err);
} else {
console.log("Success.");
}
});
})
});
},
start: false,
timeZone: "America/New_York"
});
job.start();
var express = require('express')
, app = express();
app.get('/', function(req, res) {
res.send("OK");
});
app.listen(process.env.PORT || 3000);