-
Notifications
You must be signed in to change notification settings - Fork 3
/
replace-missing-profiles.js
84 lines (74 loc) · 2.69 KB
/
replace-missing-profiles.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
var _ = require('lodash');
require('./secret')();
db = require('./db');
var states = require('./src/scripts/data/states');
var statesKeys = Object.keys(states);
var twitterConfig = {
access_token_key: process.env.TWITTER_ACCESS_TOKEN,
access_token_secret: process.env.TWITTER_TOKEN_SECRET,
consumer_secret: process.env.TWITTER_CONSUMER_SECRET,
consumer_key: process.env.TWITTER_CONSUMER_KEY
};
var Twitter = require('twitter');
var client = new Twitter(twitterConfig);
var finish = _.after(statesKeys.length, process.exit);
_.each(statesKeys, function (key) {
var data;
db.Record.findOne({
path: '/getLegislators',
key: key
}, function (err, record) {
if (record) {
data = JSON.parse(record.data);
var done = _.after(data.legislator.length, function () {
record.data = JSON.stringify(data);
record.save(finish);
});
_.each(data.legislator, function (legislator) {
if (!legislator.$.profileImage) {
console.log(legislator.$);
client.get('users/show', { screen_name: legislator.$.twitter_id }, function (error, profile, response) {
if (error) {
legislator.$.profileImage
} else {
console.log(profile['profile_image_url'].replace('_normal', '_400x400'));
console.log(profile['profile_image_url']);
legislator.$.profileImage = profile['profile_image_url'].replace('_normal', '_400x400');
}
done();
});
} else {
done();
}
});
}
});
})
// var stateReplacement = {
// 'AK': {
// 'N00007999': '/web/images/profile.png'
// }
// }
// require('./secret')();
// db = require('./db');
// var done = _.after(Object.keys(stateReplacement).length, process.exit);
// _.each(stateReplacement, function (replacements, key) {
// var data;
// db.Record.findOne({
// path: '/getLegislators',
// key: key
// }, function (err, record) {
// if (record) {
// data = JSON.parse(record.data);
// _.each(replacements, function (newSrc, cid) {
// _.each(data.legislator, function (item) {
// // if (item.$.cid === cid) {
// item.$.profileImage = newSrc;
// // }
// });
// });
// record.data = JSON.stringify(data);
// record.save(done);
// }
// })
// });