@@ -266,137 +266,56 @@ def vlr_stats(region: str, timespan: int):
266
266
return data
267
267
268
268
@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 ():
354
270
url = "https://www.vlr.gg"
355
271
resp = requests .get (url , headers = headers )
356
272
html = HTMLParser (resp .text )
357
273
status = resp .status_code
358
274
359
275
result = []
360
276
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 ())
373
292
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"
377
296
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
+ )
384
318
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
- )
400
319
segments = {"status" : status , "segments" : result }
401
320
402
321
data = {"data" : segments }
@@ -488,13 +407,6 @@ def vlr_live_score():
488
407
raise Exception ("API response: {}" .format (status ))
489
408
return data
490
409
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
-
498
410
499
411
if __name__ == "__main__" :
500
412
print (Vlr .vlr_live_score (self = Vlr ()))
0 commit comments