pars-hitmotop 1.0.3__tar.gz → 1.0.4__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.
Files changed (24) hide show
  1. {pars_hitmotop-1.0.3 → pars_hitmotop-1.0.4}/PKG-INFO +2 -2
  2. {pars_hitmotop-1.0.3 → pars_hitmotop-1.0.4}/pars_hitmotop.egg-info/PKG-INFO +2 -2
  3. {pars_hitmotop-1.0.3 → pars_hitmotop-1.0.4}/pars_hitmotop.egg-info/SOURCES.txt +8 -1
  4. pars_hitmotop-1.0.4/pars_hitmotop.egg-info/top_level.txt +3 -0
  5. pars_hitmotop-1.0.4/parse_hitmos/config/__init__.py +0 -0
  6. pars_hitmotop-1.0.4/parse_hitmos/config/load_data.py +37 -0
  7. {pars_hitmotop-1.0.3 → pars_hitmotop-1.0.4}/parse_hitmos/rating_tracks_count.py +1 -0
  8. pars_hitmotop-1.0.4/parse_hitmos/tools/__init__.py +0 -0
  9. pars_hitmotop-1.0.4/parse_hitmos/tools/base_session.py +111 -0
  10. pars_hitmotop-1.0.4/parse_hitmos/tools/headers.py +23 -0
  11. pars_hitmotop-1.0.4/parse_hitmos/tools/replace_symbol.py +11 -0
  12. pars_hitmotop-1.0.4/parse_hitmos/tools/retry_func.py +56 -0
  13. {pars_hitmotop-1.0.3 → pars_hitmotop-1.0.4}/setup.py +2 -2
  14. pars_hitmotop-1.0.3/pars_hitmotop.egg-info/top_level.txt +0 -1
  15. {pars_hitmotop-1.0.3 → pars_hitmotop-1.0.4}/LICENSE +0 -0
  16. {pars_hitmotop-1.0.3 → pars_hitmotop-1.0.4}/README.md +0 -0
  17. {pars_hitmotop-1.0.3 → pars_hitmotop-1.0.4}/pars_hitmotop.egg-info/dependency_links.txt +0 -0
  18. {pars_hitmotop-1.0.3 → pars_hitmotop-1.0.4}/pars_hitmotop.egg-info/requires.txt +0 -0
  19. {pars_hitmotop-1.0.3 → pars_hitmotop-1.0.4}/parse_hitmos/__init__.py +0 -0
  20. {pars_hitmotop-1.0.3 → pars_hitmotop-1.0.4}/parse_hitmos/entered_tracks.py +0 -0
  21. {pars_hitmotop-1.0.3 → pars_hitmotop-1.0.4}/parse_hitmos/excepts.py +0 -0
  22. {pars_hitmotop-1.0.3 → pars_hitmotop-1.0.4}/parse_hitmos/how_to_use.py +0 -0
  23. {pars_hitmotop-1.0.3 → pars_hitmotop-1.0.4}/parse_hitmos/rating_tracks_page.py +0 -0
  24. {pars_hitmotop-1.0.3 → pars_hitmotop-1.0.4}/setup.cfg +0 -0
@@ -1,8 +1,8 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pars_hitmotop
3
- Version: 1.0.3
3
+ Version: 1.0.4
4
4
  Home-page: https://github.com/JoyHubN/pars_hitmos
5
- Download-URL: https://github.com/JoyHubN/pars_hitmos/arhive/v1.0.3.zip
5
+ Download-URL: https://github.com/JoyHubN/pars_hitmos/arhive/v1.0.4.zip
6
6
  Author: JoyHubN
7
7
  Author-email: Prufu@yandex.ru
8
8
  Classifier: Programming Language :: Python
@@ -1,8 +1,8 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pars_hitmotop
3
- Version: 1.0.3
3
+ Version: 1.0.4
4
4
  Home-page: https://github.com/JoyHubN/pars_hitmos
5
- Download-URL: https://github.com/JoyHubN/pars_hitmos/arhive/v1.0.3.zip
5
+ Download-URL: https://github.com/JoyHubN/pars_hitmos/arhive/v1.0.4.zip
6
6
  Author: JoyHubN
