This repository was archived by the owner on Aug 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_api_users.js
More file actions
76 lines (72 loc) · 2.09 KB
/
create_api_users.js
File metadata and controls
76 lines (72 loc) · 2.09 KB
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
const username_uid = require('./username_uid.json')
const axios = require('axios')
const fs = require('fs')
async function asyncForEach(array, callback) {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array);
}
}
promises=[]
usernames = Object.keys(username_uid)
/* adds user */
q=0
api_keys=[]
asyncForEach(usernames, async (username,i) => {
promises.push(axios({
method: 'post',
url: 'https://1btcarg.com/admin/api/keys',
data: {
"key": {
username,
"description":"dev"
}
},
headers: {
'Api-Key': '2f5ec9ce351ac1a17afea0329c7d4f7f7e2384e2997b4daed4f38d84c40ad1e4',
'Api-Username': 'mrb'
}
}));
++q;
if( q > 200 || i == usernames.length-1 ) {
console.log("waiting results")
let results = await Promise.allSettled(promises);
results.forEach( (result,i) => {
if(result.status == 'rejected') {
console.log('error',result.reason);
}else{
api_keys.push(result.value.data)
}
});
await new Promise(r => setTimeout(r, 2000));
promises=[];
q=0;
fs.writeFileSync(`./api_keys.json`,JSON.stringify(api_keys));
}
})
/**/
//checks if is in CSV file and if not inserts
/*asyncForEach(Object.keys(authors), async permalink => {
if( !csv.includes( permalink ) )
if(promises.length<=200)
promises.push(axios({
method: 'post',
url: 'http://188.166.30.233:4567/api/v2/users/',
data: {
fullname: authors[permalink],
username: permalink
},
headers: {
'Authorization': 'Bearer 032f2ff4-f779-45b6-830c-32268781630d',
}
}))
else {
try{
let results = await Promise.all(promises)
await new Promise(r => setTimeout(r, 2000));
}catch(e){
console.log("error",permalink,e)
process.exit()
}
promises=[]
}
});*/