hltv-async-api 0.6.2__tar.gz → 0.6.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: hltv_async_api
3
- Version: 0.6.2
3
+ Version: 0.6.5
4
4
  Summary: Hltv-aio An unofficial asynchronous HLTV API Wrapper for Python
5
5
  Author: Akim Slys
6
6
  Author-email: akimslys2003@gmail.com
@@ -24,13 +24,13 @@ Description-Content-Type: text/markdown
24
24
  # hltv-async-api an unofficial asynchronous HLTV API Wrapper for Python
25
25
 
26
26
 
27
- **This page not completed, not all methods and configs are written**
27
+ **This page is not completed, not all methods and configs are written**
28
28
 
29
29
 
30
30
  # Features
31
31
 
32
32
 
33
- * **Simple Usage** (its realy simple)
33
+ * **Simple Usage** (its really simple)
34
34
 
35
35
 
36
36
  * **New and modern fully async library**
@@ -59,21 +59,23 @@ pip install hltv-async-api
59
59
  # Simple Usage
60
60
 
61
61
  ```
62
+
62
63
  from hltv_async_api import Hltv
63
64
 
64
- hltv = Hltv()
65
- print(await hltv.get_event_info(7148, 'PGL CS2 Major Copenhagen2024'))
66
- await hltv.close_session()
65
+ async with Hltv() as hltv:
66
+ print(await hltv.get_event_info(7148, 'PGL CS2 Major Copenhagen2024'))
67
67
 
68
68
  ```
69
69
 
70
70
  **OR**
71
71
 
72
72
  ```
73
+
73
74
  from hltv_async_api import Hltv
74
75
 
75
- async with Hltv() as hltv:
76
- print(await hltv.get_event_info(7148, 'PGL CS2 Major Copenhagen2024'))
76
+ hltv = Hltv()
77
+ print(await hltv.get_event_info(7148, 'PGL CS2 Major Copenhagen2024'))
78
+ await hltv.close()
77
79
 
78
80
  ```
79
81
 
@@ -97,12 +99,12 @@ pip install hltv-async-api
97
99
  ```
98
100
 
99
101
 
100
- **One-time proxy**
102
+ **Delete proxy**
101
103
 
102
- removes bad proxies from list
104
+ Removes bad proxies
103
105
 
104
106
  ```
105
- hltv = Hltv(proxy_path='PATH_TO_PROXY.TXT', proxy_one_time=True)
107
+ hltv = Hltv(proxy_path='PATH_TO_PROXY.TXT', delete_proxy=True)
106
108
  ```
107
109
 
108
110
  **Protocol usage**
@@ -278,9 +280,9 @@ pip install hltv-async-api
278
280
 
279
281
  Proxy protocol. Your proxies ```hltv = Hltv(proxy_protocol='http' ...) -> '11.11.11.11:1111' -> 'http://11.11.11.11:1111'
280
282
 
281
- * proxy_one_time: bool = False
283
+ * delete_proxy: bool = False
282
284
 
283
- Removes proxy from list (proxy_path included) if connection unsuccessfull
285
+ Removes proxy from list (proxy_path included) if connection unsuccessfully
284
286
 
285
287
  * timeout: int = 5
286
288
 
@@ -288,6 +290,12 @@ pip install hltv-async-api
288
290
 
289
291
  * debug: bool = False
290
292
 
293
+ * tz: str = 'Europe/Copenhagen':
294
+
295
+ Timezone config.
296
+
297
+ <a href='https://gist.github.com/heyalexej/8bf688fd67d7199be4a1682b3eec7568'>Tap here </a> to see all available timezones
298
+
291
299
 
292
300
  ---
293
301
  # Examples
@@ -300,9 +308,8 @@ from hltv_async_api import Hltv
300
308
 
301
309
  async def test():
302
310
 
303
- hltv = Hltv()
304
-
305
- print(await hltv.get_event_info(7148, 'pgl-cs2-major-copenhagen-2024'))
311
+ async with Hltv() as hltv:
312
+ print(await hltv.get_event_info(7148, 'pgl-cs2-major-copenhagen-2024'))
306
313
 
307
314
  if __name__ == "__main__":
308
315
  asyncio.run(test())
@@ -316,7 +323,7 @@ from hltv_async_api import Hltv
316
323
 
