|
|
|
|
@ -1,6 +1,5 @@
|
|
|
|
|
|
|
|
|
|
import cgi |
|
|
|
|
from contextlib import closing |
|
|
|
|
from datetime import date |
|
|
|
|
from enum import Enum |
|
|
|
|
import json |
|
|
|
|
@ -11,7 +10,7 @@ from urllib.error import URLError, HTTPError
|
|
|
|
|
import urllib.parse |
|
|
|
|
import urllib.request |
|
|
|
|
|
|
|
|
|
from flask import Blueprint, current_app, flash, request, render_template |
|
|
|
|
from flask import Blueprint, current_app, flash, Flask, request, render_template |
|
|
|
|
|
|
|
|
|
from .. import util |
|
|
|
|
from .. import db |
|
|
|
|
@ -20,7 +19,6 @@ from .. import db
|
|
|
|
|
#################### |
|
|
|
|
# constants |
|
|
|
|
|
|
|
|
|
bp = Blueprint('tmdb', __name__, url_prefix='/tmdb') |
|
|
|
|
TMDB_API_URL = 'https://api.themoviedb.org' |
|
|
|
|
TMDB_SEARCH_MOVIE = '/3/search/movie' |
|
|
|
|
TMDB_SEARCH_TV = '/3/search/tv' |
|
|
|
|
@ -28,6 +26,13 @@ TMDB_MOVIE_LINK_URL = 'https://www.themoviedb.org/movie/'
|
|
|
|
|
TMDB_TV_LINK_URL = 'https://www.themoviedb.org/tv/' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#################### |
|
|
|
|
# globals |
|
|
|
|
|
|
|
|
|
bp = Blueprint('tmdb', __name__, url_prefix='/tmdb') |
|
|
|
|
logger = util.getLogger(Flask(__name__).config['DEBUG']) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#################### |
|
|
|
|
# data structures |
|
|
|
|
|
|
|
|
|
@ -90,6 +95,10 @@ class view_result(object):
|
|
|
|
|
|
|
|
|
|
@bp.route('/query_movie') |
|
|
|
|
def query_movie(): |
|
|
|
|
|
|
|
|
|
logger.debug('Flask(__name__): {}'.format(Flask(__name__))) |
|
|
|
|
logger.debug('debug: {}'.format(Flask(__name__).config['DEBUG'])) |
|
|
|
|
|
|
|
|
|
errors = [] |
|
|
|
|
query = query_data() |
|
|
|
|
response = response_data() |
|
|
|
|
@ -174,7 +183,7 @@ def isQueryCached(query_str):
|
|
|
|
|
cur.execute('SELECT COUNT(*) FROM movie_queries WHERE query=?', (query_str,)) |
|
|
|
|
count = cur.fetchone()[0] |
|
|
|
|
|
|
|
|
|
print('DEBUG: {}, count: "{}"'.format(util.getFunctionName(), count)) |
|
|
|
|
logger.debug('count: "{}"'.format(count)) |
|
|
|
|
|
|
|
|
|
return (count > 0) |
|
|
|
|
|
|
|
|
|
@ -190,13 +199,11 @@ def makeLocalQuery(query_obj):
|
|
|
|
|
elif query_obj.query_type == query_type.TV_SHOW: |
|
|
|
|
pass |
|
|
|
|
|
|
|
|
|
print('DEBUG: {}, number of rows matched: "{}"'.format( |
|
|
|
|
util.getFunctionName(), len(cur.fetchall())) |
|
|
|
|
) |
|
|
|
|
logger.debug('number of rows matched: "{}"'.format(len(cur.fetchall()))) |
|
|
|
|
|
|
|
|
|
if len(cur.fetchall()) > 0: |
|
|
|
|
print('DEBUG: {}(), query string "{}", match found in local db'.format( |
|
|
|
|
util.getFunctionName(), query_obj.parsed_query_str) |
|
|
|
|
logger.debug('query string "{}", match found in local db'.format( |
|
|
|
|
query_obj.parsed_query_str) |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
for row in cur: |
|
|
|
|
@ -204,8 +211,8 @@ def makeLocalQuery(query_obj):
|
|
|
|
|
vr.title = row["title"] |
|
|
|
|
results.append(vr) |
|
|
|
|
else: |
|
|
|
|
print('DEBUG: {}(), query string "{}", no matches found in local db'.format( |
|
|
|
|
util.getFunctionName(), query_obj.parsed_query_str) |
|
|
|
|
logger.debug('query string "{}", no matches found in local db'.format( |
|
|
|
|
query_obj.parsed_query_str) |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
return results |
|
|
|
|
@ -263,9 +270,7 @@ def storeTMDBQueryResults(query_obj, result_list):
|
|
|
|
|
conn = db.get_db() |
|
|
|
|
cur = conn.cursor() |
|
|
|
|
|
|
|
|
|
print('DEBUG: {}, adding query string "{}" into local cache'.format( |
|
|
|
|
util.getFunctionName(), query_obj.parsed_query_str) |
|
|
|
|
) |
|
|
|
|
logger.debug('adding query string "{}" into local cache'.format(query_obj.parsed_query_str)) |
|
|
|
|
|
|
|
|
|
try: |
|
|
|
|
cur.execute('INSERT INTO movie_queries(query, year) VALUES (?, ?)', |
|
|
|
|
|