Browse Source

update logging to make use of new default formatting

master
cinnaboot 7 years ago
parent
commit
c9a582db95
  1. 34
      video_metadata/views/tmdb.py

34
video_metadata/views/tmdb.py

@ -174,7 +174,7 @@ def query_media_json():
q_res = doQueryAlgorithm(query)
errors = q_res['errors']
results = q_res['results']
current_app.logger.debug(f'{util.getFunctionName()}, results length: {len(results)}')
current_app.logger.debug(f'results length: {len(results)}')
else:
errors = ['required parameters: query, rel_path']
@ -193,7 +193,7 @@ def query_path_json():
errors = []
if not 'rel_path' in request.args:
errors.append(f'{util.getFunctionName()}, required parameters: rel_path')
errors.append(f'required parameters: rel_path')
else:
path = request.args['rel_path']
cur = db.get_db().cursor()
@ -233,7 +233,7 @@ def create_path_mapping():
and 'media_type' in request.form
and 'id' in request.form
):
errors.append(f'{util.getFunctionName()}, required parameters: rel_path, media_type, id')
errors.append(f'required parameters: rel_path, media_type, id')
else:
id = request.form['id']
media_type = request.form['media_type']
@ -241,7 +241,7 @@ def create_path_mapping():
id_column = getIDColumn(media_type)
conn = db.get_db()
cur = conn.cursor()
current_app.logger.debug(f'{util.getFunctionName()}, mapping path "{rel_path}" for id: {id}')
current_app.logger.debug(f'mapping path "{rel_path}" for id: {id}')
try:
cur.execute(f'INSERT INTO path_cache({id_column}, media_type, path, add_date) '
f'VALUES(?,?,?, datetime())',
@ -272,7 +272,7 @@ def doQueryAlgorithm(query:query_data) -> dict:
if query.raw_query_str and parseQueryStr(query):
if isQueryCached(query.parsed_query_str):
view_results = makeLocalQuery(query)
current_app.logger.debug(f'{util.getFunctionName()}, view_results length: {len(view_results)}')
current_app.logger.debug(f'view_results length: {len(view_results)}')
else:
makeTMDBQuery(query, response)
@ -326,9 +326,7 @@ def parseQueryStr(query_obj):
query_obj.media_type = media_type.TV_SHOW
return True
current_app.logger.warning(
f'{util.getFunctionName()}, unable to guess media type for "{query_obj.raw_query_str}"'
)
current_app.logger.warning(f'unable to guess media type for "{query_obj.raw_query_str}"')
return False
@ -337,9 +335,7 @@ def isQueryCached(query_str):
cur = conn.cursor()
cur.execute('SELECT COUNT(*) FROM query_cache WHERE query=?', (query_str,))
count = cur.fetchone()[0]
current_app.logger.debug(
f'{util.getFunctionName()}, query_cache count: {count}, query: "{query_str}"'
)
current_app.logger.debug(f'query_cache count: {count}, query: "{query_str}"')
return (count > 0)
@ -403,11 +399,11 @@ def makeTMDBQuery(query_obj, response_obj):
elif query_obj.media_type == media_type.TV_SHOW:
search_part = TMDB_SEARCH_TV
else:
query_obj.errors.append('%s(), query type is not set' % util.getFunctionName())
query_obj.errors.append('query type is not set')
return False
current_app.logger.info(
f'{util.getFunctionName()}, making remote query to TMDB API: '
f'making remote query to TMDB API: '
f'{query_obj.media_type.name}, "{query_obj.parsed_query_str}"'
)
request_headers = {"Accept": "text/html,application/xhtml+xml,application/xml"}
@ -444,7 +440,7 @@ def makeTMDBQuery(query_obj, response_obj):
charset = cgi.parse_header(ct_header)[1]['charset']
response_obj.response_body = response.read().decode(charset)
else:
response_obj.errors.append('%s(), no charset key in ct_header' % util.getFunctionName())
response_obj.errors.append('no charset key in ct_header')
response_obj.response_body = response.read()
return False
@ -472,7 +468,7 @@ def parseTMDBResult(result:object, media_type:int) -> view_result:
parsed.title = result['name']
parsed.release_date = result['first_air_date']
except KeyError as e:
current_app.logger.warning(f'{util.getFunctionName()}, missing key in JSON for "{parsed.title}": {e}')
current_app.logger.warning(f'missing key in JSON for "{parsed.title}": {e}')
return parsed
@ -482,7 +478,7 @@ def storeTMDBQueryResults(query_obj, result_list):
cur = conn.cursor()
query_id = 0
current_app.logger.debug(f'{util.getFunctionName()}, adding query string '
current_app.logger.debug(f'adding query string '
f'"{query_obj.parsed_query_str}" into local cache')
try:
@ -502,13 +498,13 @@ def storeTMDBQueryResults(query_obj, result_list):
cur.execute(f'SELECT COUNT(*) FROM query_details WHERE {id_column}=?', (r.id, ))
count = cur.fetchone()[0]
if count > 0:
current_app.logger.debug(f'{util.getFunctionName()}, '
current_app.logger.debug(
f'skipping result that is already saved. id: {r.id}, title: {r.title}'
)
break
try:
current_app.logger.debug(f'{util.getFunctionName()}, adding query details for "{r.title}"')
current_app.logger.debug(f'adding query details for "{r.title}"')
cur.execute(f'INSERT INTO query_details({id_column}, '
+ 'media_type, title, overview, release_date, original_language, poster_path)'
+ ' VALUES (?,?,?,?,?,?,?)',
@ -519,7 +515,7 @@ def storeTMDBQueryResults(query_obj, result_list):
+ ' VALUES (?,?,?)', (query_id, r.id, r.media_type)
)
except DatabaseError as e:
query_obj.errors.append(f'{util.getFunctionName()}():{util.getLineNum()}, database error \'{e}\'')
query_obj.errors.append(f'database error \'{e}\'')
if len(query_obj.errors) == 0:
conn.commit()

Loading…
Cancel
Save