-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
54 lines (46 loc) · 1.24 KB
/
index.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
require('dotenv').config();
const axios = require('axios').default;
const fs = require('fs');
const BASE_URL = process.env.BASE_URL;
let currentStr = '';
let count = 0;
const fetchData = async (name = '') => {
try {
return await axios.post(`${BASE_URL}${name}`)
} catch (error) {
console.error(error)
}
}
const writeToFile = () => {
console.log(currentStr);
console.log('total files scanned', count++)
fs.appendFileSync('scrapped.txt', currentStr, (err) => {
if (err)
console.log(err);
})
}
const saveCateogoryData = async (name) => {
const categoryData = await fetchData(`${name}/`);
if (categoryData.data.files) {
categoryData.data.files.map(item => {
currentStr = `${name}/${item.name}$`;
writeToFile();
});
}
}
const startScrapping = async () => {
const categories = await fetchData();
if (categories.data) {
const categoryList = categories.data.files;
categoryList.forEach(item => {
if (item.name !== 'snapchats' || item.name !== 'Celebrity')
saveCateogoryData(item.name);
})
};
}
Promise.all([
startScrapping()
])
.then(value = () => {
// writeToFile()
});