hltv-async-api 0.4.2__tar.gz → 0.4.3__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.4.2
3
+ Version: 0.4.3
4
4
  Summary: Hltv-aio An unofficial asynchronous HLTV API Wrapper for Python
5
5
  Home-page: https://github.com/akimerslys/aiohltv
6
6
  Author: akimerslys
@@ -29,7 +29,13 @@ License-File: LICENSE
29
29
  * **New and modern fully async library**
30
30
 
31
31
 
32
- * **Supports proxy usage with huge amount of options**
32
+ * **Huge amount of options**
33
+
34
+
35
+ * **Supports proxy usage**
36
+
37
+
38
+ * **Made with love <3**
33
39
 
34
40
 
35
41
  ---
@@ -206,7 +212,8 @@ pip install hltv-async-api
206
212
 
207
213
  * proxy_list: list | None = None
208
214
 
209
- list of your proxies, if your proxies doesnt have any protocol you can use proxy_protocol
215
+ list of your proxies, if your proxies doesnt have any protocol you can use proxy_protocol.
216
+ Note: To add nonproxy to list just put '' to it, you can find example with ar
210
217
 
211
218
  * proxy_path: str | None = None
212
219
 
@@ -231,7 +238,7 @@ pip install hltv-async-api
231
238
  * true_session=False
232
239
 
233
240
  **(BETA)**
234
- This parser automaticaly creating and clossing sessions after every use, if you want to let your session open even when parser is inactive
241
+ This parser automaticaly creating and clossing session after every call, if you want to let your session open even when parser is inactive
235
242
  use this method. **!! IMPORTANT YOU SHOULD CLOSE YOUR SESSION BEFORE KILLING PROGRAM**
236
243
 
237
244
  ```
@@ -265,6 +272,7 @@ if __name__ == "__main__":
265
272
  ```
266
273
 
267
274
  ****Proxy Parser****
275
+
268
276
  ```
269
277
  from hltv_async_api import Hltv
270
278
 
@@ -279,6 +287,101 @@ if __name__ == "__main__":
279
287
  asyncio.run(test())
280
288
  ```
281
289
 
290
+ ****Automatic parser with arq and redis****
291
+
292
+ - to run type "arq PATH_TO_FILE.WorkerSettings"
293
+
294
+ ```
295
+ import ujson
296
+ import asyncio
297
+ from arq import cron
298
+ from redis.asyncio import Redis, ConnectionPool
299
+
300
+ from hltv_async_api import Hltv
301
+
302
+
303
+
304
+ async def startup(ctx):
305
+ ctx["hltv"] = Hltv(max_delay=5, use_proxy=True, proxy_list=[settings.PROXY_MAIN, ''], true_session=True, debug=True)
306
+ ctx["redis"] = redis_client = Redis(
307
+ connection_pool=ConnectionPool.from_url(settings.redis_url),
308
+ )
309
+ logger.success(f"Scheduler started. UTC time {datetime.utcnow()}")
310
+
311
+
312
+ async def shutdown(ctx):
313
+ await ctx["hltv"].close_session()
314
+ await ctx["redis"].close()
315
+
316
+
317
+ async def parse_matches(ctx):
318
+ hltv = ctx["hltv"]
319
+ redis = ctx["redis"]
320
+ matches = await hltv.get_upcoming_matches(1, 1)
321
+ if matches:
322
+ await redis.set("matches", ujson.dumps(matches))
323
+ else:
324
+ logger.error("error parsing matches")
325
+
326
+ async def parse_events(ctx):
327
+ hltv = ctx["hltv"]
328
+ redis = ctx["redis"]
329
+ events = await hltv.get_events()
330
+ if events:
331
+ await redis.set("events", ujson.dumps(events))
332
+ else:
333
+ logger.error("error parsing events")
334
+
335
+
336
+ async def parse_top_teams(ctx):
337
+ hltv = ctx["hltv"]
338
+ redis = ctx["redis"]
339
+ top_teams = await hltv.get_top_teams(30)
340
+ if top_teams:
341
+ await redis.set("top_teams", ujson.dumps(top_teams))
342
+ else:
343
+ logger.error("error parsing top teams")
344
+
345
+
346
+ async def parse_top_players(ctx):
347
+ hltv = ctx["hltv"]
348
+ redis = ctx["redis"]
349
+ top_players = await hltv.get_best_players(30)
350
+ if top_players:
351
+ await redis.set("top_teams", ujson.dumps(top_players))
352
+ else:
353
+ logger.error("error parsing top players")
354
+
355
+
356
+ async def parse_last_news(ctx):
357
+ hltv = ctx["hltv"]
358
+ redis = ctx["redis"]
359
+ news = await hltv.get_last_news(only_today=True, max_reg_news=4)
360
+ if news:
361
+ await redis.set("news", ujson.dumps(news))
362
+ else:
363
+ logger.error("error parsing news")
364
+
365
+
366
+ class WorkerSettings:
367
+ redis_settings = settings.redis_pool
368
+ on_startup = startup
369
+ on_shutdown = shutdown
370
+ functions = [parse_matches,
371
+ parse_events,
372
+ parse_top_teams,
373
+ parse_top_players,
374
+ parse_last_news,
375
+ ]
376
+ cron_jobs = [
377
+ cron(parse_matches, minute=59),
378
+ cron(parse_events, hour=0, minute=0, second=0),
379
+ cron(parse_top_teams, day=0, hour=18, minute=1, second=30),
380
+ cron(parse_top_players, day=0, hour=20, minute=0, second=0),
381
+ cron(parse_last_news, minute=55),
382
+ ]
383
+
384
+ ```
282
385
 
