-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrotate-and-change-pic.js
38 lines (31 loc) · 1.06 KB
/
rotate-and-change-pic.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
require('./globals');
var request = require('request');
var imgPath = path.join(ROOT, 'img', 'img.jpg');
var Twit = require('twit');
var T = new Twit(config.twitter);
var writeLog = function(msg) {
var p = path.join(ROOT, 'log', 'log.json');
fs.readFile(p, function(err, data) {
data = JSON.parse(data);
data.push(msg);
fs.writeFile(p, JSON.stringify(data, undefined, 2));
});
};
fs.exists(imgPath, function loop(exists) {
if (!exists) {
T.get('users/show', { screen_name: 'yaworsw' }, function(err, data, res) {
request(data.profile_image_url.replace('_normal', '')).pipe(fs.createWriteStream(imgPath)).on('close', function() {
loop(true);
});
});
} else {
require('./lib/modifiers/rotate')(imgPath, { degs: config.degs }).then(function() {
fs.readFile(imgPath, { encoding: 'base64' }, function(err, b64) {
T.post('account/update_profile_image', { image: b64, skip_status: 1 }, function(err, data, response) {
});
});
}, function() {
writeLog('error' + arguments);
});
}
});