Skip to content

Commit 0b96d56

Browse files
committed
change in get all quotes: now only get top 10
1 parent 44519a1 commit 0b96d56

File tree

5 files changed

+26
-24
lines changed

5 files changed

+26
-24
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
# F1 quotes api 0.3.1
1+
# F1 quotes api 0.3.2
22

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

5-
##### 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```
5+
##### 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```
66

77
## Endpoints
88
#### GET list of F1 drivers or personalities **->** GET ```/```
9-
#### GET all quotes of F1 drivers or personalities **->** GET ```/quotes```
9+
#### GET 10 interesting quotes of F1 drivers or personalities **->** GET ```/quotes```
1010
#### GET all saved quotes from an specific F1 driver **->** GET ```/quotes/:drivers_last_name```
1111

1212

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "f1-quotes-api",
3-
"version": "0.3.1",
3+
"version": "0.3.2",
44
"description": "",
55
"main": "index.js",
66
"scripts": {

src/routes/driversQuotes.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import express from 'express'
22
import axios from 'axios'
3-
import cheerio, { load } from 'cheerio'
4-
import drivers from '../services/drivers'
3+
import { load } from 'cheerio'
4+
import { drivers, top10 } from '../services/drivers'
55
import { driverName } from '../types'
66

77
const router = express.Router()
@@ -11,22 +11,24 @@ const quotes = [] as any
1111
const quotesErrorMessage: string = 'Something went wrong or your input is not correct. Try "/quotes".'
1212
const driverQuotesErrorMsg: string = ' is not in the database or the input is incorrect.'
1313

14+
const quoteClass: string = '.b-qt'
15+
const quoteContent: string = '.quoteContent'
16+
17+
1418
/* all quotes */
15-
drivers.forEach(driver => {
16-
axios.get(driver.address)
17-
.then(response => {
18-
const html = response.data
19-
const $ = load(html)
19+
axios.get(top10)
20+
.then(response => {
21+
const html = response.data
22+
const $ = load(html)
2023

21-
$('.b-qt', html).each(function () {
22-
const quote = $(this).text().replace(/\n/g, '')
23-
quotes.push({
24-
quote,
25-
author: driver.name
26-
})
24+
$(quoteContent).each(function () {
25+
const quote = $(this).text().replace(/\n/g, '').replace(/\./g, '. Author: ').replace('Jr. Author: ', 'Jr.')
26+
quotes.push({
27+
quote
2728
})
28-
}).catch(err => console.log(err))
29-
})
29+
})
30+
31+
}).catch(err => console.log(err))
3032
router.get('/', (req, res) => { //quotes
3133
res.status(200) ? res.send(quotes) : res.json(quotesErrorMessage)
3234
})
@@ -51,7 +53,7 @@ router.get('/:driverId', (req, res) => { //quotes/:driverId
5153
const $ = load(html)
5254
const specificQuotes = [] as any
5355

54-
$('.b-qt', html).each(function () {
56+
$(quoteClass, html).each(function () {
5557
const quote = $(this).text().replace(/\n/g, '')
5658
specificQuotes.push({
5759
quote,

src/services/drivers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const drivers = [
1+
export const drivers = [
22
{
33
name: 'Max Verstappen',
44
address: 'https://www.brainyquote.com/authors/max-verstappen-quotes',
@@ -211,4 +211,4 @@ const drivers = [
211211
}
212212
]
213213

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

0 commit comments

Comments
 (0)