radiobrowser limits configurable in filter.yml
This commit is contained in:
parent
8766143618
commit
f9c1c7ea75
4 changed files with 37 additions and 17 deletions
|
@ -1 +1 @@
|
|||
__version__ = '1.2.0'
|
||||
__version__ = '1.2.2'
|
||||
|
|
|
@ -5,30 +5,31 @@ from ycast.generic import get_json_attr
|
|||
|
||||
white_list = {}
|
||||
black_list = {}
|
||||
filter_dir = {}
|
||||
filter_dictionary = {}
|
||||
parameter_failed_list = {}
|
||||
count_used = 0
|
||||
count_hit = 0
|
||||
LIMITS_NAME = 'limits'
|
||||
|
||||
|
||||
def init_filter():
|
||||
global white_list
|
||||
global black_list
|
||||
global parameter_failed_list
|
||||
global filter_dir
|
||||
global filter_dictionary
|
||||
global count_used
|
||||
global count_hit
|
||||
count_used = 0
|
||||
count_hit = 0
|
||||
filter_dir = generic.read_yaml_file(generic.get_var_path() + '/filter.yml')
|
||||
if filter_dir:
|
||||
white_list = filter_dir['whitelist']
|
||||
black_list = filter_dir['blacklist']
|
||||
filter_dictionary = generic.read_yaml_file(generic.get_var_path() + '/filter.yml')
|
||||
if filter_dictionary:
|
||||
white_list = filter_dictionary['whitelist']
|
||||
black_list = filter_dictionary['blacklist']
|
||||
else:
|
||||
white_list = {'lastcheckok': 1}
|
||||
black_list = {}
|
||||
filter_dir = {'whitelist': white_list, 'blacklist': black_list}
|
||||
generic.write_yaml_file(generic.get_var_path() + '/filter.yml', filter_dir)
|
||||
filter_dictionary = {'whitelist': white_list, 'blacklist': black_list}
|
||||
generic.write_yaml_file(generic.get_var_path() + '/filter.yml', filter_dictionary)
|
||||
|
||||
parameter_failed_list.clear()
|
||||
return
|
||||
|
@ -106,3 +107,17 @@ def check_station(station_json):
|
|||
return False
|
||||
count_hit = count_hit + 1
|
||||
return True
|
||||
|
||||
|
||||
def get_limit(param_name, default):
|
||||
global filter_dictionary
|
||||
filter_dictionary = generic.read_yaml_file(generic.get_var_path() + '/filter.yml')
|
||||
limits_dict = {}
|
||||
if LIMITS_NAME in filter_dictionary:
|
||||
limits_dict = filter_dictionary[LIMITS_NAME]
|
||||
if param_name in limits_dict:
|
||||
return limits_dict[param_name]
|
||||
limits_dict[param_name] = default
|
||||
filter_dictionary[LIMITS_NAME] = limits_dict
|
||||
generic.write_yaml_file(generic.get_var_path() + '/filter.yml', filter_dictionary)
|
||||
return default
|
||||
|
|
|
@ -11,17 +11,17 @@ from ycast.my_filter import check_station, init_filter, end_filter
|
|||
from ycast.generic import get_json_attr
|
||||
|
||||
API_ENDPOINT = "http://all.api.radio-browser.info"
|
||||
MINIMUM_COUNT_GENRE = 40
|
||||
MINIMUM_COUNT_COUNTRY = 5
|
||||
MINIMUM_COUNT_LANGUAGE = 5
|
||||
DEFAULT_STATION_LIMIT = 200
|
||||
SHOW_BROKEN_STATIONS = False
|
||||
SHOW_WITHOUT_FAVICON = False
|
||||
MINIMUM_COUNT_GENRE = my_filter.get_limit('MINIMUM_COUNT_GENRE', 40)
|
||||
MINIMUM_COUNT_COUNTRY = my_filter.get_limit('MINIMUM_COUNT_COUNTRY', 5)
|
||||
MINIMUM_COUNT_LANGUAGE = my_filter.get_limit('MINIMUM_COUNT_LANGUAGE', 5)
|
||||
DEFAULT_STATION_LIMIT = my_filter.get_limit('DEFAULT_STATION_LIMIT', 200)
|
||||
SHOW_BROKEN_STATIONS = my_filter.get_limit('SHOW_BROKEN_STATIONS', False)
|
||||
ID_PREFIX = "RB"
|
||||
|
||||
station_cache = {}
|
||||
|
||||
|
||||
|
||||
class Station:
|
||||
def __init__(self, station_json):
|
||||
self.stationuuid = generic.get_json_attr(station_json, 'stationuuid')
|
||||
|
|
|
@ -32,9 +32,9 @@ class MyTestCase(unittest.TestCase):
|
|||
def test_init_filter(self):
|
||||
my_filter.init_filter()
|
||||
|
||||
for elem in my_filter.filter_dir:
|
||||
for elem in my_filter.filter_dictionary:
|
||||
logging.warning("Name filtertype: %s", elem)
|
||||
filter_param = my_filter.filter_dir[elem]
|
||||
filter_param = my_filter.filter_dictionary[elem]
|
||||
if filter_param:
|
||||
for par in filter_param:
|
||||
logging.warning(" Name paramter: %s", par)
|
||||
|
@ -74,6 +74,11 @@ class MyTestCase(unittest.TestCase):
|
|||
result = radiobrowser.get_genre_directories()
|
||||
assert len(result) < 300
|
||||
|
||||
def test_get_limits(self):
|
||||
result = my_filter.get_limit('irgendwas',20)
|
||||
assert result == 20
|
||||
|
||||
|
||||
def test_recently_hit(self):
|
||||
|
||||
try:
|
||||
|
|
Loading…
Add table
Reference in a new issue