5 recently stations added in first page (experimental) bugfix missing recently.yml
This commit is contained in:
parent
cdb1c932a6
commit
f38b1f566c
3 changed files with 22 additions and 10 deletions
|
@ -93,10 +93,12 @@ def write_yaml_file(file_name, dictionary):
|
|||
try:
|
||||
with open(file_name, 'w') as f:
|
||||
yaml.dump(dictionary, f)
|
||||
return True
|
||||
except yaml.YAMLError as e:
|
||||
logging.error("YAML format error in '%':\n %s", file_name, e)
|
||||
except Exception as ex:
|
||||
logging.error("File not written '%s':\n %s", file_name, ex)
|
||||
return False
|
||||
|
||||
|
||||
def readlns_txt_file(file_name):
|
||||
|
@ -104,9 +106,7 @@ def readlns_txt_file(file_name):
|
|||
with open(file_name, 'r') as f:
|
||||
return f.readlines()
|
||||
except FileNotFoundError:
|
||||
logging.error("YAML file '%s' not found", file_name)
|
||||
except yaml.YAMLError as e:
|
||||
logging.error("YAML format error in '%':\n %s", file_name, e)
|
||||
logging.error("TXT file '%s' not found", file_name)
|
||||
return None
|
||||
|
||||
|
||||
|
@ -114,8 +114,10 @@ def writelns_txt_file(file_name, line_list):
|
|||
try:
|
||||
with open(file_name, 'w') as f:
|
||||
f.writelines(line_list)
|
||||
return True
|
||||
except Exception as ex:
|
||||
logging.error("File not written '%s':\n %s", file_name, ex)
|
||||
return False
|
||||
|
||||
|
||||
def get_json_attr(json, attr):
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
import logging
|
||||
from ycast import generic
|
||||
|
||||
MAX_ENTRIES = 15
|
||||
DIRECTORY_NAME = "recently used"
|
||||
|
||||
recently_file = generic.get_var_path() + '/recently.yml'
|
||||
is_yml_file_loadable = True
|
||||
|
||||
|
||||
def signal_station_selected(name, url, icon):
|
||||
list_heard_stations = get_stations_list()
|
||||
if len(list_heard_stations) == 0:
|
||||
if not list_heard_stations:
|
||||
list_heard_stations = []
|
||||
list_heard_stations.append(DIRECTORY_NAME + ":\n")
|
||||
# make name yaml - like
|
||||
name = name.replace(":", " -")
|
||||
|
@ -31,7 +32,8 @@ def signal_station_selected(name, url, icon):
|
|||
|
||||
|
||||
def set_stations_yaml(heard_stations):
|
||||
generic.writelns_txt_file(recently_file, heard_stations)
|
||||
global is_yml_file_loadable
|
||||
is_yml_file_loadable = generic.writelns_txt_file(recently_file, heard_stations)
|
||||
|
||||
|
||||
def get_stations_list():
|
||||
|
@ -39,9 +41,17 @@ def get_stations_list():
|
|||
|
||||
|
||||
def get_recently_stations_yaml():
|
||||
return generic.read_yaml_file(recently_file)
|
||||
global is_yml_file_loadable
|
||||
dict_stations = None
|
||||
if is_yml_file_loadable:
|
||||
dict_stations = generic.read_yaml_file(recently_file)
|
||||
if not dict_stations:
|
||||
is_yml_file_loadable = False
|
||||
return dict_stations
|
||||
|
||||
|
||||
def directory_name():
|
||||
dir = generic.read_yaml_file(recently_file)
|
||||
return list(dir.keys())[0]
|
||||
if dir:
|
||||
return list(dir.keys())[0]
|
||||
return None
|
||||
|
|
|
@ -155,7 +155,7 @@ def landing(path=''):
|
|||
len(my_stations.get_category_directories())))
|
||||
|
||||
stations = my_stations.get_stations_by_category(my_recentlystation.directory_name())
|
||||
if stations:
|
||||
if stations and len(stations) > 0:
|
||||
# emulate Sp
|
||||
page.add(vtuner.Directory(' ', url_for('my_stations_landing', _external=True),
|
||||
len(my_stations.get_category_directories())))
|
||||
|
@ -171,7 +171,7 @@ def landing(path=''):
|
|||
if count > 4:
|
||||
break
|
||||
|
||||
page.set_count(3)
|
||||
page.set_count(1)
|
||||
|
||||
else:
|
||||
page.add(vtuner.Display("'My Stations' feature not configured."))
|
||||
|
|
Loading…
Add table
Reference in a new issue