283
386
  # Requirements:
284
387
 
@@ -13,7 +13,13 @@
13
13
  * **New and modern fully async library**
14
14
 
15
15
 
16
- * **Supports proxy usage with huge amount of options**
16
+ * **Huge amount of options**
17
+
18
+
19
+ * **Supports proxy usage**
20
+
21
+
22
+ * **Made with love <3**
17
23
 
18
24
 
19
25
  ---
@@ -190,7 +196,8 @@ pip install hltv-async-api
190
196
 
191
197
  * proxy_list: list | None = None
192
198
 
193
- list of your proxies, if your proxies doesnt have any protocol you can use proxy_protocol
199
+ list of your proxies, if your proxies doesnt have any protocol you can use proxy_protocol.
200
+ Note: To add nonproxy to list just put '' to it, you can find example with ar
194
201
 
195
202
  * proxy_path: str | None = None
196
203
 
@@ -215,7 +222,7 @@ pip install hltv-async-api
215
222
  * true_session=False
216
223
 
217
224
  **(BETA)**
218
- This parser automaticaly creating and clossing sessions after every use, if you want to let your session open even when parser is inactive
225
+ This parser automaticaly creating and clossing session after every call, if you want to let your session open even when parser is inactive
219
226
  use this method. **!! IMPORTANT YOU SHOULD CLOSE YOUR SESSION BEFORE KILLING PROGRAM**
220
227
 
221
228
  ```
@@ -249,6 +256,7 @@ if __name__ == "__main__":
249
256
  ```
250
257
 
251
258
  ****Proxy Parser****
259
+
252
260
  ```
253
261
  from hltv_async_api import Hltv
254
262
 
@@ -263,6 +271,101 @@ if __name__ == "__main__":
263
271
  asyncio.run(test())
264
272
  ```
265
273
 
