-
Notifications
You must be signed in to change notification settings - Fork 0
/
tumblrPoster.js
69 lines (52 loc) · 1.97 KB
/
tumblrPoster.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
var tumblr = require('tumblr.js');
var request = require('request');
var fs = require('fs');
var gm = require('gm');
module.exports = {
process: function (qr, qrTimeData, qrWeatherData) {
var client = tumblr.createClient({
consumer_key: 'redacted',
consumer_secret: 'redacted',
token: 'redacted',
token_secret: 'redacted',
});
var blogName = 'qrtimegovernor';
var commaSeparatedTags = 'automated,QR,time,' + qrTimeData + ',' + qrWeatherData;
var download = function(uri, file, callback){
request.head(uri, function(err, res, body){
request(uri).pipe(fs.createWriteStream(file)).on('close', callback);
});
};
download(qr.time, 'time.png', function(){
download(qr.weather, 'weather.png', function(){
download('http://icons.wunderground.com/webcamramdisk/a/d/admin/1/current.jpg', 'current.jpg', function(){
gm()
.in('-page', '+0+150')
.in('current.jpg')
.in('-page', '+300+0')
.minify()
.in('time.png')
.minify()
.in('-page', '+0+0')
.in('weather.png')
.mosaic()
.write('qr_output.jpg', function (err) {
var imgToPost = fs.readFileSync('qr_output.jpg');
var buff = new Buffer(imgToPost).toString('base64');
var imageOptions = {
caption: qrTimeData + ' /// ' + qrWeatherData,
data64: buff,
tags: commaSeparatedTags
};
client.createPhotoPost(blogName, imageOptions, function (err, data) {
console.log('errors:');
console.log(err);
console.log('data:');
console.log(data);
});
})
});
});
});
}
}