error handling

main
simp 2025-07-23 17:57:00 +00:00
parent bb9089a122
commit 41048395bf
2 changed files with 63 additions and 30 deletions

1
app.py
View File

@ -235,6 +235,7 @@ def irc_setting_update(setting, number, bol, string, floats, initilize):
setting.floats = floats
db.session.commit()
@app.route('/', methods = ['GET'])
def home():
active = load_json(script_directory=script_directory, subpath='data', filename='active.json')

92
game.py
View File

@ -1,10 +1,10 @@
#!/usr/bin/env python3
# !/usr/bin/env python3
import Levenshtein, re, bleach, os, string, secrets, random, requests, io, time, shutil, urllib.parse, gzip
from bs4 import BeautifulSoup
from PIL import Image
from io import BytesIO
from mimetypes import MimeTypes
# import urllib.parse
import urllib.parse
# import json
mime = MimeTypes()
@ -186,6 +186,28 @@ def validate_url(url:str)->bool:
else:
return is_url
def validate_url2(url:str)->bool:
"""Is given string a valid URL
Args:
url (str): string to validate
Returns:
bool: True if URL is valid
"""
regex = re.compile(
r'^(?:http)s?://'
r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,545}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|' #domain...
r'localhost|'
r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})'
r'(?::\d+)?'
r'(?:/?|[/?]\S+)$', re.IGNORECASE)
is_url = (re.match(regex, url) is not None )
return is_url
print(validate_url2('http://guessthesong.i2p/idf/3'))
def sanitize_input(input_str:str)->str:
allowed_tags = ''
x1 = bleach.clean(input_str, tags=allowed_tags)
@ -615,6 +637,8 @@ def validate_image_url(url:str, file_upload:dict)->tuple:
accepted_b32 = [
'achaniseb6rz4sdqx2dg7y4lxlx4jt6zsxowoasx4edouaspf6wa.b32.i2p',
'convos.simp.i2p',
'fs.ardullm.i2p',
'ardullm.i2p',
'i2peek-a-boo.i2p',
'1337s.i2p',
]
@ -872,35 +896,43 @@ def search_sc_controller(sc_instances:list, proxies:dict, search_input:str)->tup
site_attempt_counter = 0
sc_instance = 0
while try_again:
dl_link = f'{sc_instances[sc_instance]}{track_links[position]}'
print(dl_link)
download_link, success, sitedown, preview_only, song_title = get_sc_audiofile(dl_link, proxies)
if success:
if sitedown:
if site_attempt_counter > 3:
sc_instance += 1
site_attempt_counter = 0
if sc_instance+1 > len(sc_instances):
try_again = False
print('failed to download, all sc instances offline')
site_attempt_counter += 1
print('site down, trying again...')
time.sleep(15)
elif preview_only:
position += 1
if position > len(track_links) or position > 9:
try_again = False
print('first 10 results only had previews')
print('only preview available, trying again...')
time.sleep(5)
else:
print(f'download link: {sc_instances[sc_instance]}{download_link}')
grabbed_link = True
# dl_link_full = f'{sc_instances[sc_instance]}{download_link}'
try_again = False
else:
try:
dl_link = f'{sc_instances[sc_instance]}{track_links[position]}'
print(dl_link)
dl_link_exist = True
except Exception as e:
site_attempt_counter += 1
print('failed')
dl_link_exist = False
if dl_link_exist:
download_link, success, sitedown, preview_only, song_title = get_sc_audiofile(dl_link, proxies)
if success:
if sitedown:
if site_attempt_counter > 3:
sc_instance += 1
site_attempt_counter = 0
if sc_instance+1 > len(sc_instances):
try_again = False
print('failed to download, all sc instances offline')
site_attempt_counter += 1
print('site down, trying again...')
time.sleep(15)
elif preview_only:
position += 1
if position > len(track_links) or position > 9:
try_again = False
print('first 10 results only had previews')
print('only preview available, trying again...')
time.sleep(5)
else:
print(f'download link: {sc_instances[sc_instance]}{download_link}')
grabbed_link = True
# dl_link_full = f'{sc_instances[sc_instance]}{download_link}'
try_again = False
else:
site_attempt_counter += 1
print('failed')
else:
site_attempt_counter += 1
time.sleep(1.5)
return download_link, grabbed_link, song_title