mirror of
https://github.com/tcsenpai/swingmusic.git
synced 2025-06-10 04:57:45 +00:00
ignore unicode characters errors
+ add methods on settings.Keys to verify key !== empty string
This commit is contained in:
parent
5cf0bb8c42
commit
54714a224b
@ -173,4 +173,3 @@ class HandleArgs:
|
|||||||
if any((a in ARGS for a in ALLARGS.version)):
|
if any((a in ARGS for a in ALLARGS.version)):
|
||||||
print(settings.Release.APP_VERSION)
|
print(settings.Release.APP_VERSION)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ from sqlite3 import Cursor
|
|||||||
from app.db.sqlite.utils import tuple_to_track, tuples_to_tracks
|
from app.db.sqlite.utils import tuple_to_track, tuples_to_tracks
|
||||||
|
|
||||||
from .utils import SQLiteManager
|
from .utils import SQLiteManager
|
||||||
from pprint import pprint
|
from app.utils.unicode import handle_unicode
|
||||||
|
|
||||||
|
|
||||||
class SQLiteTrackMethods:
|
class SQLiteTrackMethods:
|
||||||
@ -45,24 +45,19 @@ class SQLiteTrackMethods:
|
|||||||
|
|
||||||
track = OrderedDict(sorted(track.items()))
|
track = OrderedDict(sorted(track.items()))
|
||||||
|
|
||||||
# def should_fail():
|
|
||||||
# """
|
|
||||||
# Return true randomly.
|
|
||||||
# """
|
|
||||||
# return random.randint(0, 1) == 1
|
|
||||||
|
|
||||||
# if should_fail():
|
|
||||||
# raise Exception("Failed to insert track")
|
|
||||||
|
|
||||||
# def force_surrogatepass(string: str):
|
|
||||||
# return string.encode("utf-16", "surrogatepass").decode("utf-16")
|
|
||||||
|
|
||||||
track["artist"] = track["artists"]
|
track["artist"] = track["artists"]
|
||||||
track["albumartist"] = track["albumartists"]
|
track["albumartist"] = track["albumartists"]
|
||||||
|
|
||||||
del track["artists"]
|
del track["artists"]
|
||||||
del track["albumartists"]
|
del track["albumartists"]
|
||||||
|
|
||||||
|
try:
|
||||||
|
cur.execute(sql, track)
|
||||||
|
except UnicodeEncodeError:
|
||||||
|
# for each of the values in the track, call handle_unicode on it
|
||||||
|
for key, value in track.items():
|
||||||
|
track[key] = handle_unicode(value)
|
||||||
|
|
||||||
cur.execute(sql, track)
|
cur.execute(sql, track)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -71,13 +66,9 @@ class SQLiteTrackMethods:
|
|||||||
Inserts a list of tracks into the database.
|
Inserts a list of tracks into the database.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
with SQLiteManager() as cur:
|
with SQLiteManager() as cur:
|
||||||
for track in tracks:
|
for track in tracks:
|
||||||
try:
|
|
||||||
cls.insert_one_track(track, cur)
|
cls.insert_one_track(track, cur)
|
||||||
except Exception:
|
|
||||||
pprint(track, indent=4)
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_all_tracks():
|
def get_all_tracks():
|
||||||
|
@ -6,6 +6,7 @@ import sys
|
|||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from app import configs
|
from app import configs
|
||||||
|
from app.logger import log
|
||||||
|
|
||||||
join = os.path.join
|
join = os.path.join
|
||||||
|
|
||||||
@ -239,3 +240,15 @@ class Keys:
|
|||||||
if IS_BUILD:
|
if IS_BUILD:
|
||||||
cls.LASTFM_API = configs.LASTFM_API_KEY
|
cls.LASTFM_API = configs.LASTFM_API_KEY
|
||||||
cls.POSTHOG_API_KEY = configs.POSTHOG_API_KEY
|
cls.POSTHOG_API_KEY = configs.POSTHOG_API_KEY
|
||||||
|
|
||||||
|
cls.verify_exists()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def verify_exists(cls):
|
||||||
|
if not cls.LASTFM_API:
|
||||||
|
log.error("ERROR: LASTFM_API_KEY not set in environment")
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
if not cls.POSTHOG_API_KEY:
|
||||||
|
log.error("ERROR: POSTHOG_API_KEY not set in environment")
|
||||||
|
sys.exit(0)
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
def handle_unicode(string: str):
|
def handle_unicode(string: str):
|
||||||
"""
|
"""
|
||||||
Try resolving unicode characters, else escape them.
|
Handles Unicode errors by ignoring unicode characters
|
||||||
"""
|
"""
|
||||||
return string.encode("utf-16", "replace").decode("utf-16")
|
return string.encode("utf-16", "ignore").decode("utf-16")
|
||||||
# try:
|
|
||||||
# except:
|
|
||||||
# return string.encode("unicode_escape").decode("utf-8")
|
|
@ -80,12 +80,12 @@ def start_watchdog():
|
|||||||
|
|
||||||
|
|
||||||
def run_swingmusic():
|
def run_swingmusic():
|
||||||
|
Keys.load()
|
||||||
HandleArgs()
|
HandleArgs()
|
||||||
log_startup_info()
|
log_startup_info()
|
||||||
bg_run_setup()
|
bg_run_setup()
|
||||||
start_watchdog()
|
start_watchdog()
|
||||||
telemetry.create_userid()
|
telemetry.create_userid()
|
||||||
Keys.load()
|
|
||||||
|
|
||||||
setproctitle.setproctitle(
|
setproctitle.setproctitle(
|
||||||
f"swingmusic - {FLASKVARS.FLASK_HOST}:{FLASKVARS.FLASK_PORT}"
|
f"swingmusic - {FLASKVARS.FLASK_HOST}:{FLASKVARS.FLASK_PORT}"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user