1
0
Fork 0
mirror of https://github.com/morpheus65535/bazarr synced 2024-12-27 18:17:46 +00:00

Fixed throttled providers badges in UI throwing exception. #1631

This commit is contained in:
morpheus65535 2021-12-06 19:31:10 -05:00
parent 2cde2686fc
commit ca8f3f9fd2
2 changed files with 11 additions and 8 deletions

View file

@ -34,7 +34,7 @@ class Badges(Resource):
.where(reduce(operator.and_, movies_conditions))\
.count()
throttled_providers = len(eval(str(get_throttled_providers())))
throttled_providers = len(get_throttled_providers())
health_issues = len(get_health_issues())

View file

@ -315,12 +315,15 @@ def reset_throttled_providers():
def get_throttled_providers():
providers = {}
if os.path.exists(os.path.join(args.config_dir, 'config', 'throttled_providers.dat')):
with open(os.path.normpath(os.path.join(args.config_dir, 'config', 'throttled_providers.dat')), 'r') as handle:
providers = handle.read()
if not providers:
try:
if os.path.exists(os.path.join(args.config_dir, 'config', 'throttled_providers.dat')):
with open(os.path.normpath(os.path.join(args.config_dir, 'config', 'throttled_providers.dat')), 'r') as \
handle:
providers = ast.literal_eval(handle.read())
except (OSError, ValueError):
providers = {}
return providers
finally:
return providers
def set_throttled_providers(data):
@ -329,11 +332,11 @@ def set_throttled_providers(data):
try:
tp = eval(str(get_throttled_providers()))
tp = get_throttled_providers()
if not isinstance(tp, dict):
raise ValueError('tp should be a dict')
except Exception:
logging.error("Invalid content in throttled_providers.dat. Resetting")
# set empty content in throttled_providers.dat
set_throttled_providers('')
tp = eval(str(get_throttled_providers()))
tp = get_throttled_providers()