forked from b00tc4mp/isdi-bootcamp-202405
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement first database population b00tc4mp#84
- Loading branch information
Showing
1,046 changed files
with
14,489 additions
and
341 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
6 changes: 0 additions & 6 deletions
6
staff/marti-herms/project/Pokemon game/core/package-lock.json
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import 'dotenv/config' | ||
import express from 'express' | ||
|
||
import { mongoose } from 'cor' | ||
import axios from 'axios' | ||
|
||
import { Pokemon } from '../core/data/models.js' | ||
|
||
import fs from 'fs/promises' | ||
|
||
const port = 8080 | ||
|
||
mongoose.connect('mongodb://127.0.0.1:27017/pokemon') | ||
.then(() => { | ||
return fs.readFile('./db/abomasnow.json') | ||
.then(response => response.json()) | ||
.then(abomasnow => { | ||
return Pokemon.create({ | ||
data: abomasnow.abilities[0] | ||
}) | ||
}) | ||
|
||
}) | ||
.then(() => mongoose.disconnect()) | ||
.catch(error => { | ||
console.error(error) | ||
|
||
mongoose.disconnect() | ||
}) | ||
|
||
// api.express() | ||
|
||
// api.get('/api/data', async (req, res) => { | ||
// try { | ||
// const apiUrl = 'https://pokeapi.co/api/v2/pokemon?limit=100000&offset=0' | ||
|
||
// const response = await axios.get(apiUrl) | ||
|
||
// const json = JSON.stringify(response.data) | ||
|
||
// res.json(response.data) | ||
// } catch (error) { | ||
// console.error('Error fetching data from API:', error) | ||
// res.status(500).json({ error: 'An error occurred while fetching data.' }) | ||
// } | ||
// }) | ||
|
||
// api.get('/api/pokemon', async (req, res) => { | ||
// const jsonRead = fs.readFileSync('./pokemonList.json', 'utf-8') | ||
|
||
// const { results } = JSON.parse(jsonRead) | ||
|
||
// const names = results.map(pokemon => pokemon.name) | ||
|
||
// const names1 = names.slice(0, 1025) | ||
|
||
// names1.forEach(async pokemonName => { | ||
// const apiUrl = `https://pokeapi.co/api/v2/pokemon/${pokemonName}` | ||
|
||
// const response = await axios.get(apiUrl) | ||
|
||
// const pokemon = response.data | ||
|
||
// delete pokemon.base_experience | ||
// delete pokemon.cries | ||
// delete pokemon.game_indices | ||
// delete pokemon.height | ||
// delete pokemon.held_items | ||
// delete pokemon.is_default | ||
// delete pokemon.location_area_encounters | ||
// delete pokemon.order | ||
// delete pokemon.past_abilities | ||
// delete pokemon.past_type | ||
// delete pokemon.species | ||
|
||
// const jsonWrite = JSON.stringify(response.data) | ||
|
||
// fs.appendFile(`../db/${pokemonName}.json`, jsonWrite, (error) => { | ||
// if (error) throw new Error; | ||
|
||
// console.log('It\'s saved!'); | ||
// }) | ||
// }) | ||
|
||
|
||
// res.send() | ||
// }) | ||
|
||
|
||
// api.listen(port, () => { | ||
// console.log(`Server is running on http://localhost:${port}`) | ||
// }) | ||
// }) | ||
// .catch (error => console.error(error)) |
Oops, something went wrong.