274
+ ****Automatic parser with arq and redis****
275
+
276
+ - to run type "arq PATH_TO_FILE.WorkerSettings"
277
+
278
+ ```
279
+ import ujson
280
+ import asyncio
281
+ from arq import cron
282
+ from redis.asyncio import Redis, ConnectionPool
283
+
284
+ from hltv_async_api import Hltv
285
+
286
+
287
+
288
+ async def startup(ctx):
289
+ ctx["hltv"] = Hltv(max_delay=5, use_proxy=True, proxy_list=[settings.PROXY_MAIN, ''], true_session=True, debug=True)
290
+ ctx["redis"] = redis_client = Redis(
291
+ connection_pool=ConnectionPool.from_url(settings.redis_url),
292
+ )
293
+ logger.success(f"Scheduler started. UTC time {datetime.utcnow()}")
294
+
295
+
296
+ async def shutdown(ctx):
297
+ await ctx["hltv"].close_session()
298
+ await ctx["redis"].close()
299
+
300
+
301
+ async def parse_matches(ctx):
302
+ hltv = ctx["hltv"]
303
+ redis = ctx["redis"]
304
+ matches = await hltv.get_upcoming_matches(1, 1)
305
+ if matches:
306
+ await redis.set("matches", ujson.dumps(matches))
307
+ else:
308
+ logger.error("error parsing matches")
309
+
310
+ async def parse_events(ctx):
311
+ hltv = ctx["hltv"]
312
+ redis = ctx["redis"]
313
+ events = await hltv.get_events()
314
+ if events:
315
+ await redis.set("events", ujson.dumps(events))
316
+ else:
317
+ logger.error("error parsing events")
318
+
319
+
320
+ async def parse_top_teams(ctx):
321
+ hltv = ctx["hltv"]
322
+ redis = ctx["redis"]
323
+ top_teams = await hltv.get_top_teams(30)
324
+ if top_teams:
325
+ await redis.set("top_teams", ujson.dumps(top_teams))
326
+ else:
327
+ logger.error("error parsing top teams")
328
+
329
+
330
+ async def parse_top_players(ctx):
331
+ hltv = ctx["hltv"]
332
+ redis = ctx["redis"]
333
+ top_players = await hltv.get_best_players(30)
334
+ if top_players:
335
+ await redis.set("top_teams", ujson.dumps(top_players))
336
+ else:
337
+ logger.error("error parsing top players")
338
+
339
+
340
+ async def parse_last_news(ctx):
341
+ hltv = ctx["hltv"]
342
+ redis = ctx["redis"]
343
+ news = await hltv.get_last_news(only_today=True, max_reg_news=4)
344
+ if news:
345
+ await redis.set("news", ujson.dumps(news))
346
+ else:
347
+ logger.error("error parsing news")
348
+
349
+
350
+ class WorkerSettings:
351
+ redis_settings = settings.redis_pool
352
+ on_startup = startup
353
+ on_shutdown = shutdown
354
+ functions = [parse_matches,
355
+ parse_events,
356
+ parse_top_teams,
357
+ parse_top_players,
358
+ parse_last_news,
359
+ ]
360
+ cron_jobs = [
361
+ cron(parse_matches, minute=59),
362
+ cron(parse_events, hour=0, minute=0, second=0),
363
+ cron(parse_top_teams, day=0, hour=18, minute=1, second=30),
364
+ cron(parse_top_players, day=0, hour=20, minute=0, second=0),
365
+ cron(parse_last_news, minute=55),
366
+ ]
367
+
368
+ ```
266
369
 
267
370
  # Requirements:
268
371
 
@@ -6,4 +6,4 @@
6
6
  from .aiohltv import Hltv
7
7
 
8
8
  __author__ = 'akimerslys'
9
- __version__ = '0.4.2'
9
+ __version__ = '0.4.3'
@@ -218,19 +218,19 @@ class Hltv:
218
218
  title: str | None = None,
219
219
  team1: str | None = None,
220
220
  team2: str | None = None):
221
- if type == 'event':
221
+ if type == 'events':
222
222
  if id:
223
223
  return await self.get_event_info(id, title)
224
224
  else:
225
225
  return await self.get_events()
226
- elif type == 'match':
226
+ elif type == 'matches':
227
227
  if id:
228
228
  return await self.get_match_info(str(id), team1, team2, title)
229
229
  else:
230
230
  return await self.get_upcoming_matches()
231
231
  elif type == 'news':
232
232
  return await self.get_last_news()
233
- elif type == 'team':
233
+ elif type == 'teams':
234
234
  if id:
235
235
  return await self.get_team_info(id, title)
236
236
  else:
@@ -445,7 +445,6 @@ class Hltv:
445
445
  live_matches = r.find("div", {'class', 'liveMatchesSection'}).find_all("div", {'class', 'liveMatch-container'})
446
446
  except AttributeError:
447
447
  live_matches = []
448
- live_mat = []
449
448
  for live in live_matches:
450
449
  id_ = live.find('a', {'class': 'match a-reset'})['href'].split('/')[2]
451
450
  teams = live.find_all("div", class_="matchTeamName text-ellipsis")
@@ -464,20 +463,16 @@ class Hltv:
464
463
  score_team1 = 0