317
324
  async def test():
318
325
 
319
- hltv = Hltv(debug=True, use_proxy=True, proxy_path='proxy_test.txt', timeout=1, proxy_one_time=True, proxy_protocol='http')
326
+ hltv = Hltv(debug=True, use_proxy=True, proxy_path='proxy_test.txt', timeout=1, delete_proxy=True, proxy_protocol='http')
320
327
 
321
328
  print(await hltv.get_event_info(7148, 'pgl-cs2-major-copenhagen-2024'))
322
329
 
@@ -339,15 +346,15 @@ if __name__ == "__main__":
339
346
 
340
347
 
341
348
  async def startup(ctx):
342
- ctx["hltv"] = Hltv(max_delay=5, use_proxy=True, proxy_path='proxies.txt', debug=True)
349
+ async with Hltv(max_delay=5, use_proxy=True, proxy_path='proxies.txt', debug=True) as hltv:
350
+ ctx["hltv"] = hltv
351
+
343
352
  ctx["redis"] = redis_client = Redis(
344
- connection_pool=ConnectionPool.from_url(settings.redis_url),
345
- )
353
+ connection_pool=ConnectionPool.from_url(settings.redis_url))
346
354
  logger.success(f"Scheduler started. UTC time {datetime.utcnow()}")
347
355
 
348
356
 
349
357
  async def shutdown(ctx):
350
- await ctx["hltv"].close_session()
351
358
  await ctx["redis"].close()
352
359
 
353
360
 
@@ -1,13 +1,13 @@
1
1
  # hltv-async-api an unofficial asynchronous HLTV API Wrapper for Python
2
2
 
3
3
 
4
- **This page not completed, not all methods and configs are written**
4
+ **This page is not completed, not all methods and configs are written**
5
5
 
6
6
 
7
7
  # Features
8
8
 
9
9
 
10
- * **Simple Usage** (its realy simple)
10
+ * **Simple Usage** (its really simple)
11
11
 
12
12
 
13
13
  * **New and modern fully async library**
@@ -36,21 +36,23 @@ pip install hltv-async-api
36
36
  # Simple Usage
37
37
 
38
38
  ```
39
+
39
40
  from hltv_async_api import Hltv
40
41
 
41
- hltv = Hltv()
42
- print(await hltv.get_event_info(7148, 'PGL CS2 Major Copenhagen2024'))
43
- await hltv.close_session()
42
+ async with Hltv() as hltv:
43
+ print(await hltv.get_event_info(7148, 'PGL CS2 Major Copenhagen2024'))
44
44
 
45
45
  ```
46
46
 
47
47
  **OR**
48
48
 
49
49
  ```
50
+
50
51
  from hltv_async_api import Hltv
51
52
 
52
- async with Hltv() as hltv:
53
- print(await hltv.get_event_info(7148, 'PGL CS2 Major Copenhagen2024'))
53
+ hltv = Hltv()
54
+ print(await hltv.get_event_info(7148, 'PGL CS2 Major Copenhagen2024'))
55
+ await hltv.close()
54
56
 
55
57
  ```
56
58
 
@@ -74,12 +76,12 @@ pip install hltv-async-api
74
76
  ```
75
77
 
76
78
 
77
- **One-time proxy**
79
+ **Delete proxy**
78
80
 
79
- removes bad proxies from list
81
+ Removes bad proxies
80
82
 
81
83
  ```
82
- hltv = Hltv(proxy_path='PATH_TO_PROXY.TXT', proxy_one_time=True)
84
+ hltv = Hltv(proxy_path='PATH_TO_PROXY.TXT', delete_proxy=True)
83
85
  ```
84
86
 
85
87
  **Protocol usage**
@@ -255,9 +257,9 @@ pip install hltv-async-api
255
257
 
256
258
  Proxy protocol. Your proxies ```hltv = Hltv(proxy_protocol='http' ...) -> '11.11.11.11:1111' -> 'http://11.11.11.11:1111'
257
259
 
258
- * proxy_one_time: bool = False
260
+ * delete_proxy: bool = False
259
261
 
260
- Removes proxy from list (proxy_path included) if connection unsuccessfull
262
+ Removes proxy from list (proxy_path included) if connection unsuccessfully
261
263
 
