hltv-async-api 0.4.1__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.
@@ -0,0 +1,391 @@
1
+ Metadata-Version: 2.1
2
+ Name: hltv_async_api
3
+ Version: 0.4.3
4
+ Summary: Hltv-aio An unofficial asynchronous HLTV API Wrapper for Python
5
+ Home-page: https://github.com/akimerslys/aiohltv
6
+ Author: akimerslys
7
+ Author-email: Akim Slys <akimslys2003@gmail.com>
8
+ Project-URL: Homepage, https://github.com/akimerslys/aiohltv
9
+ Project-URL: Issues, https://github.com/akimerslys/aiohltv/issues
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: OS Independent
13
+ Requires-Python: >=3.9
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+
17
+ # hltv-async-api an unofficial asynchronous HLTV API Wrapper for Python
18
+
19
+
20
+ **This page not completed, not all methods and configs are written**
21
+
22
+
23
+ # Features
24
+
25
+
26
+ * **Simple Usage** (its realy simple)
27
+
28
+
29
+ * **New and modern fully async library**
30
+
31
+
32
+ * **Huge amount of options**
33
+
34
+
35
+ * **Supports proxy usage**
36
+
37
+
38
+ * **Made with love <3**
39
+
40
+
41
+ ---
42
+
43
+ # Installation
44
+
45
+ ```
46
+ pip install hltv-async-api
47
+ ```
48
+
49
+ ---
50
+
51
+
52
+ # Simple Usage
53
+
54
+ ```
55
+ from hltv_async_api import Hltv
56
+
57
+ hltv = Hltv()
58
+ live_matches = await hltv.get_live_matches()
59
+ ```
60
+
61
+ ---
62
+
63
+ # Proxy Usage
64
+
65
+ **Load Proxies from list**
66
+
67
+ ```
68
+ proxy_list = ['http://120.234.203.171:9002', 'http://110.38.68.38:80']
69
+
70
+ hltv = Hltv(use_proxy=True, proxy_list=proxy_list)
71
+ ```
72
+
73
+ **Load Proxies from file**
74
+
75
+ ```
76
+ hltv = Hltv(use_proxy=True, proxy_path='PATH_TO_PROXY.TXT')
77
+ ```
78
+
79
+
80
+ **One-time proxy**
81
+
82
+ ```
83
+ hltv = Hltv(use_proxy=True, proxy_path='PATH_TO_PROXY.TXT', proxy_one_time=True)
84
+ ```
85
+
86
+ **Protocol usage**
87
+
88
+ ```
89
+ proxy_list = ['120.234.203.171:9002', '110.38.68.38:80']
90
+
91
+ hltv = Hltv(use_proxy=True, proxy_list=proxy_list, proxy_protocol='http')
92
+ ```
93
+
94
+ ---
95
+ # Methods
96
+
97
+ * **get_upcoming_matches(days: int = 7, min_star_rating: int = 1)**
98
+
99
+ -days (the number of days into the future to fetch matches for)
100
+
101
+ -min_star_rating (the minimum star rating for matches to include)
102
+
103
+ ```
104
+ await hltv.get_upcoming_matches(1, 5)
105
+
106
+ >>> ['date': '11-11', 'matches': [id: '1111', team1: 'Natus Vincere' | 'TBD', team2: 'FaZe' | 'TBD', time: '14:15', maps: '3', stars: 5, 'PGL CS2 Major Copenhagen 2024' | None]]```
107
+
108
+ ```
109
+ * **get_events(outgoing=True, future=True, max_events=10) -> [('id', 'title', 'startdate', 'enddate')]**
110
+
111
+ ```
112
+ await hltv.get_events(future=False)
113
+
114
+ >>>{'id': '7437', 'name': 'IEM Chengdu 2024', 'start_date': '8-4', 'end_date': '14-4'}, {'id': '7757', 'name': 'BetBoom Dacha Belgrade 2024 Europe Closed Qualifier', 'start_date': '2-4', 'end_date': '12-4'}]
115
+
116
+ ```
117
+
118
+ * **get_event_results(event_id: int | str)**
119
+
120
+
121
+ ```
122
+ await get_event_results(7148)
123
+
124
+ >>> ['date': '31-3', 'matches': ['id': '1111', team1': 'FaZe', 'team2': 'Natus Vincere', 'score1': '1', 'score2': '2']]
125
+
126
+ ```
127
+
128
+ * **get_event_matches(event_id: str | int):**
129
+
130
+ ```
131
+ await hltv.get_event_matches(7148)
132
+
133
+ >>>[{'date': 'LIVE', 'matches': [{'id': '2371135', 'team1': 'GUN5', 'team2': 'KOI', 't1_id': '12471', 't2_id': '12591'}]}, {'date': '2024-04-08', 'matches': [{'id': '2371131', 'time': '20:00', 'team1': 'Aurora', 'team2': 'Metizport', 't1_id': '11861', 't2_id': '11641'}]}]
134
+ ```
135
+
136
+ * **get_event_info(event_id: str | int, event_title: str) -> (event_id, event_title, event_start, event_end, prize, team_num, location, groups)**
137
+
138
+ ```
139
+ await hltv.get_event_info(7148, 'PGL CS2 Major Copenhagen2024')
140
+
141
+ (7148, 'PGL CS2 Major Copenhagen2024', '21-3', '31-3', '$1,250,000', '16', 'Copenhagen, Denmark', [])
142
+ ```
143
+
144
+
145
+ * **get_top_teams(max_teams=30) -> ['rank', 'title', 'points', 'change', 'id']**
146
+
147
+ ```
148
+ await hltv.get_top_teams(2)
149
+
150
+ >>>[{'id': '1111', 'rank': '1', 'title': 'FaZe', 'points': '939', 'change': '-', 'id': '6667'}, {'id': '1111', 'rank': '2', 'title': 'Natus Vincere', 'points': '757', 'change': '+4', 'id': '4608'}]
151
+ ```
152
+
153
+ * **get_team_info(team_id: int | str, title: str) -> (team_id, team_title, rank, [players], coach, average_age, weeks_in_top_20, last_trophy, total_trophys)**
154
+
155
+ ```
156
+ await hltv.get_team_info(6667, 'faze')
157
+
158
+ >>>(6667, 'faze', '1', ['karrigan', 'rain', 'frozen', 'ropz', 'broky'], 'NEO', '26.5', '256', 'CS Asia Championships 2023', 21)
159
+ ```
160
+
161
+ * **get_last_news(max_reg_news=2, only_today=True, only_featured=False) -> [date, [featured_id, featured_title, featured_desciption], [regular_id, reg_title, reg_time]]**
162
+
163
+ ```
164
+ await hltv.get_last_news(only_today=True, max_reg_news=1)
165
+
166
+ >>>[{'date': '02-04', 'f_news': [{'f_id': '38682', 'f_title': 'NIP confirm r1nkle signing', 'f_desc': "Ninjas in Pyjamas only have an anchor player left to sign following the young Ukrainian AWPer's addition."}], 'news': [{'id': '38685', 'title': 'Rounds add sLowi, p3kko', 'posted': 'an hour ago'}, {'id': '38690', 'title': 'n1ssim returns to Sharks after paiN loan deal expires', 'posted': 'an hour ago'}]}]
167
+ ```
168
+
169
+ * **get_best_players(top=40) -> ('rank', 'name', 'team', 'maps', 'rating')**
170
+
171
+ ```
172
+ await hltv.get_best_players(2)
173
+
174
+ >>>[{'rank': 1, 'name': 'donk', 'team': 'Spirit', 'maps': '33', 'rating': '1.52'}, {'rank': 2, 'name': 'm0NESY', 'team': 'G2', 'maps': '34', 'rating': '1.38'}]
175
+ ```
176
+
177
+ ---
178
+ # Configs
179
+
180
+ * max_delay: int = 15
181
+
182
+ We automaticly increasing reconnecting delay by 1 sec to max_delay (from 1s to 5s)
183
+
184
+ ```
185
+ hltv = Hltv(max_delay=5, use_proxy=False)
186
+
187
+ >>>Fetching https://www.hltv.org/matches/2370727/faze-vs-natus-vincere-pgl-cs2-major-copenhagen-2024, code: 403
188
+ >>>Got 403 forbitten
189
+ >>>Calling again, increasing delay to 4s
190
+ >>>Fetching https://www.hltv.org/matches/2370727/faze-vs-natus-vincere-pgl-cs2-major-copenhagen-2024, code: 403
191
+ >>>Got 403 forbitten
192
+ >>>Calling again, increasing delay to 5s
193
+ ```
194
+
195
+ * max_retries: int = 0
196
+
197
+ Max retries. 0 or -1 for infinity tries.
198
+
199
+ ```
200
+ hltv = Hltv(max_retries=2, debug=True)
201
+ print(await hltv.get_best_players())
202
+
203
+ Creating Session
204
+ Trying connect to https://www.hltv.org/stats/players?startDate=2024-01-01&endDate=2024-12-31&rankingFilter=Top20, try 1/2
205
+ Trying connect to https://www.hltv.org/stats/players?startDate=2024-01-01&endDate=2024-12-31&rankingFilter=Top20, try 2/2
206
+ Connection failed
207
+ ```
208
+
209
+ * use_proxy: bool = False
210
+
211
+ Proxy Usage. No compatibility with max_delay (max_delay will be ignored)
212
+
213
+ * proxy_list: list | None = None
214
+
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
217
+
218
+ * proxy_path: str | None = None
219
+
220
+ Path to your proxy (proxy_list will be ignored). If your proxies doesnt have any protocol you can use proxy_protocol
221
+
222
+ * proxy_protocol: str | None = None,
223
+
224
+ Proxy protocol. Your proxies ```hltv = Hltv(proxy_protocol='http' ...) -> '11.11.11.11:1111' -> 'http://11.11.11.11:1111'
225
+
226
+ * proxy_one_time: bool = False
227
+
228
+ Removes proxy from list (proxy_path included) if connection unsuccessfull
229
+
230
+ * timeout: int = 5
231
+
232
+ Max time to close connection. Recommended to use timeout=1 if you are using random proxies.
233
+
234
+ * debug: bool = False
235
+
236
+ More loggs
237
+
238
+ * true_session=False
239
+
240
+ **(BETA)**
241
+ This parser automaticaly creating and clossing session after every call, if you want to let your session open even when parser is inactive
242
+ use this method. **!! IMPORTANT YOU SHOULD CLOSE YOUR SESSION BEFORE KILLING PROGRAM**
243
+
244
+ ```
245
+ async def test():
246
+ hltv = Hltv(true_session=True)
247
+ print(await hltv.get_best_players())
248
+ print(await hltv.get_upcoming_matches())
249
+ await hltv.close_session()
250
+
251
+ if __name__ == "__main__":
252
+ asyncio.run(test())
253
+ ```
254
+
255
+ ---
256
+ # Examples
257
+
258
+ ****Simple Example****
259
+
260
+ ```
261
+ from hltv_async_api import Hltv
262
+
263
+
264
+ async def test():
265
+
266
+ hltv = Hltv()
267
+
268
+ print(await hltv.get_event_info(7148, 'pgl-cs2-major-copenhagen-2024'))
269
+
270
+ if __name__ == "__main__":
271
+ asyncio.run(test())
272
+ ```
273
+
274
+ ****Proxy Parser****
275
+
276
+ ```
277
+ from hltv_async_api import Hltv
278
+
279
+
280
+ async def test():
281
+
282
+ hltv = Hltv(debug=True, use_proxy=True, proxy_path='proxy_test.txt', timeout=1, proxy_one_time=True, proxy_protocol='http')
283
+
284
+ print(await hltv.get_event_info(7148, 'pgl-cs2-major-copenhagen-2024'))
285
+
286
+ if __name__ == "__main__":
287
+ asyncio.run(test())
288
+ ```
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
+ ```
385
+
386
+ # Requirements:
387
+
388
+ Python 3.9+
389
+
390
+ License:
391
+ HLTV Async is licensed under the MIT License, allowing for personal and commercial use with minimal restrictions.