-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathavogado.js
executable file
·137 lines (126 loc) · 3.45 KB
/
avogado.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import { Command } from 'commander';
import scrapperWeb from './scrappers/web.js';
import scrapperIG from './scrappers/instagram.js';
import scrapperTwitter from './scrappers/twitter.js';
import { delay } from './scripts/utility.js';
import pull from './scripts/pullers.js';
import { push } from './scripts/pushers.js';
import flush from './scripts/flushers.js';
import download from './scripts/downloaders.js';
import check from './scripts/checkers.js';
const cmd = new Command();
cmd
.name('avogado')
.description('Node.js Artisan-like CLI')
.version('1.0.0')
.action(async () => {
const types = ['web', 'twitter', 'instagram'];
await scrapperWeb();
await delay(5);
console.info('-------------------');
await scrapperTwitter();
await delay(5);
console.info('-------------------');
await scrapperIG();
console.info();
types.forEach(async (type) => {
await delay(5);
await push(type);
});
types.forEach(async (type) => {
await delay(5);
await download(type);
});
});
cmd
.command('scrap')
.description('Script to call scrapper')
.option('-t, --type <type>', 'if null it scrap all type, type: web, twitter & instagram', null)
.option(
'-m, --mode <mode>',
'default is "new", only have 2 mode scrap: all or new, available in instagram and twitter type',
null
)
.action(async (options) => {
const scrapNew = options.mode !== null ? options.mode === 'new' : true;
if (options.type === 'web') {
await scrapperWeb();
} else if (options.type === 'twitter') {
await scrapperTwitter(scrapNew);
} else if (options.type === 'instagram') {
await scrapperIG(scrapNew);
} else {
await scrapperWeb();
await delay(3);
console.info('-------------------');
await scrapperTwitter(scrapNew);
await delay(3);
console.info('-------------------');
await scrapperIG(scrapNew);
}
});
cmd
.command('pull')
.description('Script to pull data from pocketbase')
.option('-t, --type <type>', 'if null it scrap all type, type: web, twitter & instagram', null)
.action(async (options) => {
if (options.type === null) {
await pull('web');
await delay(1.5);
console.info();
await pull('twitter');
await delay(1.5);
console.info();
await pull('instagram');
} else {
await pull(options.type);
}
});
cmd
.command('push')
.description('Script to push data to pocketbase')
.option(
'-t, --type <type>',
'if null it will push all type, type: web, twitter & instagram',
null
)
.action(async (options) => {
if (options.type === null) {
await push('web');
await delay(1.5);
console.info();
await push('twitter');
await delay(1.5);
console.info();
await push('instagram');
} else {
await push(options.type);
}
});
cmd
.command('flush')
.description('Script to flush data in Pocketbase')
.option('-t, --type <type>', 'type: web, twitter & instagram', null)
.action(async (options) => await flush(options.type));
cmd
.command('download')
.description('Script to download data in Pocketbase')
.option('-t, --type <type>', 'type: web, twitter & instagram', null)
.action(async (options) => {
if (options.type === null) {
await download('web');
await delay(1.5);
console.info();
await download('twitter');
await delay(1.5);
console.info();
await download('instagram');
} else {
await download(options.type);
}
});
cmd
.command('check')
.description('Script to check scrapper data from Pocketbase')
.action(async () => await check());
cmd.parse(process.argv);