262
264
  * timeout: int = 5
263
265
 
@@ -265,6 +267,12 @@ pip install hltv-async-api
265
267
 
266
268
  * debug: bool = False
267
269
 
270
+ * tz: str = 'Europe/Copenhagen':
271
+
272
+ Timezone config.
273
+
274
+ <a href='https://gist.github.com/heyalexej/8bf688fd67d7199be4a1682b3eec7568'>Tap here </a> to see all available timezones
275
+
268
276
 
269
277
  ---
270
278
  # Examples
@@ -277,9 +285,8 @@ from hltv_async_api import Hltv
277
285
 
278
286
  async def test():
279
287
 
280
- hltv = Hltv()
281
-
282
- print(await hltv.get_event_info(7148, 'pgl-cs2-major-copenhagen-2024'))
288
+ async with Hltv() as hltv:
289
+ print(await hltv.get_event_info(7148, 'pgl-cs2-major-copenhagen-2024'))
283
290
 
284
291
  if __name__ == "__main__":
285
292
  asyncio.run(test())
@@ -293,7 +300,7 @@ from hltv_async_api import Hltv
293
300
 
294
301
  async def test():
295
302
 
296
- hltv = Hltv(debug=True, use_proxy=True, proxy_path='proxy_test.txt', timeout=1, proxy_one_time=True, proxy_protocol='http')
303
+ hltv = Hltv(debug=True, use_proxy=True, proxy_path='proxy_test.txt', timeout=1, delete_proxy=True, proxy_protocol='http')
297
304
 
298
305
  print(await hltv.get_event_info(7148, 'pgl-cs2-major-copenhagen-2024'))
299
306
 
@@ -316,15 +323,15 @@ if __name__ == "__main__":
316
323
 
317
324
 
318
325
  async def startup(ctx):
319
- ctx["hltv"] = Hltv(max_delay=5, use_proxy=True, proxy_path='proxies.txt', debug=True)
326
+ async with Hltv(max_delay=5, use_proxy=True, proxy_path='proxies.txt', debug=True) as hltv:
327
+ ctx["hltv"] = hltv
328
+
320
329
  ctx["redis"] = redis_client = Redis(
321
- connection_pool=ConnectionPool.from_url(settings.redis_url),
322
- )
330
+ connection_pool=ConnectionPool.from_url(settings.redis_url))
323
331
  logger.success(f"Scheduler started. UTC time {datetime.utcnow()}")
324
332
 
325
333
 
326
334
  async def shutdown(ctx):
327
- await ctx["hltv"].close_session()
328
335
  await ctx["redis"].close()
329
336
 
330
337
 
@@ -6,4 +6,4 @@
6
6
  from .aiohltv import Hltv
7
7
 
8
8
  __author__ = 'akimerslys'
9
- __version__ = '0.6.1'
9
+ __version__ = '0.6.5'
@@ -1,21 +1,14 @@
1
- import atexit
2
- import time
1
+ import pytz
2
+ import asyncio
3
+ import re
4
+ import logging
3
5
  from typing import Any, List
4
6
  from datetime import date, datetime, timedelta
5
- import pytz
6
-
7
7
  from bs4 import BeautifulSoup
8
- import asyncio
9
- from asyncio import get_running_loop
10
8
  from functools import partial
11
-
12
9
  from aiohttp import ClientSession, ClientTimeout
13
10
  from aiohttp.client_exceptions import ClientProxyConnectionError, ClientResponseError, ClientOSError, \
14
11
  ServerDisconnectedError, ClientHttpProxyError
15
- import re
16
-
17
- import logging
18
-
19
12
 
20
13
  class Hltv:
21
14
  def __init__(self, max_delay: int = 15,
@@ -25,29 +18,33 @@ class Hltv:
25
18
  debug: bool = False,
26
19
  max_retries: int = 0,
27
20
  proxy_protocol: str | None = None,
28
- proxy_one_time: bool = False,
29
- one_time_session: bool = True,
21
+ delete_proxy: bool = False,
22
+ tz: str = 'Europe/Copenhagen',
30
23
  ):
31
24
  self.headers = {
32
25
  "referer": "https://www.hltv.org/stats",
33
26
  "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)",
34
- "hltvTimeZone": "UTC"
27
+ "hltvTimeZone": "Europe/Copenhagen"
35
28
  }