7
7
  Author-email: Prufu@yandex.ru
8
8
  Classifier: Programming Language :: Python
@@ -11,4 +11,11 @@ parse_hitmos/entered_tracks.py
11
11
  parse_hitmos/excepts.py
12
12
  parse_hitmos/how_to_use.py
13
13
  parse_hitmos/rating_tracks_count.py
14
- parse_hitmos/rating_tracks_page.py
14
+ parse_hitmos/rating_tracks_page.py
15
+ parse_hitmos/config/__init__.py
16
+ parse_hitmos/config/load_data.py
17
+ parse_hitmos/tools/__init__.py
18
+ parse_hitmos/tools/base_session.py
19
+ parse_hitmos/tools/headers.py
20
+ parse_hitmos/tools/replace_symbol.py
21
+ parse_hitmos/tools/retry_func.py
@@ -0,0 +1,3 @@
1
+ parse_hitmos
2
+ parse_hitmos/config
3
+ parse_hitmos/tools
File without changes
@@ -0,0 +1,37 @@
1
+ import json
2
+ import os.path
3
+
4
+ class SID:
5
+ def __init__(self):
6
+ self.sid = None
7
+ self.path = os.path.join(os.path.dirname(__file__), 'data.json')
8
+ print(self.path)
9
+ self.__load_sid()
10
+
11
+ def __load_sid(self):
12
+ if not self.sid:
13
+ if not os.path.exists(self.path):
14
+ with open(self.path, encoding='utf-8', mode='w') as data:
15
+ json.dump({'sid': ''}, data, indent=4)
16
+
17
+ with open(self.path, 'r', encoding='utf-8') as f:
18
+ self.sid = json.load(f)['sid']
19
+
20
+ def get_sid(self):
21
+ return self.sid
22
+
23
+ def __load_config(self):
24
+ with open(self.path, 'r', encoding='utf-8') as f:
25
+ return json.load(f)
26
+
27
+ def write_sid(self, sid):
28
+ data = self.__update_sid(sid)
29
+ with open(self.path, 'w', encoding='utf-8') as f:
30
+ json.dump(data, f, indent=4)
31
+
32
+ def __update_sid(self, sid):
33
+ data = self.__load_config()
34
+ self.sid = sid['sid']
35
+ data['sid']=sid['sid']
36
+ return json.loads(json.dumps(data, indent=4))
37
+
@@ -75,6 +75,7 @@ class RatingCount(BaseSessionHandlerRating):
75
75
  self.session.close()
76
76
  self.data = {"items": _items}
77
77
  return self.data
78
+
78
79
  @property
79
80
  def get_author(self) -> list[str]:
80
81
  return [item['author'] for item in self.data['items']]
