Skip to content

Commit

Permalink
change in get all quotes: now only get top 10
Browse files Browse the repository at this point in the history
  • Loading branch information
stv-beep committed Aug 30, 2022
1 parent 44519a1 commit 0b96d56
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 24 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# F1 quotes api 0.3.1
# F1 quotes api 0.3.2

##### 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```
##### Very easy to use. GET ```/``` 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
#### GET list of F1 drivers or personalities **->** GET ```/```
#### GET all quotes of F1 drivers or personalities **->** GET ```/quotes```
#### GET 10 interesting quotes of F1 drivers or personalities **->** GET ```/quotes```
#### GET all saved quotes from an specific F1 driver **->** GET ```/quotes/:drivers_last_name```


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.3.1",
"version": "0.3.2",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
34 changes: 18 additions & 16 deletions src/routes/driversQuotes.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import express from 'express'
import axios from 'axios'
import cheerio, { load } from 'cheerio'
import drivers from '../services/drivers'
import { load } from 'cheerio'
import { drivers, top10 } from '../services/drivers'
import { driverName } from '../types'

const router = express.Router()
Expand All @@ -11,22 +11,24 @@ 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.'

const quoteClass: string = '.b-qt'
const quoteContent: string = '.quoteContent'


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

$('.b-qt', html).each(function () {
const quote = $(this).text().replace(/\n/g, '')
quotes.push({
quote,
author: driver.name
})
$(quoteContent).each(function () {
const quote = $(this).text().replace(/\n/g, '').replace(/\./g, '. Author: ').replace('Jr. Author: ', 'Jr.')
quotes.push({
quote
})
}).catch(err => console.log(err))
})
})

}).catch(err => console.log(err))
router.get('/', (req, res) => { //quotes
res.status(200) ? res.send(quotes) : res.json(quotesErrorMessage)
})
Expand All @@ -51,7 +53,7 @@ router.get('/:driverId', (req, res) => { //quotes/:driverId
const $ = load(html)
const specificQuotes = [] as any

$('.b-qt', html).each(function () {
$(quoteClass, html).each(function () {
const quote = $(this).text().replace(/\n/g, '')
specificQuotes.push({
quote,
Expand Down
4 changes: 2 additions & 2 deletions src/services/drivers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const drivers = [
export const drivers = [
{
name: 'Max Verstappen',
address: 'https://www.brainyquote.com/authors/max-verstappen-quotes',
Expand Down Expand Up @@ -211,4 +211,4 @@ const drivers = [
}
]

export default drivers;
export const top10 = 'https://www.brainyquote.com/lists/topics/top-10-f1-quotes'

0 comments on commit 0b96d56

Please sign in to comment.