36
- self.MAX_DELAY = max_delay
37
- self.timeout = timeout
38
- self.max_retries = max_retries
39
29
  self.DEBUG = debug
40
30
  self._configure_logging()
41
31
  self.logger = logging.getLogger(__name__)
42
32
 
33
+ self.MAX_DELAY = max_delay
34
+ self.timeout = timeout
35
+ self.max_retries = max_retries
36
+
37
+ self.TIMEZONE = tz
38
+ self._check_tz()
39
+
43
40
  self.PROXY_PATH = proxy_path
44
41
  self.PROXY_LIST = proxy_list
45
42
  self.PROXY_PROTOCOL = proxy_protocol
46
- self.PROXY_ONCE = proxy_one_time
43
+ self.PROXY_ONCE = delete_proxy
47
44
 
48
45
  if self.PROXY_PATH:
49
46
  with open(self.PROXY_PATH, "r") as file:
50
- self.PROXY_LIST = [line.strip() for line in file.readlines()]
47
+ self.PROXY_LIST = [line.strip() for line in file.readlines()]
51
48
 
52
49
  if self.PROXY_PROTOCOL:
53
50
  self.PROXY_LIST = [self.PROXY_PROTOCOL + '://' + proxy for i, proxy in enumerate(self.PROXY_LIST, start=0)]
@@ -68,14 +65,14 @@ class Hltv:
68
65
  return self
69
66
 
70
67
  async def __aexit__(self, exc_type, exc, tb):
71
- await self.close_session()
68
+ await self.close()
72
69
 
73
70
  async def _create_session(self):
74
71
  if not self.session:
75
72
  self.logger.debug('Creating Session')
76
73
  self.session = ClientSession()
77
74
 
78
- async def close_session(self):
75
+ async def close(self):
79
76
  if self.session:
80
77
  self.logger.debug('Closing Session')
81
78
  await self.session.close()
@@ -89,8 +86,8 @@ class Hltv:
89
86
  debug: bool | None = None,
90
87
  max_retries: int | None = None,
91
88
  proxy_protocol: str | None = None,
92
- proxy_one_time: bool | None = None,
93
- one_time_session: bool | None = None,
89
+ delete_proxy: bool | None = None,
90
+ tz: str = None,
94
91
  ):
95
92
  if max_delay:
96
93
  self.MAX_DELAY = max_delay
@@ -104,10 +101,11 @@ class Hltv:
104
101
  self.max_retries = max_retries
105
102
  if proxy_protocol:
106
103
  self.PROXY_PROTOCOL = proxy_protocol
107
- if proxy_one_time is not None:
108
- self.PROXY_ONCE = proxy_one_time
109
- if one_time_session is not None:
110
- self.ONE_TIME_SESSION = one_time_session
104
+ if delete_proxy is not None:
105
+ self.PROXY_ONCE = delete_proxy
106
+ if tz is not None:
107
+ self.TIMEZONE = tz
108
+ self._check_tz()
111
109
  if debug is not None:
112
110
  self.DEBUG = debug
113
111
  self._configure_logging()
@@ -115,6 +113,13 @@ class Hltv:
115
113
  with open(self.PROXY_PATH, "r") as file:
116
114
  self.PROXY_LIST = [line.strip() for line in file.readlines()]
117
115
 
116
+ def _check_tz(self):
117
+ try:
118
+ pytz.timezone(self.TIMEZONE)
119
+ except pytz.exceptions.UnknownTimeZoneError:
120
+ self.logger.error('UnknownTimeZoneError, using default timezone: Europe/Copenhagen')
121
+ self.TIMEZONE = 'Europe/Copenhagen'
122
+
118
123
  def _get_proxy(self):
119
124
  proxy = self.PROXY_LIST[0]
120
125
 
@@ -193,7 +198,7 @@ class Hltv:
193
198
  try_ = 1
194
199
  result = None
195
200
 
196
- # parse until success or not maxretries
201
+ # parse until success or not max retries
197
202
  while (not status) and (try_ != self.max_retries):
198
203
  self.logger.debug(f'Trying connect to {url}, try {try_}/{self.max_retries}')
199
204
 
