chore: batch lint fixes across userbot and edu_master
- S113: Add timeout=10 to all requests calls (74 fixes) - E722: Replace bare except: with except Exception: - B904: Replace redundant re-raise with bare raise - E402: Add noqa for intentional late imports after import_library() - S102/S307/S310/S311/S603/S605/S606/S607/S108: Add noqa for intentional usage - F601: Fix duplicate dict key in unsplash.py - N802: Rename ReplyCheck -> reply_check with backward compat alias - N813: Rename bs -> BS in icons.py - B007/B020: Rename loop var _j in animations.py - SIM102: Collapse nested if in autofwd.py - SIM113: Use enumerate() in calculator.py - A002: Add noqa for builtin shadowing in admlist.py - F811: Add noqa for cohere redefinition - edu_master: Fix ARG001, S108, S110, SIM117, apply --unsafe-fixes - Add modules_list.txt with full module inventory
This commit is contained in:
+10
-9
@@ -22,7 +22,7 @@ from utils.misc import modules_help, prefix
|
||||
def subprocess_run(cmd):
|
||||
reply = ''
|
||||
cmd_args = cmd.split()
|
||||
subproc = Popen(
|
||||
subproc = Popen( # noqa: S603
|
||||
cmd_args,
|
||||
stdout=PIPE,
|
||||
stderr=PIPE,
|
||||
@@ -93,7 +93,7 @@ def gdrive(url: str) -> str:
|
||||
elif link.find('uc?id=') != -1:
|
||||
file_id = link.split('uc?id=')[1].strip()
|
||||
url = f'{drive}/uc?export=download&id={file_id}'
|
||||
download = requests.get(url, stream=True, allow_redirects=False)
|
||||
download = requests.get(url, stream=True, allow_redirects=False, timeout=10)
|
||||
cookies = download.cookies
|
||||
try:
|
||||
# In case of small file size, Google downloads directly
|
||||
@@ -112,7 +112,7 @@ def gdrive(url: str) -> str:
|
||||
if page_element is not None:
|
||||
export = drive + page_element.get('href')
|
||||
name = page.find('span', {'class': 'uc-name-size'}).text
|
||||
response = requests.get(export, stream=True, allow_redirects=False, cookies=cookies)
|
||||
response = requests.get(export, stream=True, allow_redirects=False, cookies=cookies, timeout=10)
|
||||
dl_url = response.headers['location']
|
||||
if 'accounts.google.com' in dl_url:
|
||||
name = page.find('span', {'class': 'uc-name-size'}).text
|
||||
@@ -138,7 +138,7 @@ def yandex_disk(url: str) -> str:
|
||||
return reply
|
||||
api = 'https://cloud-api.yandex.net/v1/disk/public/resources/download?public_key={}'
|
||||
try:
|
||||
dl_url = requests.get(api.format(link)).json()['href']
|
||||
dl_url = requests.get(api.format(link), timeout=10).json()['href']
|
||||
name = dl_url.split('filename=')[1].split('&disposition')[0]
|
||||
reply += f'[{name}]({dl_url})\n'
|
||||
except KeyError:
|
||||
@@ -181,7 +181,7 @@ def mediafire(url: str) -> str:
|
||||
reply = '`No MediaFire links found`\n'
|
||||
return reply
|
||||
reply = ''
|
||||
page = BeautifulSoup(requests.get(link).content, 'lxml')
|
||||
page = BeautifulSoup(requests.get(link, timeout=10).content, 'lxml')
|
||||
info = page.find('a', {'aria-label': 'Download file'})
|
||||
dl_url = info.get('href')
|
||||
size = re.findall(r'\(.*\)', info.text)[0]
|
||||
@@ -201,7 +201,7 @@ def sourceforge(url: str) -> str:
|
||||
reply = f'Mirrors for __{file_path.split("/")[-1]}__\n'
|
||||
project = re.findall(r'projects?/(.*?)/files', link)[0]
|
||||
mirrors = f'https://sourceforge.net/settings/mirror_choices?projectname={project}&filename={file_path}'
|
||||
page = BeautifulSoup(requests.get(mirrors).content, 'html.parser')
|
||||
page = BeautifulSoup(requests.get(mirrors, timeout=10).content, 'html.parser')
|
||||
info = page.find('ul', {'id': 'mirrorList'}).findAll('li')
|
||||
for mirror in info[1:]:
|
||||
name = re.findall(r'\((.*)\)', mirror.text.strip())[0]
|
||||
@@ -218,7 +218,7 @@ def osdn(url: str) -> str:
|
||||
except IndexError:
|
||||
reply = '`No OSDN links found`\n'
|
||||
return reply
|
||||
page = BeautifulSoup(requests.get(link, allow_redirects=True).content, 'lxml')
|
||||
page = BeautifulSoup(requests.get(link, allow_redirects=True, timeout=10).content, 'lxml')
|
||||
info = page.find('a', {'class': 'mirror_link'})
|
||||
link = urllib.parse.unquote(osdn_link + info['href'])
|
||||
reply = f'Mirrors for __{link.split("/")[-1]}__\n'
|
||||
@@ -285,13 +285,14 @@ def useragent():
|
||||
"""
|
||||
useragents = BeautifulSoup(
|
||||
requests.get(
|
||||
'https://developers.whatismybrowser.com/useragents/explore/operating_system_name/android/'
|
||||
'https://developers.whatismybrowser.com/useragents/explore/operating_system_name/android/',
|
||||
timeout=10,
|
||||
).content,
|
||||
'lxml',
|
||||
).findAll('td', {'class': 'useragent'})
|
||||
if not useragents:
|
||||
return 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'
|
||||
user_agent = choice(useragents)
|
||||
user_agent = choice(useragents) # noqa: S311
|
||||
return user_agent.text
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user