forked from iamstarkov/jsunderhood
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.js
68 lines (56 loc) · 2.56 KB
/
update.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
require('dotenv').config();
const { outputFile } = require('fs-extra');
const { isEmpty, concat, reverse, last, dissoc, map, head } = require('ramda');
const moment = require('moment');
const { default: dec } = require('bignum-dec');
const { sync } = require('rimraf');
const tokens = {
consumer_key: process.env.TWITTER_CONSUMER_KEY,
consumer_secret: process.env.TWITTER_CONSUMER_SECRET,
access_token: process.env.TWITTER_ACCESS_TOKEN_KEY,
access_token_key: process.env.TWITTER_ACCESS_TOKEN_KEY,
access_token_secret: process.env.TWITTER_ACCESS_TOKEN_SECRET,
};
const getTweets = require('get-tweets');
const getInfo = require('get-twitter-info');
const getFollowers = require('get-twitter-followers');
const log = require('./helpers/log');
const { underhood } = require('./.underhoodrc.json');
const authors = require('./authors');
const saveMedia = require('./helpers/save-media');
// const twitterMentions = require('twitter-mentions');
const ensureFilesForFirstUpdate = require('./helpers/ensure-author-files');
const getAuthorArea = require('./helpers/get-author-area');
const saveAuthorArea = require('./helpers/save-author-area');
const { authorId, first, username } = head(authors);
ensureFilesForFirstUpdate(authorId);
const tweets = getAuthorArea(authorId, 'tweets').tweets || [];
// const mentions = getAuthorArea(authorId, 'mentions').mentions || [];
const tweetsSinceId = isEmpty(tweets) ? dec(first) : last(tweets).id_str;
getTweets(tokens, underhood, tweetsSinceId).then((newTweetsRaw) => {
const concattedTweets = concat(tweets, reverse(newTweetsRaw));
saveAuthorArea(authorId, 'tweets', { tweets: concattedTweets });
});
getInfo(tokens, underhood).then((info) => {
saveAuthorArea(authorId, 'info', info);
});
sync(`./dump/images/${username}*`);
saveMedia(tokens, underhood, authorId, (err, media) => {
if (err) throw err;
saveAuthorArea(authorId, 'media', media);
});
getFollowers(tokens, underhood, (err, followersWithStatuses) => {
if (err) throw err;
const followers = map(dissoc('status'), followersWithStatuses);
saveAuthorArea(authorId, 'followers', { followers });
});
saveAuthorArea(authorId, 'mentions', { mentions: [] });
// const mentionsSinceId = isEmpty(mentions) ? first : last(mentions).id_str;
// twitterMentions(tokens, mentionsSinceId, (err, newMentionsRaw) => {
// if (err) throw err;
// const concattedMentions = concat(mentions, reverse(newMentionsRaw));
// saveAuthorArea(authorId, 'mentions', { mentions: concattedMentions });
// });
outputFile('./dump/.timestamp', moment().unix(), (err) => {
log(`${err ? '✗' : '✓'} timestamp`);
});