Skip to content

Commit f42cd47

Browse files
committed
Merge branch 'dev'
2 parents 4253ae3 + 4041226 commit f42cd47

File tree

5 files changed

+54
-146
lines changed

5 files changed

+54
-146
lines changed

Procfile

Lines changed: 0 additions & 1 deletion
This file was deleted.

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Built by [Andre Saddler](https://github.com/axsddlr/)
99
All endpoints are relative to [https://vlrggapi.vercel.app](https://vlrggapi.vercel.app).
1010

1111
### `/news`
12+
1213
- Method: `GET`
1314
- Description: Fetches the latest news articles related to Valorant Esports.
1415
- Response Example:
@@ -30,6 +31,7 @@ All endpoints are relative to [https://vlrggapi.vercel.app](https://vlrggapi.ver
3031
```
3132

3233
### `/match/results`
34+
3335
- Method: `GET`
3436
- Description: Fetches recent match results.
3537
- Response Example:
@@ -57,6 +59,7 @@ All endpoints are relative to [https://vlrggapi.vercel.app](https://vlrggapi.ver
5759
```
5860

5961
### `/rankings/{region}`
62+
6063
- Method: `GET`
6164
- Description: Fetches rankings for a specific region.
6265
- Response Example:
@@ -82,6 +85,7 @@ All endpoints are relative to [https://vlrggapi.vercel.app](https://vlrggapi.ver
8285
```
8386

8487
### `/stats/{region}/{timespan}`
88+
8589
- Method: `GET`
8690
- Description: Fetches player statistics for a specific region and timespan.
8791
- Response Example:
@@ -109,6 +113,7 @@ All endpoints are relative to [https://vlrggapi.vercel.app](https://vlrggapi.ver
109113
```
110114

111115
### `/match/upcoming`
116+
112117
- Method: `GET`
113118
- Description: Fetches upcoming matches.
114119
- Response Example:
@@ -122,20 +127,23 @@ All endpoints are relative to [https://vlrggapi.vercel.app](https://vlrggapi.ver
122127
"team2": "Team 2 Name",
123128
"flag1": "Team 1 Country Flag",
124129
"flag2": "Team 2 Country Flag",
125-
"score1": "-",
126-
"score2": "-",
127130
"time_until_match": "Time Until Match",
128131
"round_info": "Round Information",
129132
"tournament_name": "Tournament Name",
133+
"unix_timestamp": "Match Start Time UNIX Timestamp",
130134
"match_page": "/path/to/match",
131135
"tournament_icon": "URL to Tournament Icon"
132136
}
133137
]
134138
}
135139
}
136140
```
141+
```
142+
143+
```
137144

138145
### `/match/live_score`
146+
139147
- Method: `GET`
140148
- Description: Fetches live scores for ongoing matches.
141149
- Response Example:

api/scrape.py

Lines changed: 40 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -266,137 +266,56 @@ def vlr_stats(region: str, timespan: int):
266266
return data
267267

268268
@staticmethod
269-
def vlr_upcoming():
270-
url = "https://www.vlr.gg/matches"
271-
resp = requests.get(url, headers=headers)
272-
html = HTMLParser(resp.text)
273-
status = resp.status_code
274-
275-
result = []
276-
for item in html.css("a.wf-module-item"):
277-
url_path = item.attributes["href"]
278-
eta = item.css_first(".match-item-eta").text().strip()
279-
eta = eta.replace("\t", " ").replace("\n", " ").split()
280-
281-
try:
282-
if eta[0] == "ago" or "LIVE":
283-
eta = "LIVE"
284-
else:
285-
eta = eta[1] + " " + eta[2] + " from now"
286-
except IndexError:
287-
eta = "Unknown"
288-
289-
rounds = item.css_first(".match-item-event-series").text().strip()
290-
291-
tourney = item.css_first(".match-item-event").text().strip()
292-
tourney = tourney.replace("\t", " ")
293-
tourney = tourney.strip().split("\n")[1]
294-
tourney = tourney.strip()
295-
296-
tourney_icon_url = item.css_first("img").attributes["src"]
297-
tourney_icon_url = f"https:{tourney_icon_url}"
298-
299-
flag_list = [
300-
flag_parent.attributes["class"].replace(" mod-", "_")
301-
for flag_parent in item.css(".flag")
302-
]
303-
flag1 = flag_list[0]
304-
flag2 = flag_list[1]
305-
306-
try:
307-
team_array = (
308-
item.css_first("div.match-item-vs")
309-
.css_first("div:nth-child(2)")
310-
.text()
311-
)
312-
except Exception: # Replace bare except with except Exception
313-
team_array = "TBD"
314-
team_array = team_array.replace("\t", " ").replace("\n", " ")
315-
team_array = team_array.strip().split(" ")
316-
317-
team1 = "TBD"
318-
team2 = "TBD"
319-
if team_array is not None and len(team_array) > 1:
320-
team1 = team_array[0]
321-
team2 = team_array[4].strip()
322-
323-
score1 = "-"
324-
score2 = "-"
325-
if team_array is not None and len(team_array) > 1:
326-
score1 = team_array[1].replace(" ", "").strip()
327-
score2 = team_array[-1].replace(" ", "").strip()
328-
329-
result.append(
330-
{
331-
"team1": team1,
332-
"team2": team2,
333-
"flag1": flag1,
334-
"flag2": flag2,
335-
"score1": score1,
336-
"score2": score2,
337-
"time_until_match": eta,
338-
"round_info": rounds,
339-
"tournament_name": tourney,
340-
"match_page": url_path,
341-
"tournament_icon": tourney_icon_url,
342-
}
343-
)
344-
segments = {"status": status, "segments": result}
345-
346-
data = {"data": segments}
347-
348-
if status != 200:
349-
raise Exception("API response: {}".format(status))
350-
return data
351-
352-
@staticmethod
353-
def vlr_upcoming_index():
269+
def vlr_upcoming_matches():
354270
url = "https://www.vlr.gg"
355271
resp = requests.get(url, headers=headers)
356272
html = HTMLParser(resp.text)
357273
status = resp.status_code
358274

359275
result = []
360276
for item in html.css(".js-home-matches-upcoming a.wf-module-item"):
361-
teams = []
362-
flags = []
363-
scores = []
364-
for team in item.css(".h-match-team"):
365-
teams.append(team.css_first(".h-match-team-name").text().strip())
366-
flags.append(
367-
team.css_first(".flag")
368-
.attributes["class"]
369-
.replace(" mod-", "")
370-
.replace("16", "_")
371-
)
372-
scores.append(team.css_first(".h-match-team-score").text().strip())
277+
# Check if the match is upcoming
278+
is_upcoming = item.css_first(".h-match-eta.mod-upcoming")
279+
if is_upcoming:
280+
teams = []
281+
flags = []
282+
scores = []
283+
for team in item.css(".h-match-team"):
284+
teams.append(team.css_first(".h-match-team-name").text().strip())
285+
flags.append(
286+
team.css_first(".flag")
287+
.attributes["class"]
288+
.replace(" mod-", "")
289+
.replace("16", "_")
290+
)
291+
scores.append(team.css_first(".h-match-team-score").text().strip())
373292

374-
eta = item.css_first(".h-match-eta").text().strip()
375-
if eta != "LIVE":
376-
eta = eta + " from now"
293+
eta = item.css_first(".h-match-eta").text().strip()
294+
if eta != "LIVE":
295+
eta = eta + " from now"
377296

378-
rounds = item.css_first(".h-match-preview-event").text().strip()
379-
tournament = item.css_first(".h-match-preview-series").text().strip()
380-
timestamp = int(
381-
item.css_first(".moment-tz-convert").attributes["data-utc-ts"]
382-
)
383-
url_path = url + "/" + item.attributes["href"]
297+
rounds = item.css_first(".h-match-preview-event").text().strip()
298+
tournament = item.css_first(".h-match-preview-series").text().strip()
299+
timestamp = datetime.fromtimestamp(
300+
int(item.css_first(".moment-tz-convert").attributes["data-utc-ts"]),
301+
tz=timezone.utc,
302+
).strftime("%Y-%m-%d %H:%M:%S")
303+
url_path = "https://www.vlr.gg" + item.attributes["href"]
304+
305+
result.append(
306+
{
307+
"team1": teams[0],
308+
"team2": teams[1],
309+
"flag1": flags[0],
310+
"flag2": flags[1],
311+
"time_until_match": eta,
312+
"round_info": rounds,
313+
"tournament_name": tournament,
314+
"unix_timestamp": timestamp,
315+
"match_page": url_path,
316+
}
317+
)
384318

385-
result.append(
386-
{
387-
"team1": teams[0],
388-
"team2": teams[1],
389-
"flag1": flags[0],
390-
"flag2": flags[1],
391-
"score1": scores[0],
392-
"score2": scores[1],
393-
"time_until_match": eta,
394-
"round_info": rounds,
395-
"tournament_name": tournament,
396-
"unix_timestamp": timestamp,
397-
"match_page": url_path,
398-
}
399-
)
400319
segments = {"status": status, "segments": result}
401320

402321
data = {"data": segments}
@@ -488,13 +407,6 @@ def vlr_live_score():
488407
raise Exception("API response: {}".format(status))
489408
return data
490409

491-
segments = {"status": status, "segments": result}
492-
data = {"data": segments}
493-
494-
if status != 200:
495-
raise Exception("API response: {}".format(status))
496-
return data
497-
498410

499411
if __name__ == "__main__":
500412
print(Vlr.vlr_live_score(self=Vlr()))

app.json

Lines changed: 0 additions & 7 deletions
This file was deleted.

main.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
app = FastAPI(
1313
title="vlrggapi",
1414
description="An Unofficial REST API for [vlr.gg](https://www.vlr.gg/), a site for Valorant Esports match and news "
15-
"coverage. Made by [Rehkloos](https://github.com/Rehkloos)",
16-
version="1.0.5",
15+
"coverage. Made by [axsddlr](https://github.com/axsddlr)",
1716
docs_url="/",
1817
redoc_url=None,
1918
)
@@ -83,19 +82,16 @@ async def VLR_ranks(region, request: Request):
8382
@app.get("/match/upcoming")
8483
@limiter.limit("250/minute")
8584
async def VLR_upcoming(request: Request):
86-
return vlr.vlr_upcoming()
85+
return vlr.vlr_upcoming_matches()
8786

88-
@app.get("/match/upcoming_index")
89-
@limiter.limit("250/minute")
90-
async def VLR_upcoming_index(request: Request):
91-
return vlr.vlr_upcoming_index()
9287

9388
@app.get("/match/live_score")
9489
@limiter.limit("250/minute")
9590
async def VLR_live_score(request: Request):
9691
return vlr.vlr_live_score()
9792

98-
@app.get('/health')
93+
94+
@app.get("/health")
9995
def health():
10096
return "Healthy: OK"
10197

0 commit comments

Comments
 (0)