forked from jeffreyclu/friend.ly
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddFake.html
More file actions
46 lines (44 loc) · 1.53 KB
/
addFake.html
File metadata and controls
46 lines (44 loc) · 1.53 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
<button onClick="generateFake()">add fake</button>
<script>
const generateFake = () => {
for (let i=0; i<100; i++) {
fetch("https://randomuser.me/api/")
.then(resp => resp.json())
.then(data => {
const { name, location, dob, login, picture } = data.results[0]
const { first } = name;
const { city } = location;
const { age } = dob;
const { username, password } = login;
const { large } = picture;
const pronouns = ["He", "She", "They", "Other"];
const primary_interests = ["Live Music", "Live Sports", "Art Shows", "Dancing", "Watching Movies", "Eating Out"];
const pronoun = pronouns[getRandom(0, 4)];
const primary_interest = primary_interests[getRandom(0, 6)];
const user = {
name: first,
age: age,
gender: pronoun,
city: "London",
primary_interest: primary_interest,
username: username,
password: password,
avatar: large,
}
fetch('/api/adduser', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(user),
})
})
}
const getRandom = (min, max) => {
min = Math.ceil(min);
max = Math.floor(max);
const output = Math.floor(Math.random() * (max - min)) + min
return output; //The maximum is exclusive and the minimum is inclusive
}
}
</script>