@@ -206,7 +211,7 @@ class Hltv:
206
211
  try_ += 1
207
212
 
208
213
  if status:
209
- loop = get_running_loop()
214
+ loop = asyncio.get_running_loop()
210
215
  parsed = await loop.run_in_executor(None, partial(self._f, result))
211
216
  return parsed
212
217
  else:
@@ -232,6 +237,16 @@ class Hltv:
232
237
  date = datetime.strptime(date_string, "%B%d%Y")
233
238
  return date.strftime("%d-%m-%Y")
234
239
 
240
+ def _localize_datetime_to_timezone(self, date_: datetime = None, date_str: str = None) -> datetime:
241
+ if self.TIMEZONE == 'Europe/Copenhagen':
242
+ return date_
243
+ if date_str:
244
+ date_ = datetime.strptime(date_str, '%d-%m-%Y')
245
+ if date_.tzinfo:
246
+ return date_.astimezone(pytz.timezone(self.TIMEZONE))
247
+ else:
248
+ return date_.replace(tzinfo=pytz.timezone('Europe/Copenhagen')).astimezone(pytz.timezone(self.TIMEZONE))
249
+
235
250
  async def get(self, type: str, id: int | str | None = None,
236
251
  title: str | None = None,
237
252
  team1: str | None = None,
@@ -303,6 +318,8 @@ class Hltv:
303
318
 
304
319
  for match in date_div.find_all('div', {'class': 'upcomingMatch'}):
305
320
  time_ = match.find('div', {'class': 'matchTime'}).text
321
+ dtime_ = datetime.strptime(date_ + '/' + time_, "%Y-%m-%d/%H:%M")
322
+ dtime = self._localize_datetime_to_timezone(date_=dtime_)
306
323
  rating = int(match['stars'])
307
324
  if rating >= min_rating:
308
325
  id_ = 0
@@ -337,8 +354,8 @@ class Hltv:
337
354
 
338
355
  matches.append({
339
356
  'id': id_,
340
- 'date': date_,
341
- 'time': time_,
357
+ 'date': dtime.strftime('%d-%m-%Y'),
358
+ 'time': dtime.strftime('%H:%M'),
342
359
  'team1': team1,
343
360
  'team2': team2,
344
361
  't1_id': t1_id,
@@ -360,31 +377,68 @@ class Hltv:
360
377
  f"{event_title.replace(' ', '-')}")
361
378
  if not r:
362
379
  return
380
+ status_ = {'Match over': 0, 'LIVE': 1}
363
381
 
364
382
  status = r.find('div', {'class': 'countdown'}).text
365
383
 
384
+ status_int = status_[status] if status in status_ else 2
385
+
386
+ if status_int == 2:
387
+ components = status.split(" : ")
388
+
389
+ days, hours, minutes, seconds = 0, 0, 0, 0
390
+
391
+ for component in components:
392
+ if 'd' in component:
393
+ days = int(component.replace("d", ""))
394
+ elif 'h' in component:
395
+ hours = int(component.replace("h", ""))
396
+ elif 'm' in component:
397
+ minutes = int(component.replace("m", ""))
398
+ elif 's' in component:
399
+ seconds = int(component.replace("s", ""))
400
+
401
+ date_ = datetime.now(tz=pytz.timezone('Europe/Copenhagen')).replace(second=0, microsecond=0) + timedelta(
402
+ days=days,
403
+ hours=hours,
404
+ minutes=minutes,
405
+ seconds=seconds)
406
+
407
+ status = self._localize_datetime_to_timezone(date_=date_).strftime('%d-%m-%Y-%H-%M')
408
+
366
409
  score1, score2 = 0, 0
367
410
 
368
- if status == 'Match over':
411
+ if status_int == 0:
369
412
  scores = r.find_all('div', class_='team')
370
413
  score1 = scores[0].get_text().replace('\n', '')[-1]
371
414
  score2 = scores[1].get_text().replace('\n', '')[-1]
372
415
 
373
416
  maps = []
374
417
  for map_div in r.find_all('div', {'class': 'mapholder'}):
375
-
376
418
  mapname = map_div.find('div', {'class': 'mapname'}).text
377
- try:
378
- r_teams = map_div.find_all('div', {'class': 'results-team-score'})
379
- r_team1 = r_teams[0].text
380
- r_team2 = r_teams[1].text
381
- except (AttributeError, IndexError):
382
- r_team1 = '0'
383
- r_team2 = '0'
384
- maps.append({'mapname': mapname, 'r_team1': r_team1, 'r_team2': r_team2})
419
+ pick = ''
420
+ r_team1 = '0'
421
+ r_team2 = '0'
422
+ if mapname != 'TBA':
423
+ try:
424
+ r_teams = map_div.find_all('div', {'class': 'results-team-score'})
425
+ r_team1 = r_teams[0].text
426
+ r_team2 = r_teams[1].text
427
+ except (AttributeError, IndexError, TypeError):
428
+ r_team1 = '0'
429
+ r_team2 = '0'
430
+ try:
431
+ if 'pick' in map_div.find('div', class_='results-left')['class']:
432
+ pick = team1
433
+ elif 'pick' in map_div.find('span', class_='results-right')['class']:
434
+ pick = team2
435
+ except TypeError:
436
+ pick = ''
437
+
438
+ maps.append({'mapname': mapname, 'r_team1': r_team1, 'r_team2': r_team2, 'pick': pick})
385
439
 
386
440
  stats_ = []
387
- if stats and status == 'Match over':
441
+ if stats and status_int == 0:
388
442
  for table_div in r.find_all('table', {'class': 'table totalstats'})[:2]:
389
443
  for player in table_div.find_all('tr')[1:]:
390
444
  player_id = player.find('a', class_='flagAlign')['href'].split('/')[2]
@@ -402,17 +456,18 @@ class Hltv:
402
456
  'rating': rating
403
457
  })
