Skip to content

Commit

Permalink
add time to getResults
Browse files Browse the repository at this point in the history
- issue #45
  • Loading branch information
dajk committed Feb 7, 2021
1 parent 29fc833 commit 72ab9d1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ http://localhost:3000/
"title": "ESL Pro League Season 5 Finals preview",
"description": "The next big offline event, the ESL Pro League Season 5 Finals, is kicking off tomorrow, May 30, with the round-robin group stage. We have put together a preview where we delve into each of the 12 teams taking part in the $750,000 tournament.",
"link": "https://www.hltv.org/news/20567/esl-pro-league-season-5-finals-preview",
"date": "Mon, 29 May 2017 23:27:00 GMT"
"time": "2017-05-29T23:27:00.000Z"
}
]
```
Expand All @@ -115,6 +115,7 @@ http://localhost:3000/results
{
"event": "ECS Season 4 Europe",
"maps": "trn",
"time": "2017-08-29T22:05:00.000Z",
"team1": {
"name": "fnatic",
"crest": "https://static.hltv.org/images/team/logo/4991",
Expand Down
16 changes: 12 additions & 4 deletions src/results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { CONFIG } from './config'
interface IResult {
event: string
maps: string | 'bo3'
time: string
team1: {
name: string
crest: string
Expand Down Expand Up @@ -34,27 +35,34 @@ export async function getResults(): Promise<IResult[]> {

const results: IResult[] = []

const resultElements = $('.results-all .result-con')
const resultElements = $('.allres .result-con')
$(resultElements).each((_i, element) => {
const el = $(element).find('tr')

const timestamp = Number(
el.parents('.result-con').attr('data-zonedgrouping-entry-unix')
)

const time = new Date(timestamp).toISOString()
const team1 = el.children('.team-cell').first()
const team2 = el.children('.team-cell').last()
const matchId = $(element).children('a').attr('href')!
const matchId = $(element).children('a').attr('href') as string
const maps = el.find('.map-text')
const result1 = el.find('.result-score').children('span').first()
const result2 = el.find('.result-score').children('span').last()

const objData: IResult = {
event: el.find('.event-name').text(),
maps: maps.text(),
time,
team1: {
name: team1.find('.team').text(),
crest: team1.find('img').attr('src')!,
crest: team1.find('img').attr('src') as string,
result: parseInt(result1.text(), 10),
},
team2: {
name: team2.find('.team').text(),
crest: team2.find('img').attr('src')!,
crest: team2.find('img').attr('src') as string,
result: parseInt(result2.text(), 10),
},
matchId,
Expand Down
2 changes: 1 addition & 1 deletion src/rss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default async function getRSS(type: 'news') {
title: result.rss.channel[0].item[i].title[0],
description: result.rss.channel[0].item[i].description[0],
link: result.rss.channel[0].item[i].link[0],
date: result.rss.channel[0].item[i].pubDate[0],
time: new Date(result.rss.channel[0].item[i].pubDate[0]).toISOString(),
}

rss.push(obj)
Expand Down
4 changes: 2 additions & 2 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ describe('hltv-api', () => {
expect(news.title.length).toBeGreaterThan(3)
expect(news.description).toBeDefined()
expect(news.link).toContain(CONFIG.BASE)
expect(news.date.length).toBeGreaterThan(10)
expect(news.date).toContain('GMT')
expect(news.time).toBeDefined()
})

it('should catch error in `getRSS`', async () => {
Expand All @@ -34,6 +33,7 @@ describe('hltv-api', () => {
const response = await HLTV.getResults()
expect(response.length).toBeDefined()
const result = response[0]
expect(result.time).toBeDefined()
expect(result.team1.name).toBeDefined()
expect(result.team1.crest).toContain(CONFIG.CDN)
expect(result.team2.name).toBeDefined()
Expand Down

1 comment on commit 72ab9d1

@vercel
Copy link

@vercel vercel bot commented on 72ab9d1 Feb 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.