This commit is contained in:
Thomas Hanika 2022-01-25 17:39:29 +01:00
parent a490e13b99
commit 7f76a50b36
3 changed files with 33 additions and 12 deletions

View file

@ -5,7 +5,7 @@ import hashlib
USER_AGENT = 'YCast'
VAR_PATH = os.path.expanduser("~") + '/.ycast'
CACHE_PATH = VAR_PATH + '/cache'
FILTER_PATH = VAR_PATH + '/filter'
class Directory:
def __init__(self, name, item_count, displayname=None):
@ -35,7 +35,9 @@ def get_stationid_prefix(uid):
def get_cache_path(cache_name):
cache_path = CACHE_PATH + '/' + cache_name
cache_path = CACHE_PATH
if cache_name:
cache_path = CACHE_PATH + '/' + cache_name
try:
os.makedirs(cache_path)
except FileExistsError:
@ -45,6 +47,25 @@ def get_cache_path(cache_name):
return None
return cache_path
def get_filter_path():
try:
os.makedirs(FILTER_PATH)
except FileExistsError:
pass
except PermissionError:
logging.error("Could not create cache folders (%s) because of access permissions", cache_path)
return None
return FILTER_PATH
def get_var_path():
try:
os.makedirs(VAR_PATH)
except FileExistsError:
pass
except PermissionError:
logging.error("Could not create cache folders (%s) because of access permissions", cache_path)
return None
return VAR_PATH
def get_checksum(feed, charlimit=12):
hash_feed = feed.encode()

View file

@ -2,11 +2,11 @@ import logging
import os
import yaml
from ycast import generic
VAR_PATH = os.path.expanduser("~") + '/.ycast'
MAX_ENTRIES = 15
config_file = VAR_PATH + '/recently.yml'
recently_file = generic.get_var_path() + '/recently.yml'
def signal_station_selected(name, url, icon):
@ -44,20 +44,20 @@ def set_stations_yaml(heared_stations):
return None
try:
with open(config_file, 'w') as f:
with open(recently_file, 'w') as f:
f.writelines(heared_stations)
logging.info("File written '%s'", config_file)
logging.info("File written '%s'", recently_file)
except Exception as ex:
logging.error("File not written '%s': %s", config_file, ex)
logging.error("File not written '%s': %s", recently_file, ex)
def get_stations_list():
try:
with open(config_file, 'r') as f:
with open(recently_file, 'r') as f:
heared_stations = f.readlines()
except FileNotFoundError:
logging.warning("File not found '%s' not found", config_file)
logging.warning("File not found '%s' not found", recently_file)
return []
except yaml.YAMLError as e:
logging.error("Station configuration format error: %s", e)
@ -67,10 +67,10 @@ def get_stations_list():
def get_recently_stations_yaml():
try:
with open(config_file, 'r') as f:
with open(recently_file, 'r') as f:
my_stations = yaml.safe_load(f)
except FileNotFoundError:
logging.error("Station configuration '%s' not found", config_file)
logging.error("Station configuration '%s' not found", recently_file)
return None
except yaml.YAMLError as e:
logging.error("Station configuration format error: %s", e)

View file

@ -6,7 +6,7 @@ import ycast.generic as generic
ID_PREFIX = "MY"
config_file = 'stations.yml'
config_file = generic.get_var_path() + '/stations.yml'
class Station: