Skip to content

Commit

Permalink
added drivers and f1 personalities
Browse files Browse the repository at this point in the history
  • Loading branch information
stv-beep committed Aug 30, 2022
1 parent 7ea62ea commit 44519a1
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 49 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# F1 quotes api
# F1 quotes api 0.3.1

##### An API showing several quotes said by famous Formula 1 drivers and Formula 1 personalities.

##### Very easy to use. ```/``` shows all the F1 drivers or personalities who have quotes saved in this API, and their code to access them. For example: Max Verstappen's quotes: ```/quotes/verstappen```

### Endpoints
## Endpoints
#### GET list of F1 drivers or personalities **->** GET ```/```
#### GET all quotes of F1 drivers or personalities **->** GET ```/quotes```
#### GET all saved quotes from an specific F1 driver **->** GET ```/quotes/:drivers_last_name```




###### Dev:
## Developer:

```npm install```

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "f1-quotes-api",
"version": "0.2.0",
"version": "0.3.1",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
6 changes: 2 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ const app = express()
app.use(express.json())

app.get('/', (_req, res) => {
res.json(driverName)
res.status(200).json(driverName)
})



app.use('/quotes', quotesRouter)

app.use('/quotes/:driverId', quotesRouter)

app.listen(PORT, () => console.log(`running on http://localhost:${PORT}` + ' on ' + new Date().toLocaleDateString()))
app.listen(PORT, () => console.log(`running on http://localhost:${PORT}` + ' on ' + new Date().toLocaleTimeString() , new Date().toLocaleDateString()))
11 changes: 4 additions & 7 deletions src/routes/driversQuotes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import express from 'express'
import axios from 'axios'
import cheerio from 'cheerio'
import cheerio, { load } from 'cheerio'
import drivers from '../services/drivers'
import { driverName } from '../types'

Expand All @@ -11,12 +11,12 @@ const quotes = [] as any
const quotesErrorMessage: string = 'Something went wrong or your input is not correct. Try "/quotes".'
const driverQuotesErrorMsg: string = ' is not in the database or the input is incorrect.'


/* all quotes */
drivers.forEach(driver => {
axios.get(driver.address)
.then(response => {
const html = response.data
const $ = cheerio.load(html)
const $ = load(html)

$('.b-qt', html).each(function () {
const quote = $(this).text().replace(/\n/g, '')
Expand All @@ -27,9 +27,6 @@ drivers.forEach(driver => {
})
}).catch(err => console.log(err))
})


/* all quotes */
router.get('/', (req, res) => { //quotes
res.status(200) ? res.send(quotes) : res.json(quotesErrorMessage)
})
Expand All @@ -51,7 +48,7 @@ router.get('/:driverId', (req, res) => { //quotes/:driverId
axios.get(driverURL)
.then(response => {
const html = response.data
const $ = cheerio.load(html)
const $ = load(html)
const specificQuotes = [] as any

$('.b-qt', html).each(function () {
Expand Down
9 changes: 4 additions & 5 deletions src/services/drivers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const drivers = [
const drivers = [
{
name: 'Max Verstappen',
address: 'https://www.brainyquote.com/authors/max-verstappen-quotes',
Expand Down Expand Up @@ -129,7 +129,6 @@ const drivers = [
address: 'https://www.brainyquote.com/authors/ayrton-senna-quotes',
driverId: 'senna'
},
/*
{
name: 'Marcus Ericsson',
address: 'https://www.brainyquote.com/authors/marcus-ericsson-quotes',
Expand Down Expand Up @@ -179,8 +178,8 @@ const drivers = [
name: 'Niki Lauda',
address: 'https://www.brainyquote.com/authors/niki-lauda-quotes',
driverId: 'lauda'
}, */
/* {
},
{
name: 'Toto Wolff',
address: 'https://www.brainyquote.com/authors/toto-wolff-quotes',
driverId: 'wolff'
Expand Down Expand Up @@ -209,7 +208,7 @@ const drivers = [
name: 'Susie Wolff',
address: 'https://www.brainyquote.com/authors/susie-wolff-quotes_2',
driverId: 'wolff'
} */
}
]

export default drivers;
50 changes: 24 additions & 26 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
export enum driverName {
Max_Verstappen = 'verstappen',
Lewis_Hamilton = 'hamilton',
Fernando_Alonso = 'alonso',
Carlos_Sainz_Jr = 'sainz',
Daniel_Ricciardo = 'ricciardo',
Charles_Leclerc = 'leclerc',
Sebastian_Vettel = 'vettel',
Mick_Schumacher = 'mick',
Sergio_Perez = 'perez',
Kevin_Magnussen = 'magnussen',
Lance_Stroll = 'stroll',
Rubens_Barrichello = 'barrichello',
Mattia_Binotto = 'binotto',
Valtteri_Bottas = 'bottas',
Lando_Norris = 'norris',


Jenson_Button = 'button',
Marcus_Ericsson = 'ericsson',
Lewis_Hamilton = 'hamilton',
Christian_Horner = 'horner',
Nico_Hülkenberg = 'hulkenberg',
Heikki_Kovalainen = 'kovalainen',
Robert_Kubica = 'kubica',
Kimi_Räikkönen = 'raikkonen',
Michael_Schumacher = 'schumacher',
Ayrton_Senna = 'senna',
/* Marcus_Ericsson = 'ericsson',
Rubens_Barrichello = 'barrichello',
Niki_Lauda = 'lauda',
Charles_Leclerc = 'leclerc',
Kevin_Magnussen = 'magnussen',
Pastor_Maldonado = 'maldonado',
Felipe_Massa = 'massa',
Jenson_Button = 'button',
Lando_Norris = 'norris',
Sergio_Perez = 'perez',
Alain_Prost = 'prost',
Heikki_Kovalainen = 'kovalainen',
Kimi_Räikkönen = 'raikkonen',
Daniel_Ricciardo = 'ricciardo',
Nico_Rosberg = 'rosberg',
Pastor_Maldonado = 'maldonado',
Niki_Lauda = 'lauda',
Carlos_Sainz_Jr = 'sainz',
Michael_Schumacher = 'schumacher',
Mick_Schumacher = 'mick',
Ayrton_Senna = 'senna',
Lance_Stroll = 'stroll',
Max_Verstappen = 'verstappen',
Sebastian_Vettel = 'vettel',
Susie_Wolff = 'susie',
Toto_Wolff = 'wolff',
Mattia_Binotto = 'binotto',
Christian_Horner = 'horner',
Susie_Wolff = 'susie' */
}
}

0 comments on commit 44519a1

Please sign in to comment.