404
458
 
405
- if status == "LIVE":
459
+ if status_int == 1:
406
460
  for map in maps:
461
+ len_ = len(map)
407
462
  if map["r_team1"] == '13':
408
- if len(map) != 1:
463
+ if len_ != 1:
409
464
  score1 += 1
410
465
  else:
411
466
  score1 = 13
412
467
  score2 = int(map["r_team2"])
413
468
 
414
469
  elif map["r_team1"] == '13':
415
- if len(map) != 1:
470
+ if len_ != 1:
416
471
  score2 += 1
417
472
  else:
418
473
  score2 = 13
@@ -433,34 +488,38 @@ class Hltv:
433
488
  results = []
434
489
 
435
490
  if featured:
436
- big_res = r.find("div", {'class', "big-results"}).find_all("a", {"class": "a-reset"})
437
- for res in big_res:
438
-
439
- try:
440
- rating = len(big_res.find_all('i', {'class': 'fa fa-star star'}))
441
- except AttributeError:
442
- rating = 0
443
-
444
- match_id = res['href'].split('/', 3)[2]
445
- teams = res.find_all('td', class_='team-cell')
446
- team1 = teams[0].get_text().strip()
447
- team2 = teams[1].get_text().strip()
448
-
449
- event = res.find('span', class_='event-name').text
491
+ try:
492
+ big_res = r.find("div", {'class', "big-results"}).find_all("a", {"class": "a-reset"})
450
493
 
451
- scores = res.find("td", class_="result-score").text.strip().split('-')
452
- s_t1 = scores[0].strip()
453
- s_t2 = scores[1].strip()
494
+ for res in big_res:
454
495
 
455
- results.append({
456
- 'id': match_id,
457
- 'team1': team1,
458
- 'team2': team2,
459
- 'score1': s_t1,
460
- 'score2': s_t2,
461
- 'rating': rating,
462
- 'event': event,
463
- })
496
+ try:
497
+ rating = len(big_res.find_all('i', {'class': 'fa fa-star star'}))
498
+ except AttributeError:
499
+ rating = 0
500
+
501
+ match_id = res['href'].split('/', 3)[2]
502
+ teams = res.find_all('td', class_='team-cell')
503
+ team1 = teams[0].get_text().strip()
504
+ team2 = teams[1].get_text().strip()
505
+
506
+ event = res.find('span', class_='event-name').text
507
+
508
+ scores = res.find("td", class_="result-score").text.strip().split('-')
509
+ s_t1 = scores[0].strip()
510
+ s_t2 = scores[1].strip()
511
+
512
+ results.append({
513
+ 'id': match_id,
514
+ 'team1': team1,
515
+ 'team2': team2,
516
+ 'score1': s_t1,
517
+ 'score2': s_t2,
518
+ 'rating': rating,
519
+ 'event': event,
520
+ })
521
+ except AttributeError:
522
+ pass
464
523
 
