-
Notifications
You must be signed in to change notification settings - Fork 0
/
generateJson.js
99 lines (91 loc) · 3.22 KB
/
generateJson.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
require('dotenv').config()
const fs = require('fs')
const axios = require('axios')
const apiKey = process.env.GIPHY_API_KEY
// prepare 150 queries
const queries = [
'hooray', 'seriously?', 'ironman', 'marvel',
'racoon', 'thor', 'god', 'omg', 'thunder', 'hmm',
'huh?', 'love', 'captain', 'america', 'pure',
'purity', 'tranquil', 'awesome', 'movie', 'chips',
'war', 'explosion', 'bomb', 'tank', 'sun',
'glasses', 'coke', 'hot', 'summer', 'winter',
'snow', 'weather', 'dust', 'corn', 'interstellar',
'star', 'planet', 'earth', 'humane', 'kind',
'iphone', 'apple', 'steve jobs', 'smart', 'maple',
'books', 'library', 'study', 'technology', 'canada',
'free', 'news', 'cheat', 'tax', 'makeuup', 'dating',
'propose', 'props', 'tattoo', 'team', 'holic', 'fantasy',
'fan', 'feelings', 'nothing', 'something', 'coding',
'geek', 'cat', 'dog', 'doggo', 'catdog', 'adventure',
'groove', 'grooving', 'mobile', 'web', 'hero',
'listen music', 'play music', 'music video', 'hang out',
'infinite', 'infinite loop', 'find out', 'understand',
'why not', 'wow', 'cheer up', 'dont worry', 'be happy',
'how to', 'sure', 'why not', 'hint', 'rich', 'fancy',
'reaction', 'reality', 'weekend', 'cloudy', 'sunny',
'snow', 'winter', 'summer', 'spring', 'autumn', 'windy',
'hello', 'oh my gosh' , 'wait a second', 'please', 'lego',
'please dont', 'come on', 'hey', 'give up', 'guitar', 'ronaldo',
'say hi', 'piano', 'cake', 'simpsons', 'finn the human',
'finn and jake', 'cafe', 'coffee', 'journey', 'kitty',
'super mario', 'smurf', 'pilot', 'candy', 'chocolate',
'book', 'story', 'disney', 'pixar', 'food', 'spongebob',
'rabbit', 'tiger', 'koala', 'chameleon', 'avengers',
'frodo baggins', 'gandalf', 'snack', 'snoopy', 'cookie',
'funny cats', 'funny dog', 'gorilla', 'notification',
'dinosaur', 'kims convenience', 'conan obrien', 'starwars',
];
const allRequests = queries
.map((query) => {
return axios({
method: 'get',
url: 'http://api.giphy.com/v1/gifs/search',
params: {
api_key: apiKey,
q: query,
limit: 20,
},
headers: {
'Content-Type': 'application/json',
},
})
.then((response) => response.data.data)
.then((data) => {
return data.map((gif) => {
const gifPath = gif.images.original_still.url.split('/media/')[1]
const gifHashId = gifPath.split('/')[0]
const resolvedUrl = `https://i.giphy.com/${gifHashId}.gif`
// extract things that seem useful
return {
kind: query,
type: gif.type,
id: gif.id,
slug: gif.slug,
url: resolvedUrl,
createdAt: gif.import_datetime,
}
})
})
})
Promise
.all(allRequests)
.then((allData) => {
const result = allData.reduce(
(flattened, array) => flattened.concat(...array),
[]
)
fs.writeFile(
'data.json',
JSON.stringify(result),
'utf8',
() => {}
)
})
.catch((error) => {
console.log('**************************************')
console.log('******** Axios error occured. ********')
console.log('**************************************')
console.error(error.response)
console.log('**************************************')
})