-
Notifications
You must be signed in to change notification settings - Fork 6
/
migration.js
53 lines (47 loc) · 1.55 KB
/
migration.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
import authors from './authors';
import { reverse, merge } from 'ramda';
import tokens from 'twitter-tokens';
import getInfo from 'get-twitter-info';
import getAuthorArea from './helpers/get-author-area';
import saveAuthorArea from './helpers/save-author-area';
import log from './helpers/log';
import { remove, outputJSON } from 'fs-extra';
import saveMedia from './helpers/save-media';
import rimraf from 'rimraf';
const spaces = 2;
// INFO
function initInfo({ username }) {
getInfo(tokens, username, (err, info) => {
if (err) throw err;
const existing = getAuthorArea(username, 'info');
const result = merge(info, existing);
saveAuthorArea(username, 'info', result);
});
}
authors.map(initInfo);
// MEDIA
function initMedia({ username }) {
saveMedia(tokens, username, username, (err, media) => {
if (err) throw err;
saveAuthorArea(username, 'media', media);
});
}
authors.map(initMedia);
// MENTIONS
function createEmptyMentions({ username }) {
outputJSON(`./dump/${username}-mentions.json`, { mentions: [] }, { spaces }, saveErr => {
log(`${saveErr ? '✗' : '✓'} ${username}’s empty mentions`);
});
}
authors.map(createEmptyMentions);
// TWEETS
function reverseAndRenameTweets({ username }) {
const { tweets: oldTweets } = getAuthorArea(username);
const tweets = reverse(oldTweets);
saveAuthorArea(username, 'tweets', { tweets });
remove(`./dump/${username}.json`, rmErr => {
log(`${rmErr ? '✗' : '✓'} ${username}’s old tweets removed`);
});
}
authors.map(reverseAndRenameTweets);
rimraf.sync('./migration.js')