hltv-async-api 0.2.8__tar.gz → 0.3.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: hltv_async_api
3
- Version: 0.2.8
3
+ Version: 0.3.0
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
@@ -6,4 +6,4 @@
6
6
  from .aiohltv import Hltv
7
7
 
8
8
  __author__ = 'akimerslys'
9
- __version__ = '0.2.8'
9
+ __version__ = '0.2.8b'
@@ -42,6 +42,10 @@ class Hltv:
42
42
  self._configure_logging()
43
43
  self.logger = logging.getLogger(__name__)
44
44
 
45
+ if self.PROXY_PATH:
46
+ with open(self.PROXY_PATH, "r") as file:
47
+ self.PROXY_LIST = [line.strip() for line in file.readlines()]
48
+
45
49
  def _configure_logging(self):
46
50
  level = logging.DEBUG if self.DEBUG else logging.INFO
47
51
  logging.basicConfig(level=level, format="%(message)s")
@@ -62,8 +66,6 @@ class Hltv:
62
66
  self.timeout = timeout
63
67
  if use_proxy:
64
68
  self.USE_PROXY = use_proxy
65
- if proxy_file_path:
66
- self.PROXY_PATH = proxy_file_path
67
69
  if proxy_list:
68
70
  self.PROXY_LIST = proxy_list
69
71
  if max_retries:
@@ -75,37 +77,26 @@ class Hltv:
75
77
  if debug:
76
78
  self.DEBUG = debug
77
79
  self._configure_logging()
80
+ if proxy_file_path:
81
+ with open(self.PROXY_PATH, "r") as file:
82
+ self.PROXY_LIST = [line.strip() for line in file.readlines()]
78
83
 
79
84
  async def get_proxy(self):
80
- proxy = ''
81
- if self.PROXY_PATH:
82
- async with aiofiles.open(self.PROXY_PATH, "r") as file:
83
- new_proxy = await file.readline().strip()
84
- if new_proxy:
85
- proxy = new_proxy
86
-
87
- else:
88
- proxy = self.PROXY_LIST[0]
85
+ proxy = self.PROXY_LIST[0]
89
86
 
90
87
  if self.PROXY_PROTOCOL and proxy != '' and self.PROXY_PROTOCOL not in proxy:
91
88
  proxy = self.PROXY_PROTOCOL + '://' + proxy
92
89
 
93
90
  return proxy
94
91
 
95
- async def switch_proxy(self, proxy):
96
- if self.PROXY_PATH:
97
- if self.PROXY_PROTOCOL:
98
- proxy = proxy.replace(self.PROXY_PROTOCOL + '://', '')
99
- async with aiofiles.open(self.PROXY_PATH, "r+") as file:
100
- proxies = await file.readlines()
101
- await file.seek(0)
102
- for line in proxies:
103
- if line.strip() != proxy:
104
- await file.write(line)
105
- if not self.REMOVE_PROXY:
106
- await file.write(proxy + "\n")
92
+ async def switch_proxy(self):
93
+ if self.REMOVE_PROXY:
94
+ self.logger.debug(f'Removing proxy {self.PROXY_LIST[0]}')
95
+ self.PROXY_LIST = self.PROXY_LIST[1:]
107
96
  else:
108
- self.PROXY_LIST = self.PROXY_LIST[1:] + [self.PROXY_LIST[0]]
97
+ self.logger.debug(f"Switching proxy {self.PROXY_LIST[0]}")
98
+ self.PROXY_LIST = self.PROXY_LIST[1:] + self.PROXY_LIST[0]
99
+ self.logger.info(f"New proxy: {self.PROXY_LIST[0]}")
109
100
 
110
101
  def f(self, result):
111
102
  return BeautifulSoup(result, "lxml")
@@ -121,9 +112,7 @@ class Hltv:
121
112
 
122
113
  async def parse_error_handler(self, proxy, delay: int = 0) -> int:
123
114
  if self.USE_PROXY:
124
- self.logger.debug(f"Switching proxy {proxy}")
125
- await self.switch_proxy(proxy)
126
- self.logger.info(f"New proxy: {await self.get_proxy()}")
115
+ await self.switch_proxy()
127
116
  else:
128
117
  if delay < self.MAX_DELAY:
129
118
  delay += 1
@@ -689,7 +678,7 @@ class Hltv:
689
678
 
690
679
 
691
680
  async def test():
692
- hltv = Hltv()
681
+ hltv = Hltv(use_proxy=True, proxy_path='proxies.txt', debug=True, remove_proxy=True, proxy_protocol='http')
693
682
  print(await hltv.get_last_news(only_today=True, max_reg_news=1))
694
683
 
695
684
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: hltv_async_api
3
- Version: 0.2.8
3
+ Version: 0.3.0
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
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "hltv_async_api"
3
- version = "0.2.8"
3
+ version = "0.3.0"
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.2.8',
5
+ version='0.3.0',
6
6
  author='akimerslys',
7
7
  author_email='akimslys2003@gmail.com',
8
8
  description='Hltv-aio: An unofficial asynchronous HLTV API Wrapper for Python',
@@ -14,6 +14,7 @@ setup(
14
14
  install_requires=[
15
15
  'aiohttp==3.9.3',
16
16
  'aiosignal==1.3.1',
17
+ 'aiofiles==23.2.1',
17
18
  'attrs==23.2.0',
18
19
  'beautifulsoup4==4.12.3',
19
20
  'frozenlist==1.4.1',
File without changes
File without changes
File without changes