-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathparse.js
48 lines (43 loc) · 1.35 KB
/
parse.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
/* eslint-disable @typescript-eslint/no-var-requires */
const { PrismaClient } = require('@prisma/client');
const axios = require('axios');
const prisma = new PrismaClient();
const test = async () => {
const {data} = await axios.get('https://www.thecocktaildb.com/api/json/v1/1/random.php');
const cocktailData = data.drinks[0];
//console.log(data.drinks[0]);
const ingredients = [];
for (let i = 1; i < 15; i++) {
if (cocktailData['strIngredient' + i]) {
const measure = cocktailData['strMeasure' + i];
ingredients.push({
name: cocktailData['strIngredient' + i],
amount: measure ? measure.trim() : '',
});
}
}
const name = cocktailData.strDrink;
const cache = await prisma.cocktail.findFirst({
where: {
name,
}
});
if (!cache) {
console.log(`${name} does not exist!`);
await prisma.cocktail.create({
data: {
name: cocktailData.strDrink,
description: cocktailData.strInstructions,
image: cocktailData.strDrinkThumb,
ingredients: {
create: ingredients
}
}
});
} else {
console.log(`${name} does exist!`);
}
};
for (let i = 0; i < 1000; i++) {
test();
}