465
464
  score_team2 = 0"""
466
465
 
467
- live_mat.append({
466
+ matches.append({
468
467
  'id': id_,
468
+ 'date': 'LIVE',
469
469
  'team1': team1,
470
470
  'team2': team2,
471
471
  't1_id': t1_id,
472
472
  't2_id': t2_id
473
473
  })
474
474
 
475
- matches.append({
476
- 'date': 'LIVE',
477
- 'matches': live_mat,
478
- })
479
475
  for date_sect in r.find_all('div', {'class': 'upcomingMatchesSection'}):
480
- upc_matches = []
481
476
  date_ = date_sect.find('span', {'class': 'matchDayHeadline'}).text.split(' ')[-1]
482
477
  for match in date_sect.find_all('div', {'class': 'upcomingMatch'}):
483
478
  teams_ = match.find_all("div", class_="matchTeamName text-ellipsis")
@@ -495,8 +490,9 @@ class Hltv:
495
490
  except IndexError:
496
491
  pass
497
492
 
498
- upc_matches.append({
493
+ matches.append({
499
494
  'id': id_,
495
+ 'date': date_,
500
496
  'time': time_,
501
497
  'team1': team1_,
502
498
  'team2': team2_,
@@ -504,8 +500,6 @@ class Hltv:
504
500
  't2_id': t2_id
505
501
  })
506
502
 
507
- matches.append({'date': date_, 'matches': upc_matches})
508
-
509
503
  return matches
510
504
  async def get_featured_events(self, max_: int = 1):
511
505
  r = await self._fetch('https://www.hltv.org/events')
@@ -590,7 +584,7 @@ class Hltv:
590
584
  return events
591
585
 
592
586
  async def get_event_info(self, event_id: str | int, event_title: str):
593
- #TODO ADD PLACEC FOR PAST EVENTS? OR WINNER?
587
+ #TODO ADD WINNER?
594
588
 
595
589
  r = await self._fetch(f"https://www.hltv.org/events/{str(event_id)}/{event_title.replace(' ', '-')}")
596
590
  if not r:
@@ -776,6 +770,7 @@ class Hltv:
776
770
  return players
777
771
 
778
772
  async def get_last_news(self, max_reg_news=2, only_today=True, only_featured=False):
773
+
779
774
  r = await self._fetch('https://www.hltv.org/')
780
775
 
781
776
  today = datetime.now(tz=pytz.timezone('Europe/Copenhagen'))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: hltv_async_api
3
- Version: 0.4.2
3
+ Version: 0.4.3
4
4
  Summary: Hltv-aio An unofficial asynchronous HLTV API Wrapper for Python
5
5
  Home-page: https://github.com/akimerslys/aiohltv
6
6
  Author: akimerslys
@@ -29,7 +29,13 @@ License-File: LICENSE
29
29
  * **New and modern fully async library**
30
30
 
31
31
 
32
- * **Supports proxy usage with huge amount of options**
32
+ * **Huge amount of options**
33
+
34
+
35
+ * **Supports proxy usage**
36
+
37
+
38
+ * **Made with love <3**
33
39
 
34
40
 
35
41
  ---
@@ -206,7 +212,8 @@ pip install hltv-async-api
206
212
 
207
213
  * proxy_list: list | None = None
208
214
 
209
- list of your proxies, if your proxies doesnt have any protocol you can use proxy_protocol
215
+ list of your proxies, if your proxies doesnt have any protocol you can use proxy_protocol.
216
+ Note: To add nonproxy to list just put '' to it, you can find example with ar
210
217
 
211
218
  * proxy_path: str | None = None
212
219
 
@@ -231,7 +238,7 @@ pip install hltv-async-api
231
238
  * true_session=False
232
239
 
233
240
  **(BETA)**
234
- This parser automaticaly creating and clossing sessions after every use, if you want to let your session open even when parser is inactive
241
+ This parser automaticaly creating and clossing session after every call, if you want to let your session open even when parser is inactive
235
242
  use this method. **!! IMPORTANT YOU SHOULD CLOSE YOUR SESSION BEFORE KILLING PROGRAM**
236
243
 
237
244
  ```
@@ -265,6 +272,7 @@ if __name__ == "__main__":
265
272
  ```
266
273
 
267
274
  ****Proxy Parser****
275
+
268
276
  ```
269
277
  from hltv_async_api import Hltv
270
278
 
@@ -279,6 +287,101 @@ if __name__ == "__main__":
279
287
  asyncio.run(test())
280
288
  ```
281
289
 
290
+ ****Automatic parser with arq and redis****
291
+
292
+ - to run type "arq PATH_TO_FILE.WorkerSettings"
293
+
294
+ ```
295
+ import ujson
296
+ import asyncio
297
+ from arq import cron
298
+ from redis.asyncio import Redis, ConnectionPool
299
+
300
+ from hltv_async_api import Hltv
301
+
302
+
303
+
304
+ async def startup(ctx):
305
+ ctx["hltv"] = Hltv(max_delay=5, use_proxy=True, proxy_list=[settings.PROXY_MAIN, ''], true_session=True, debug=True)
306
+ ctx["redis"] = redis_client = Redis(
307
+ connection_pool=ConnectionPool.from_url(settings.redis_url),
308
+ )
309
+ logger.success(f"Scheduler started. UTC time {datetime.utcnow()}")
310
+
311
+
312
+ async def shutdown(ctx):
313
+ await ctx["hltv"].close_session()
314
+ await ctx["redis"].close()
315
+
316
+
317
+ async def parse_matches(ctx):
318
+ hltv = ctx["hltv"]
319
+ redis = ctx["redis"]
320
+ matches = await hltv.get_upcoming_matches(1, 1)
321
+ if matches:
322
+ await redis.set("matches", ujson.dumps(matches))
323
+ else:
324
+ logger.error("error parsing matches")
325
+
326
+ async def parse_events(ctx):
327
+ hltv = ctx["hltv"]
328
+ redis = ctx["redis"]
329
+ events = await hltv.get_events()
330
+ if events:
331
+ await redis.set("events", ujson.dumps(events))
332
+ else:
333
+ logger.error("error parsing events")
334
+
335
+
336
+ async def parse_top_teams(ctx):
337
+ hltv = ctx["hltv"]
338
+ redis = ctx["redis"]
339
+ top_teams = await hltv.get_top_teams(30)
340
+ if top_teams:
341
+ await redis.set("top_teams", ujson.dumps(top_teams))
342
+ else:
343
+ logger.error("error parsing top teams")
344
+
345
+
346
+ async def parse_top_players(ctx):
347
+ hltv = ctx["hltv"]
348
+ redis = ctx["redis"]
349
+ top_players = await hltv.get_best_players(30)
350
+ if top_players:
351
+ await redis.set("top_teams", ujson.dumps(top_players))
352
+ else:
353
+ logger.error("error parsing top players")
354
+
355
+
356
+ async def parse_last_news(ctx):
357
+ hltv = ctx["hltv"]
358
+ redis = ctx["redis"]
359
+ news = await hltv.get_last_news(only_today=True, max_reg_news=4)
360
+ if news:
361
+ await redis.set("news", ujson.dumps(news))
362
+ else:
363
+ logger.error("error parsing news")
364
+
365
+
366
+ class WorkerSettings:
367
+ redis_settings = settings.redis_pool
368
+ on_startup = startup
369
+ on_shutdown = shutdown
370
+ functions = [parse_matches,
371
+ parse_events,
372
+ parse_top_teams,
373
+ parse_top_players,
374
+ parse_last_news,
375
+ ]
376
+ cron_jobs = [
377
+ cron(parse_matches, minute=59),
378
+ cron(parse_events, hour=0, minute=0, second=0),
379
+ cron(parse_top_teams, day=0, hour=18, minute=1, second=30),
380
+ cron(parse_top_players, day=0, hour=20, minute=0, second=0),
381
+ cron(parse_last_news, minute=55),
382
+ ]
383
+
384
+ ```
282
385
 
283
386
  # Requirements:
284
387
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "hltv_async_api"
3
- version = "0.4.2"
3
+ version = "0.4.3"
4
4
  authors = [
5
5
  { name="Akim Slys", email="akimslys2003@gmail.com" },
6
6
  ]
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name='hltv_async_api',
5
- version='0.4.2',
5
+ version='0.4.3',
6
6
  author='akimerslys',
7
7
  author_email='akimslys2003@gmail.com',
8
8
  description='Hltv-aio: An unofficial asynchronous HLTV API Wrapper for Python',
File without changes
File without changes