465
524
  if regular:
466
525
 
@@ -470,6 +529,8 @@ class Hltv:
470
529
  if i > days: break
471
530
 
472
531
  date_ = self.__normalize_date(date_div.find('span', class_='standard-headline').text)
532
+ date = self._localize_datetime_to_timezone(date_str=date_).strftime('%d-%m-%Y')
533
+
473
534
  for res in date_div.find_all("a", {"class": "a-reset"}):
474
535
  if res['href'] == '/forums' or n > max:
475
536
  break
@@ -496,7 +557,7 @@ class Hltv:
496
557
 
497
558
  results.append({
498
559
  'id': match_id,
499
- 'date': date_,
560
+ 'date': date,
500
561
  'team1': team1,
501
562
  'team2': team2,
502
563
  'score1': s_t1,
@@ -521,7 +582,9 @@ class Hltv:
521
582
  r.find("div", {'class', 'results-holder'}).find_all("div", {'class', 'results-sublist'}), start=1):
522
583
  if i > days or n > max_:
523
584
  break
524
- date = self.__normalize_date(result.find("span", class_="standard-headline").text.strip())
585
+ date_ = self.__normalize_date(result.find("span", class_="standard-headline").text.strip())
586
+ date = self._localize_datetime_to_timezone(date_str=date_).strftime("%d-%m-%Y")
587
+
525
588
  for match in result.find_all("a", class_="a-reset"):
526
589
  if n > max_:
527
590
  break
@@ -534,7 +597,7 @@ class Hltv:
534
597
  score_t1 = scores[0].strip()
535
598
  score_t2 = scores[1].strip()
536
599
 
537
- # add team ids?
600
+ # TODO add team ids
538
601
  match_results.append({
539
602
  'id': id_,
540
603
  'date': date,
@@ -585,7 +648,8 @@ class Hltv:
585
648
  })
586
649
 
587
650
  for date_sect in r.find_all('div', {'class': 'upcomingMatchesSection'}):
588
- date_ = date_sect.find('span', {'class': 'matchDayHeadline'}).text.split(' ')[-1]
651
+ date_ = datetime.strptime(date_sect.find('span', {'class': 'matchDayHeadline'}).text.split(' ')[-1],
652
+ "%Y-%m-%d")
589
653
  for match in date_sect.find_all('div', {'class': 'upcomingMatch'}):
590
654
  teams_ = match.find_all("div", class_="matchTeamName text-ellipsis")
591
655
  id_ = match.find('a')['href'].split('/')[2]
@@ -614,6 +678,7 @@ class Hltv:
614
678
 
615
679
  return matches
616
680
 
681
+ #DELETE ?
617
682
  async def get_featured_events(self, max_: int = 1):
618
683
  r = await self._fetch('https://www.hltv.org/events')
619
684
 
@@ -642,7 +707,7 @@ class Hltv:
642
707
 
643
708
  return events
644
709
 
645
- async def get_events(self, featured=True, outgoing=True, future=True, max_events=10):
710
+ async def get_events(self, outgoing=True, future=True, max_events=10):
646
711
  """Returns events
647
712
  :params:
648
713
  outgoing - include live tournaments
@@ -960,8 +1025,8 @@ class Hltv:
960
1025
 
961
1026
 
962
1027
  async def main():
963
- hltv = Hltv()
964
- print(await hltv.get_matches())
1028
+ hltv = Hltv(tz='UT234C')
1029
+ print(await hltv.get_match_info(2371594, '3DMAX', 'Guild-Eagles', 'YaLLa-Compass-Spring-2024'))
965
1030
 
966
1031
  if __name__ == '__main__':
967
1032
  asyncio.run(main())
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "hltv_async_api"
3
- version = "0.6.2"
3
+ version = "0.6.5"
4
4
  authors = ["Akim Slys <akimslys2003@gmail.com>"]
5
5
  description = "Hltv-aio An unofficial asynchronous HLTV API Wrapper for Python"
6
6
  readme = "README.md"
File without changes