hltv-async-api 0.5.2__tar.gz → 0.6.0__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.
- {hltv_async_api-0.5.2 → hltv_async_api-0.6.0}/PKG-INFO +2 -2
- {hltv_async_api-0.5.2 → hltv_async_api-0.6.0}/README.md +1 -1
- {hltv_async_api-0.5.2 → hltv_async_api-0.6.0}/hltv_async_api/__init__.py +1 -1
- {hltv_async_api-0.5.2 → hltv_async_api-0.6.0}/hltv_async_api/aiohltv.py +54 -50
- {hltv_async_api-0.5.2 → hltv_async_api-0.6.0}/pyproject.toml +1 -1
- hltv_async_api-0.5.2/hltv_async_api/proxies.txt +0 -100
- {hltv_async_api-0.5.2 → hltv_async_api-0.6.0}/LICENSE +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: hltv_async_api
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.6.0
|
|
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
|
|
@@ -203,7 +203,7 @@ pip install hltv-async-api
|
|
|
203
203
|
>>>[{'id': '19230', 'rank': 1, 'name': 'm0NESY', 'team': 'G2', 'maps': '44', 'rating': '1.37'}, {'id': '18053', 'rank': 2, 'name': 'broky', 'team': 'FaZe', 'maps': '54', 'rating': '1.19'}]
|
|
204
204
|
```
|
|
205
205
|
|
|
206
|
-
* **get
|
|
206
|
+
* **get(type: str, id: int | str | None = None, title: str | None = None, team1: str | None = None, team2: str | None = None):**
|
|
207
207
|
(BETA) This method is not finished. Possible types 'events', 'matches', 'teams', also u can add id | title | team1 | team2, to parse more.
|
|
208
208
|
ex.
|
|
209
209
|
|
|
@@ -180,7 +180,7 @@ pip install hltv-async-api
|
|
|
180
180
|
>>>[{'id': '19230', 'rank': 1, 'name': 'm0NESY', 'team': 'G2', 'maps': '44', 'rating': '1.37'}, {'id': '18053', 'rank': 2, 'name': 'broky', 'team': 'FaZe', 'maps': '54', 'rating': '1.19'}]
|
|
181
181
|
```
|
|
182
182
|
|
|
183
|
-
* **get
|
|
183
|
+
* **get(type: str, id: int | str | None = None, title: str | None = None, team1: str | None = None, team2: str | None = None):**
|
|
184
184
|
(BETA) This method is not finished. Possible types 'events', 'matches', 'teams', also u can add id | title | team1 | team2, to parse more.
|
|
185
185
|
ex.
|
|
186
186
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import time
|
|
1
2
|
from typing import Any, List
|
|
2
3
|
from datetime import date, datetime, timedelta
|
|
3
4
|
import pytz
|
|
@@ -18,14 +19,13 @@ import logging
|
|
|
18
19
|
class Hltv:
|
|
19
20
|
def __init__(self, max_delay: int = 15,
|
|
20
21
|
timeout: int = 5,
|
|
21
|
-
use_proxy: bool = False,
|
|
22
22
|
proxy_path: str | None = None,
|
|
23
23
|
proxy_list: list | None = None,
|
|
24
24
|
debug: bool = False,
|
|
25
25
|
max_retries: int = 0,
|
|
26
26
|
proxy_protocol: str | None = None,
|
|
27
27
|
proxy_one_time: bool = False,
|
|
28
|
-
|
|
28
|
+
one_time_session: bool = True,
|
|
29
29
|
):
|
|
30
30
|
self.headers = {
|
|
31
31
|
"referer": "https://www.hltv.org/stats",
|
|
@@ -35,11 +35,12 @@ class Hltv:
|
|
|
35
35
|
self.MAX_DELAY = max_delay
|
|
36
36
|
self.timeout = timeout
|
|
37
37
|
self.max_retries = max_retries
|
|
38
|
-
self.USE_PROXY = use_proxy
|
|
39
38
|
self.PROXY_PATH = proxy_path
|
|
40
39
|
self.PROXY_LIST = proxy_list
|
|
41
40
|
self.PROXY_PROTOCOL = proxy_protocol
|
|
42
41
|
self.PROXY_ONCE = proxy_one_time
|
|
42
|
+
self.ONE_TIME_SESSION = one_time_session
|
|
43
|
+
self.session = None
|
|
43
44
|
self.DEBUG = debug
|
|
44
45
|
self._configure_logging()
|
|
45
46
|
self.logger = logging.getLogger(__name__)
|
|
@@ -48,16 +49,21 @@ class Hltv:
|
|
|
48
49
|
with open(self.PROXY_PATH, "r") as file:
|
|
49
50
|
self.PROXY_LIST = [line.strip() for line in file.readlines()]
|
|
50
51
|
|
|
51
|
-
|
|
52
|
-
|
|
52
|
+
if proxy_path or proxy_list:
|
|
53
|
+
self.USE_PROXY = True
|
|
54
|
+
else:
|
|
55
|
+
self.USE_PROXY = False
|
|
56
|
+
|
|
57
|
+
self._create_session()
|
|
53
58
|
|
|
54
59
|
def _configure_logging(self):
|
|
55
60
|
level = logging.DEBUG if self.DEBUG else logging.INFO
|
|
56
61
|
logging.basicConfig(level=level, format="%(message)s")
|
|
57
62
|
|
|
58
|
-
|
|
59
|
-
self.
|
|
60
|
-
|
|
63
|
+
def _create_session(self):
|
|
64
|
+
if not self.session:
|
|
65
|
+
self.logger.debug('Creating Session')
|
|
66
|
+
self.session = ClientSession()
|
|
61
67
|
|
|
62
68
|
async def close_session(self):
|
|
63
69
|
if self.session:
|
|
@@ -74,7 +80,7 @@ class Hltv:
|
|
|
74
80
|
max_retries: int | None = None,
|
|
75
81
|
proxy_protocol: str | None = None,
|
|
76
82
|
proxy_one_time: bool | None = None,
|
|
77
|
-
|
|
83
|
+
one_time_session: bool | None = None,
|
|
78
84
|
):
|
|
79
85
|
if max_delay:
|
|
80
86
|
self.MAX_DELAY = max_delay
|
|
@@ -90,8 +96,8 @@ class Hltv:
|
|
|
90
96
|
self.PROXY_PROTOCOL = proxy_protocol
|
|
91
97
|
if proxy_one_time is not None:
|
|
92
98
|
self.PROXY_ONCE = proxy_one_time
|
|
93
|
-
if
|
|
94
|
-
self.
|
|
99
|
+
if one_time_session is not None:
|
|
100
|
+
self.ONE_TIME_SESSION = one_time_session
|
|
95
101
|
if debug is not None:
|
|
96
102
|
self.DEBUG = debug
|
|
97
103
|
self._configure_logging()
|
|
@@ -99,7 +105,7 @@ class Hltv:
|
|
|
99
105
|
with open(self.PROXY_PATH, "r") as file:
|
|
100
106
|
self.PROXY_LIST = [line.strip() for line in file.readlines()]
|
|
101
107
|
|
|
102
|
-
|
|
108
|
+
def _get_proxy(self):
|
|
103
109
|
proxy = self.PROXY_LIST[0]
|
|
104
110
|
|
|
105
111
|
if self.PROXY_PROTOCOL and proxy != '' and self.PROXY_PROTOCOL not in proxy:
|
|
@@ -107,7 +113,7 @@ class Hltv:
|
|
|
107
113
|
|
|
108
114
|
return proxy
|
|
109
115
|
|
|
110
|
-
|
|
116
|
+
def _switch_proxy(self):
|
|
111
117
|
if self.PROXY_ONCE:
|
|
112
118
|
self.logger.debug(f'Removing proxy {self.PROXY_LIST[0]}')
|
|
113
119
|
self.PROXY_LIST = self.PROXY_LIST[1:]
|
|
@@ -129,9 +135,9 @@ class Hltv:
|
|
|
129
135
|
return True
|
|
130
136
|
return False
|
|
131
137
|
|
|
132
|
-
|
|
138
|
+
def _parse_error_handler(self, delay: int = 0) -> int:
|
|
133
139
|
if self.USE_PROXY:
|
|
134
|
-
|
|
140
|
+
self._switch_proxy()
|
|
135
141
|
else:
|
|
136
142
|
if delay < self.MAX_DELAY:
|
|
137
143
|
delay += 1
|
|
@@ -145,7 +151,7 @@ class Hltv:
|
|
|
145
151
|
proxy = ''
|
|
146
152
|
# setup new proxy, cuz old one was switched
|
|
147
153
|
if self.USE_PROXY:
|
|
148
|
-
proxy =
|
|
154
|
+
proxy = self._get_proxy()
|
|
149
155
|
else:
|
|
150
156
|
# delay, only for non proxy users. (default = 1-15s)
|
|
151
157
|
await asyncio.sleep(delay)
|
|
@@ -154,24 +160,25 @@ class Hltv:
|
|
|
154
160
|
self.logger.info(f"Fetching {url}, code: {response.status}")
|
|
155
161
|
if response.status == 403 or response.status == 404:
|
|
156
162
|
self.logger.debug("Got 403 forbitten")
|
|
157
|
-
return False,
|
|
163
|
+
return False, self._parse_error_handler(delay)
|
|
158
164
|
|
|
159
165
|
# checking for challenge page.
|
|
160
166
|
result = await response.text()
|
|
161
167
|
if await self._cloudflare_check(result):
|
|
162
|
-
return False,
|
|
168
|
+
return False, self._parse_error_handler(delay)
|
|
163
169
|
|
|
164
170
|
return True, result
|
|
165
171
|
except (ClientProxyConnectionError, ClientResponseError, ClientOSError,
|
|
166
172
|
ServerDisconnectedError, TimeoutError, ClientHttpProxyError) as e:
|
|
167
173
|
self.logger.debug(e)
|
|
168
|
-
delay =
|
|
174
|
+
delay = self._parse_error_handler(delay)
|
|
175
|
+
return False, delay
|
|
176
|
+
except ClientTimeout:
|
|
169
177
|
return False, delay
|
|
170
178
|
|
|
171
179
|
async def _fetch(self, url, delay: int = 0):
|
|
172
180
|
if not self.session:
|
|
173
|
-
|
|
174
|
-
|
|
181
|
+
self._create_session()
|
|
175
182
|
status = False
|
|
176
183
|
try_ = 1
|
|
177
184
|
result = None
|
|
@@ -188,11 +195,8 @@ class Hltv:
|
|
|
188
195
|
delay = result
|
|
189
196
|
try_ += 1
|
|
190
197
|
|
|
191
|
-
|
|
192
|
-
if not self.TRUE_SESSION:
|
|
193
|
-
# Automatically close session after parse
|
|
198
|
+
if not self.ONE_TIME_SESSION:
|
|
194
199
|
await self.close_session()
|
|
195
|
-
|
|
196
200
|
if status:
|
|
197
201
|
loop = get_running_loop()
|
|
198
202
|
parsed = await loop.run_in_executor(None, partial(self._f, result))
|
|
@@ -245,7 +249,8 @@ class Hltv:
|
|
|
245
249
|
async def get_matches(self, days: int = 1, min_rating: int = 1, live: bool = True, future: bool = True):
|
|
246
250
|
"""returns a list of all upcoming matches on HLTV"""
|
|
247
251
|
r = await self._fetch("https://www.hltv.org/matches")
|
|
248
|
-
if not r:
|
|
252
|
+
if not r:
|
|
253
|
+
return
|
|
249
254
|
|
|
250
255
|
matches = []
|
|
251
256
|
|
|
@@ -337,6 +342,7 @@ class Hltv:
|
|
|
337
342
|
|
|
338
343
|
except AttributeError:
|
|
339
344
|
return None
|
|
345
|
+
|
|
340
346
|
return matches
|
|
341
347
|
|
|
342
348
|
async def get_match_info(self, match_id: str | int, team1: str, team2: str, event_title: str, stats: bool = True):
|
|
@@ -439,13 +445,13 @@ class Hltv:
|
|
|
439
445
|
s_t2 = scores[1].strip()
|
|
440
446
|
|
|
441
447
|
results.append({
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
448
|
+
'id': match_id,
|
|
449
|
+
'team1': team1,
|
|
450
|
+
'team2': team2,
|
|
451
|
+
'score1': s_t1,
|
|
452
|
+
'score2': s_t2,
|
|
453
|
+
'rating': rating,
|
|
454
|
+
'event': event,
|
|
449
455
|
})
|
|
450
456
|
|
|
451
457
|
if regular:
|
|
@@ -481,14 +487,14 @@ class Hltv:
|
|
|
481
487
|
s_t2 = scores[1].strip()
|
|
482
488
|
|
|
483
489
|
results.append({
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
490
|
+
'id': match_id,
|
|
491
|
+
'date': date_,
|
|
492
|
+
'team1': team1,
|
|
493
|
+
'team2': team2,
|
|
494
|
+
'score1': s_t1,
|
|
495
|
+
'score2': s_t2,
|
|
496
|
+
'rating': rating,
|
|
497
|
+
'event': event,
|
|
492
498
|
})
|
|
493
499
|
|
|
494
500
|
n += 1
|
|
@@ -503,7 +509,8 @@ class Hltv:
|
|
|
503
509
|
match_results = []
|
|
504
510
|
|
|
505
511
|
n = 0
|
|
506
|
-
for i, result in enumerate(
|
|
512
|
+
for i, result in enumerate(
|
|
513
|
+
r.find("div", {'class', 'results-holder'}).find_all("div", {'class', 'results-sublist'}), start=1):
|
|
507
514
|
if i > days or n > max_:
|
|
508
515
|
break
|
|
509
516
|
date = self.__normalize_date(result.find("span", class_="standard-headline").text.strip())
|
|
@@ -944,12 +951,9 @@ class Hltv:
|
|
|
944
951
|
return news
|
|
945
952
|
|
|
946
953
|
|
|
947
|
-
async def
|
|
948
|
-
hltv = Hltv(
|
|
949
|
-
print(await hltv.
|
|
950
|
-
|
|
951
|
-
await hltv.close_session()
|
|
952
|
-
|
|
954
|
+
async def main():
|
|
955
|
+
hltv = Hltv()
|
|
956
|
+
print(await hltv.get_matches())
|
|
953
957
|
|
|
954
|
-
if __name__ ==
|
|
955
|
-
asyncio.run(
|
|
958
|
+
if __name__ == '__main__':
|
|
959
|
+
asyncio.run(main())
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
38.162.21.116:3128
|
|
2
|
-
38.162.22.227:3128
|
|
3
|
-
38.162.12.213:3128
|
|
4
|
-
38.162.21.1:3128
|
|
5
|
-
38.162.11.39:3128
|
|
6
|
-
38.162.23.154:3128
|
|
7
|
-
154.6.98.200:3128
|
|
8
|
-
154.6.98.201:3128
|
|
9
|
-
38.162.5.118:3128
|
|
10
|
-
38.162.21.62:3128
|
|
11
|
-
89.213.228.107:3128
|
|
12
|
-
38.162.29.203:3128
|
|
13
|
-
38.162.18.109:3128
|
|
14
|
-
38.162.12.104:3128
|
|
15
|
-
154.6.98.100:3128
|
|
16
|
-
154.6.99.1:3128
|
|
17
|
-
89.213.229.51:3128
|
|
18
|
-
38.162.13.123:3128
|
|
19
|
-
38.162.6.240:3128
|
|
20
|
-
38.162.15.7:3128
|
|
21
|
-
154.6.97.37:3128
|
|
22
|
-
38.162.11.214:3128
|
|
23
|
-
38.162.23.151:3128
|
|
24
|
-
38.162.26.58:3128
|
|
25
|
-
38.162.5.30:3128
|
|
26
|
-
38.162.4.117:3128
|
|
27
|
-
154.6.97.252:3128
|
|
28
|
-
38.162.24.83:3128
|
|
29
|
-
38.162.27.155:3128
|
|
30
|
-
38.162.11.249:3128
|
|
31
|
-
38.162.12.33:3128
|
|
32
|
-
38.162.20.110:3128
|
|
33
|
-
38.162.29.69:3128
|
|
34
|
-
89.213.230.8:3128
|
|
35
|
-
38.162.21.3:3128
|
|
36
|
-
89.213.228.254:3128
|
|
37
|
-
38.162.5.63:3128
|
|
38
|
-
38.162.4.180:3128
|
|
39
|
-
38.162.22.30:3128
|
|
40
|
-
38.162.0.158:3128
|
|
41
|
-
38.162.27.12:3128
|
|
42
|
-
89.213.229.33:3128
|
|
43
|
-
89.213.230.79:3128
|
|
44
|
-
38.162.11.130:3128
|
|
45
|
-
38.162.28.9:3128
|
|
46
|
-
89.213.231.107:3128
|
|
47
|
-
38.162.28.146:3128
|
|
48
|
-
38.162.5.177:3128
|
|
49
|
-
38.162.14.243:3128
|
|
50
|
-
154.6.99.135:3128
|
|
51
|
-
38.162.6.189:3128
|
|
52
|
-
89.213.230.64:3128
|
|
53
|
-
38.162.16.12:3128
|
|
54
|
-
38.162.24.158:3128
|
|
55
|
-
154.6.99.99:3128
|
|
56
|
-
38.162.2.218:3128
|
|
57
|
-
38.162.14.99:3128
|
|
58
|
-
38.162.31.114:3128
|
|
59
|
-
38.162.29.170:3128
|
|
60
|
-
38.162.27.133:3128
|
|
61
|
-
38.162.16.149:3128
|
|
62
|
-
154.6.99.93:3128
|
|
63
|
-
38.162.29.159:3128
|
|
64
|
-
38.162.17.57:3128
|
|
65
|
-
38.162.27.74:3128
|
|
66
|
-
38.162.23.74:3128
|
|
67
|
-
38.162.21.216:3128
|
|
68
|
-
38.162.4.225:3128
|
|
69
|
-
154.6.99.158:3128
|
|
70
|
-
38.162.17.188:3128
|
|
71
|
-
38.162.22.103:3128
|
|
72
|
-
38.162.5.61:3128
|
|
73
|
-
154.6.97.8:3128
|
|
74
|
-
38.162.19.250:3128
|
|
75
|
-
154.6.98.68:3128
|
|
76
|
-
38.162.13.135:3128
|
|
77
|
-
38.162.14.159:3128
|
|
78
|
-
38.162.30.46:3128
|
|
79
|
-
38.162.19.144:3128
|
|
80
|
-
38.162.15.243:3128
|
|
81
|
-
38.162.24.32:3128
|
|
82
|
-
38.162.27.182:3128
|
|
83
|
-
38.162.7.214:3128
|
|
84
|
-
38.162.5.146:3128
|
|
85
|
-
154.6.96.129:3128
|
|
86
|
-
38.162.27.119:3128
|
|
87
|
-
38.162.27.134:3128
|
|
88
|
-
38.162.30.14:3128
|
|
89
|
-
38.162.24.60:3128
|
|
90
|
-
89.213.231.145:3128
|
|
91
|
-
38.162.3.126:3128
|
|
92
|
-
89.213.229.124:3128
|
|
93
|
-
38.162.23.224:3128
|
|
94
|
-
154.6.98.98:3128
|
|
95
|
-
38.162.1.238:3128
|
|
96
|
-
154.6.97.218:3128
|
|
97
|
-
89.213.229.97:3128
|
|
98
|
-
38.162.3.161:3128
|
|
99
|
-
38.162.13.166:3128
|
|
100
|
-
38.162.11.227:3128
|
|
File without changes
|