File without changes
@@ -0,0 +1,111 @@
1
+ import requests
2
+ from urllib.parse import urljoin
3
+ from requests.exceptions import ReadTimeout
4
+
5
+ from parse_hitmos.excepts import MaxAttempts
6
+ from parse_hitmos.config.load_data import SID
7
+ from parse_hitmos.tools.headers import get_headers
8
+ from parse_hitmos.tools.retry_func import safe_get_main_url
9
+
10
+ class BaseSessionHandlerRating:
11
+ def __init__(self):
12
+ self.__attempt = 0
13
+ self.max_attempt = 10
14
+ self.session = None
15
+ self.sid = SID()
16
+ self.base_url = ''
17
+ self.song_rated = ''
18
+ self.create_session()
19
+
20
+ def create_session(self):
21
+
22
+ __headers = get_headers()
23
+ cookies = {'sid': self.sid.get_sid()}
24
+
25
+ self.session = requests.Session()
26
+ response = safe_get_main_url(self, 'https://hitmos.me', headers=__headers, cookies=cookies, timeout=5)
27
+
28
+ if response.status_code == 403:
29
+ response = self.session.get('https://hitmos.me/', cookies={'sid':self.sid.get_sid()}, headers=__headers, allow_redirects=True)
30
+ self.sid.write_sid(self.session.cookies.get_dict())
31
+
32
+ self.base_url = response.url
33
+ self.song_rated = urljoin(response.url, 'songs/top-rated')
34
+
35
+
36
+
37
+ class BaseSessionHandlerRatingPage:
38
+ def __init__(self):
39
+ self.__attempt = 0
40
+ self.max_attempt = 10
41
+ self.session = None
42
+ self.sid = SID()
43
+ self.base_url = ''
44
+ self.song_rated = ''
45
+ self.create_session()
46
+
47
+ def create_session(self):
48
+
49
+ __headers = get_headers()
50
+ cookies = {'sid': self.sid.get_sid()}
51
+
52
+ self.session = requests.Session()
53
+ response = safe_get_main_url(self, 'https://hitmos.me', headers=__headers, cookies=cookies, timeout=5)
54
+
55
+
56
+ self.base_url = response.url
57
+ self.song_rated_more1 = urljoin(response.url, 'songs/top-rated/start/')
58
+ self.song_rated = urljoin(response.url, 'songs/top-rated')
59
+
60
+
61
+ class BaseSessionHandlerInputTracks:
62
+ def __init__(self):
63
+ self.__attempt = 0
64
+ self.max_attempt = 10
65
+ self.base_url = None
66
+ self.search_url = None
67
+ self.session = None
68
+ self.sid = SID()
69
+ self.create_session()
70
+
71
+ def create_session(self):
72
+ __headers = get_headers()
73
+ cookies = {'sid': self.sid.get_sid()}
74
+
75
+ while self.__attempt < self.max_attempt:
76
+ try:
77
+ self.session = requests.Session()
78
+ if len(cookies['sid']) == 0:
79
+ response = self.session.get('https://hitmos.me/', headers=__headers, allow_redirects=True, timeout=(5, 15))
80
+ else:
81
+ self.session.cookies.update(cookies)
82
+ response = self.session.get('https://hitmos.me/', headers=__headers, allow_redirects=True, timeout=(5, 15))
83
+
84
+ if response.status_code == 200:
85
+ response = self.session.get(response.url, headers=__headers)
86
+ if len(self.session.cookies.get_dict()) == 0:
87
+ continue
88
+ else:
89
+ self.sid.write_sid(self.session.cookies.get_dict())
90
+ break
91
+ else:
92
+ response = self.session.get('https://hitmos.me/', headers=__headers, allow_redirects=True, timeout=5)
93
+ if response.status_code == 200:
94
+ self.sid.write_sid(self.session.cookies.get_dict())
95
+ break
96
+ except ReadTimeout as err:
97
+ self.__attempt +=1
98
+ cookies = {}
99
+ print(err)
100
+ self.session.cookies.clear()
101
+ cookies = {}
102
+ self.session.close()
103
+ else:
104
+ self.__attempt = 0
105
+ print('Произошла непредвиденная ситуация', __file__)
106
+
107
+ else:
108
+ raise MaxAttempts(self.max_attempt)
109
+
110
+ self.base_url = response.url
111
+ self.search_url = urljoin(self.base_url, 'search?q=')
@@ -0,0 +1,23 @@
1
+ import fake_useragent
2
+
3
+
4
+ def get_headers():
5
+ user = fake_useragent.UserAgent().random
6
+
7
+ headers = {
8
+ 'User-Agent': user,
9
+ 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
10
+ 'Accept-Language': 'ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3',
11
+ # 'DNT': '1',
12
+ # 'Sec-GPC': '1',
13
+ # 'Connection': 'keep-alive',
14
+ # 'Upgrade-Insecure-Requests': '1',
15
+ # 'Sec-Fetch-Dest': 'document',
16
+ # 'Sec-Fetch-Mode': 'navigate',
17
+ # 'Sec-Fetch-Site': 'none',
18
+ # 'Sec-Fetch-User': '?1',
19
+ # 'Priority': 'u=0, i',
20
+ # 'Pragma': 'no-cache',
21
+ # 'Cache-Control': 'no-cache',
22
+ }
23
+ return headers
@@ -0,0 +1,11 @@
1
+ def replace_symbol_in_title(title):
2
+ return (title.replace('/','')
3
+ .replace(':','')
4
+ .replace('*','')
5
+ .replace('?','')
6
+ .replace('"','')
7
+ .replace('<','')
8
+ .replace('>','')
9
+ .replace('|','')
10
+ .replace('\\','')
11
+ )
@@ -0,0 +1,56 @@
1
+ from requests.models import Response
2
+ from tenacity import retry, stop_after_attempt, wait_fixed, retry_if_exception_type
3
+ from requests.exceptions import ChunkedEncodingError, ConnectionError, ReadTimeout
4
+
5
+ @retry(
6
+ stop=stop_after_attempt(5),
7
+ wait=wait_fixed(2),
8
+ retry=retry_if_exception_type((ChunkedEncodingError, ConnectionError)))
9
+ def safe_get(self, url, headers, cookies=None, allow_redirects=False, timeout=15) -> Response:
10
+ try:
11
+ response = self.session.get(url, headers=headers, cookies=cookies, allow_redirects=allow_redirects, timeout=timeout, stream=True)
12
+ except ReadTimeout as err:
13
+ print(err)
14
+ self.create_session()
15
+ response = self.session.get(url, headers=headers, cookies=cookies, allow_redirects=allow_redirects, timeout=timeout, stream=True)
16
+ self.sid.write_sid(response.cookies.get_dict()['sid'])
17
+ return response
18
+
19
+
20
+ @retry(
21
+ stop=stop_after_attempt(5),
22
+ wait=wait_fixed(2),
23
+ retry=retry_if_exception_type((ChunkedEncodingError, ConnectionError)))
24
+ def safe_head(self, url, headers, cookies=None, allow_redirects=False, timeout=15) -> Response:
25
+ try:
26
+ response = self.session.head(url, headers=headers, cookies=cookies, allow_redirects=allow_redirects, timeout=timeout, stream=True)
27
+ except ReadTimeout as err:
28
+ print(err)
29
+ self.create_session()
30
+ response = self.session.head(url, headers=headers, cookies=cookies, allow_redirects=allow_redirects, timeout=timeout, stream=True)
31
+ self.sid.write_sid(response.cookies.get_dict()['sid'])
32
+ return response
33
+
34
+ @retry(
35
+ stop=stop_after_attempt(10),
36
+ wait=wait_fixed(2),
37
+ retry=retry_if_exception_type((ReadTimeout)))
38
+ def safe_get_main_url(self, url, headers, cookies=None, allow_redirects=False, timeout=15) -> Response:
39
+ if len(cookies['sid']) != 0:
40
+ response = self.session.get(url, headers=headers, cookies=cookies, allow_redirects=True, timeout=timeout)
41
+ if response.status_code == 200:
42
+ self.session.cookies.update(cookies)
43
+ self.sid.write_sid(self.session.cookies.get_dict())
44
+ return response
45
+ else:
46
+ self.session.close()
47
+ else:
48
+ response = self.session.get(url, headers=headers, allow_redirects=True, timeout=timeout)
49
+ if response.status_code == 200:
50
+ self.session.cookies.update(response.cookies.get_dict())
51
+ self.sid.write_sid(self.session.cookies.get_dict())
52
+ return response
53
+
54
+
55
+
56
+
@@ -1,6 +1,6 @@
1
1
  from setuptools import setup
2
2
 
3
- version='1.0.3'
3
+ version='1.0.4'
4
4
 
5
5
  with open('README.md', encoding='utf-8') as f:
6
6
  long_description=f.read()
@@ -21,7 +21,7 @@ setup(
21
21
  'tenacity==9.1.2',
22
22
  ],
23
23
  # license=...,
24
- packages = ['parse_hitmos'],
24
+ packages = ['parse_hitmos', 'parse_hitmos/config', 'parse_hitmos/tools'],
25
25
  classifiers = [
26
26
  'Programming Language :: Python',
27
27
  'Programming Language :: Python :: 3.8',
@@ -1 +0,0 @@
1
- parse_hitmos
File without changes
File without changes
File without changes