forked from iamstarkov/jsunderhood
-
Notifications
You must be signed in to change notification settings - Fork 0
/
migration.js
53 lines (47 loc) · 1.6 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
const getInfo = require('get-twitter-info');
const tokens = require('twitter-tokens');
const { reverse, merge } = require('ramda');
const { remove, outputJSON } = require('fs-extra');
const rimraf = require('rimraf');
const authors = require('./authors');
const getAuthorArea = require('./helpers/get-author-area');
const saveAuthorArea = require('./helpers/save-author-area');
const log = require('./helpers/log');
const saveMedia = require('./helpers/save-media');
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');