This repository has been archived by the owner on Nov 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
update.js
62 lines (50 loc) · 2.14 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
import log from './helpers/log';
import { outputFile } from 'fs-extra';
import { isEmpty, concat, reverse, last, dissoc, map, head } from 'ramda';
import moment from 'moment';
import dec from 'bignum-dec';
import { sync as rm } from 'rimraf';
import { underhood } from './.underhoodrc.json';
import authors from './authors';
import tokens from 'twitter-tokens';
import getTweets from 'get-tweets';
import getInfo from 'get-twitter-info';
import saveMedia from './helpers/save-media';
import getFollowers from 'get-twitter-followers';
import twitterMentions from 'twitter-mentions';
import ensureFilesForFirstUpdate from './helpers/ensure-author-files';
import getAuthorArea from './helpers/get-author-area';
import saveAuthorArea from './helpers/save-author-area';
const { first, username } = head(authors);
ensureFilesForFirstUpdate(username);
const tweets = getAuthorArea(username, 'tweets').tweets || [];
const mentions = getAuthorArea(username, 'mentions').mentions || [];
const tweetsSinceId = isEmpty(tweets) ? dec(first) : last(tweets).id_str;
getTweets(tokens, underhood, tweetsSinceId, (err, newTweetsRaw) => {
if (err) throw err;
const concattedTweets = concat(tweets, reverse(newTweetsRaw));
saveAuthorArea(username, 'tweets', { tweets: concattedTweets });
});
getInfo(tokens, underhood, (err, info) => {
if (err) throw err;
saveAuthorArea(username, 'info', info);
});
rm(`./dump/images/${username}*`);
saveMedia(tokens, underhood, username, (err, media) => {
if (err) throw err;
saveAuthorArea(username, 'media', media);
});
getFollowers(tokens, underhood, (err, followersWithStatuses) => {
if (err) throw err;
const followers = map(dissoc('status'), followersWithStatuses);
saveAuthorArea(username, 'followers', { followers });
});
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(username, 'mentions', { mentions: concattedMentions });
});
outputFile('./dump/.timestamp', moment().unix(), err => {
log(`${err ? '✗' : '✓'} timestamp`);
});