-
Notifications
You must be signed in to change notification settings - Fork 0
/
teste.js
100 lines (81 loc) · 2.83 KB
/
teste.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
const api = require('marvel-api');
const marvel = api.createClient({
publicKey: process.env.MARVEL_KEY,
privateKey: process.env.MARVEL_KEY_SECRET
});
// openai
const { Configuration, OpenAIApi } = require("openai");
const configuration = new Configuration({
apiKey: process.env.OPEN_AI_KEY,
});
const openai = new OpenAIApi(configuration);
let TOTAL_MARVEL_CHARACTERS_COUNT = 1563
const generateRandomMarvelCharacter = async (callback) => {
// total hardcoded 1562
// one more to include 1562
const random = Math.floor(Math.random() * (TOTAL_MARVEL_CHARACTERS_COUNT - 0)) + 0
marvel.characters.findAll(1, random)
.then((result) => {
// console.log(result)
let updatedTotal = +result.meta.total+1
console.log(`TOTAL_MARVEL_CHARACTERS_COUNT =[${TOTAL_MARVEL_CHARACTERS_COUNT}] updated=[${updatedTotal}]`)
TOTAL_MARVEL_CHARACTERS_COUNT = updatedTotal
callback(result.data[0])
})
.fail(console.error)
.done();
}
let TOTAL_MARVEL_STORY_COUNT = 123823
const generateRandomMarvelStory = async (callback) => {
// total hardcoded 1562
// one more to include 1562
const random = Math.floor(Math.random() * (TOTAL_MARVEL_STORY_COUNT - 0)) + 0
marvel.stories.findAll(1, random)
.then((result) => {
// console.log(result)
let updatedTotal = +result.meta.total+1
console.log(`TOTAL_MARVEL_STORY_COUNT =[${TOTAL_MARVEL_STORY_COUNT}] updated=[${updatedTotal}]`)
TOTAL_MARVEL_STORY_COUNT = updatedTotal
callback(result.data[0])
})
.fail(console.error)
.done();
}
let TOTAL_MARVEL_EVENT_COUNT = 75
const generateRandomMarvelEvents = async (callback) => {
const random = Math.floor(Math.random() * (TOTAL_MARVEL_EVENT_COUNT - 0)) + 0
marvel.events.findAll(1, random)
.then((result) => {
console.log(result)
let updatedTotal = +result.meta.total+1
console.log(`TOTAL_MARVEL_EVENT_COUNT =[${TOTAL_MARVEL_EVENT_COUNT}] updated=[${updatedTotal}]`)
TOTAL_MARVEL_EVENT_COUNT = updatedTotal
callback(result.data[0])
})
.fail(console.error)
.done();
}
const generateImage = async (text) => {
console.log(`generateImage prompt=[${text}]`)
const response = await openai.createImage({
prompt: text,
n: 1,
size: "1024x1024",
});
let image_url = response.data.data[0].url;
console.log(`url of generated image = [${image_url}]`)
return image_url;
}
const main = async () => {
// generateImage('a twitter background of a painting of an epic battle portrayed as supernova')
generateRandomMarvelEvents((event) => {
console.log(event)
})
}
main()
const printRandomInt = (number) => {
for (var i = 0; i < number; i++) {
console.log(Math.floor(Math.random() * (4 - 0)) + 0)
}
}
// printRandomInt(100)