Add pyproject.toml
Run isort and block
This commit is contained in:
parent
7155240be5
commit
ef50a1b7c3
@ -8,8 +8,8 @@ import pytz
|
|||||||
from flask import Blueprint, current_app, make_response, render_template, request
|
from flask import Blueprint, current_app, make_response, render_template, request
|
||||||
from flask_login import login_required
|
from flask_login import login_required
|
||||||
|
|
||||||
import func
|
|
||||||
import database
|
import database
|
||||||
|
import func
|
||||||
|
|
||||||
Comics = Blueprint("comics", __name__, template_folder="templates")
|
Comics = Blueprint("comics", __name__, template_folder="templates")
|
||||||
|
|
||||||
|
63
database.py
63
database.py
@ -7,8 +7,7 @@ import sqlalchemy
|
|||||||
from comicapi.issuestring import IssueString
|
from comicapi.issuestring import IssueString
|
||||||
from flask import current_app
|
from flask import current_app
|
||||||
from flask_login import UserMixin, current_user
|
from flask_login import UserMixin, current_user
|
||||||
from sqlalchemy import ARRAY, TIMESTAMP, Boolean, Column, DateTime, Integer, Numeric, String, create_engine, \
|
from sqlalchemy import ARRAY, REAL, TIMESTAMP, Boolean, Column, DateTime, Integer, Numeric, String, create_engine, func, over
|
||||||
func, over, REAL
|
|
||||||
from sqlalchemy.dialects.postgresql import BYTEA
|
from sqlalchemy.dialects.postgresql import BYTEA
|
||||||
from sqlalchemy.exc import IntegrityError
|
from sqlalchemy.exc import IntegrityError
|
||||||
from sqlalchemy.ext.declarative import declarative_base
|
from sqlalchemy.ext.declarative import declarative_base
|
||||||
@ -384,8 +383,7 @@ def update_user_tv_movie_data(tmdb_id, parent_id, time, length, finished=False,
|
|||||||
session.commit()
|
session.commit()
|
||||||
return user_data
|
return user_data
|
||||||
else:
|
else:
|
||||||
data = UserTvMovieData(
|
data = UserTvMovieData((email, tmdb_id, parent_id, time, length, finished, datetime.datetime.now(), extended, directors_cut))
|
||||||
(email, tmdb_id, parent_id, time, length, finished, datetime.datetime.now(), extended, directors_cut))
|
|
||||||
session.add(data)
|
session.add(data)
|
||||||
session.commit()
|
session.commit()
|
||||||
return data
|
return data
|
||||||
@ -536,8 +534,7 @@ def db_get_all_comics():
|
|||||||
def db_get_series_by_publisher(publisher):
|
def db_get_series_by_publisher(publisher):
|
||||||
session = Session()
|
session = Session()
|
||||||
result = (
|
result = (
|
||||||
session.query(Comic).filter(Comic.publisher == publisher).order_by(Comic.series, Comic.seriesyear,
|
session.query(Comic).filter(Comic.publisher == publisher).order_by(Comic.series, Comic.seriesyear, Comic.issue).distinct(Comic.series).all()
|
||||||
Comic.issue).distinct(Comic.series).all()
|
|
||||||
)
|
)
|
||||||
series = result
|
series = result
|
||||||
return series
|
return series
|
||||||
@ -546,8 +543,7 @@ def db_get_series_by_publisher(publisher):
|
|||||||
def db_get_comics_in_series(series, publisher, series_year):
|
def db_get_comics_in_series(series, publisher, series_year):
|
||||||
session = Session()
|
session = Session()
|
||||||
result = (
|
result = (
|
||||||
session.query(Comic).filter(Comic.publisher == publisher, Comic.series == series,
|
session.query(Comic).filter(Comic.publisher == publisher, Comic.series == series, Comic.seriesyear == series_year).order_by(Comic.issue).all()
|
||||||
Comic.seriesyear == series_year).order_by(Comic.issue).all()
|
|
||||||
)
|
)
|
||||||
comics = result
|
comics = result
|
||||||
return comics
|
return comics
|
||||||
@ -568,8 +564,7 @@ def db_get_comic_by_id(comic_id):
|
|||||||
|
|
||||||
def db_get_thumbnail_by_id_page(comic_id, pageNumber):
|
def db_get_thumbnail_by_id_page(comic_id, pageNumber):
|
||||||
session = Session()
|
session = Session()
|
||||||
thumbnail = session.query(ComicThumbnail).filter(ComicThumbnail.comic_id == comic_id,
|
thumbnail = session.query(ComicThumbnail).filter(ComicThumbnail.comic_id == comic_id, ComicThumbnail.pagenumber == pageNumber).one_or_none()
|
||||||
ComicThumbnail.pagenumber == pageNumber).one_or_none()
|
|
||||||
return thumbnail
|
return thumbnail
|
||||||
|
|
||||||
|
|
||||||
@ -684,16 +679,15 @@ def db_get_all_movies():
|
|||||||
movies = session.query(Movie).order_by(Movie.title, Movie.year).all()
|
movies = session.query(Movie).order_by(Movie.title, Movie.year).all()
|
||||||
if current_user:
|
if current_user:
|
||||||
email = current_user.email
|
email = current_user.email
|
||||||
movies = [(movie,
|
movies = [
|
||||||
session.execute("SELECT rpiwebapp.is_movie_finished({}, '{}')".format(movie.tmdb_id, email)).first()[
|
(movie, session.execute("SELECT rpiwebapp.is_movie_finished({}, '{}')".format(movie.tmdb_id, email)).first()[0]) for movie in movies
|
||||||
0]) for movie in movies]
|
]
|
||||||
return movies
|
return movies
|
||||||
|
|
||||||
|
|
||||||
def db_get_movie_by_tmdb_id(tmdb_id, extended=False, directors_cut=False):
|
def db_get_movie_by_tmdb_id(tmdb_id, extended=False, directors_cut=False):
|
||||||
session = Session()
|
session = Session()
|
||||||
result = session.query(Movie).filter(Movie.tmdb_id == tmdb_id, Movie.extended == extended,
|
result = session.query(Movie).filter(Movie.tmdb_id == tmdb_id, Movie.extended == extended, Movie.directors_cut == directors_cut).one_or_none()
|
||||||
Movie.directors_cut == directors_cut).one_or_none()
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
@ -709,12 +703,8 @@ def get_all_tv_movies():
|
|||||||
shows = session.query(TvShow).order_by(TvShow.title, TvShow.year).all()
|
shows = session.query(TvShow).order_by(TvShow.title, TvShow.year).all()
|
||||||
if current_user:
|
if current_user:
|
||||||
email = current_user.email
|
email = current_user.email
|
||||||
shows = [
|
shows = [(i, session.execute("SELECT rpiwebapp.is_tv_show_finished({}, '{}')".format(i.tmdb_id, email)).first()[0]) for i in shows]
|
||||||
(i, session.execute("SELECT rpiwebapp.is_tv_show_finished({}, '{}')".format(i.tmdb_id, email)).first()[0])
|
movies = [(i, session.execute("SELECT rpiwebapp.is_movie_finished({}, '{}')".format(i.tmdb_id, email)).first()[0]) for i in movies]
|
||||||
for i in shows]
|
|
||||||
movies = [
|
|
||||||
(i, session.execute("SELECT rpiwebapp.is_movie_finished({}, '{}')".format(i.tmdb_id, email)).first()[0]) for
|
|
||||||
i in movies]
|
|
||||||
tv_movies = movies + shows
|
tv_movies = movies + shows
|
||||||
tv_movies = sorted(tv_movies, key=tv_movie_sort)
|
tv_movies = sorted(tv_movies, key=tv_movie_sort)
|
||||||
return tv_movies
|
return tv_movies
|
||||||
@ -722,8 +712,7 @@ def get_all_tv_movies():
|
|||||||
|
|
||||||
def get_tv_movie_by_tmdb_id(tmdb_id, extended=False, directors_cut=False):
|
def get_tv_movie_by_tmdb_id(tmdb_id, extended=False, directors_cut=False):
|
||||||
session = Session()
|
session = Session()
|
||||||
result = session.query(Movie).filter(Movie.tmdb_id == tmdb_id, Movie.extended == extended,
|
result = session.query(Movie).filter(Movie.tmdb_id == tmdb_id, Movie.extended == extended, Movie.directors_cut == directors_cut).one_or_none()
|
||||||
Movie.directors_cut == directors_cut).one_or_none()
|
|
||||||
if not result:
|
if not result:
|
||||||
result = session.query(TvShow).filter(TvShow.tmdb_id == tmdb_id).one_or_none()
|
result = session.query(TvShow).filter(TvShow.tmdb_id == tmdb_id).one_or_none()
|
||||||
return result
|
return result
|
||||||
@ -738,9 +727,7 @@ def get_all_tv_shows():
|
|||||||
result = session.query(TvShow).order_by(TvShow.title, TvShow.year).all()
|
result = session.query(TvShow).order_by(TvShow.title, TvShow.year).all()
|
||||||
if current_user:
|
if current_user:
|
||||||
email = current_user.email
|
email = current_user.email
|
||||||
shows = [
|
shows = [(i, session.execute("SELECT rpiwebapp.is_tv_show_finished({}, {})".format(i.tmdb_id, email)).first()[0]) for i in result]
|
||||||
(i, session.execute("SELECT rpiwebapp.is_tv_show_finished({}, {})".format(i.tmdb_id, email)).first()[0]) for
|
|
||||||
i in result]
|
|
||||||
else:
|
else:
|
||||||
shows = result
|
shows = result
|
||||||
return shows
|
return shows
|
||||||
@ -754,8 +741,7 @@ def get_tv_show(tmdb_id):
|
|||||||
|
|
||||||
def get_tv_show_episodes_by_tmdb_id(tmdb_id):
|
def get_tv_show_episodes_by_tmdb_id(tmdb_id):
|
||||||
session = Session()
|
session = Session()
|
||||||
result = session.query(TvEpisode).filter(TvEpisode.parent_tmdb_id == tmdb_id).order_by(TvEpisode.season,
|
result = session.query(TvEpisode).filter(TvEpisode.parent_tmdb_id == tmdb_id).order_by(TvEpisode.season, TvEpisode.episode).all()
|
||||||
TvEpisode.episode).all()
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
@ -784,16 +770,14 @@ def db_get_user_tv_movie_data(tmdb_id, extended=False, directors_cut=False):
|
|||||||
def db_get_user_tv_show_episodes_data(parent_tmdb_id) -> list:
|
def db_get_user_tv_show_episodes_data(parent_tmdb_id) -> list:
|
||||||
session = Session()
|
session = Session()
|
||||||
email = current_user.email
|
email = current_user.email
|
||||||
result = session.query(UserTvMovieData).filter(UserTvMovieData.user == email,
|
result = session.query(UserTvMovieData).filter(UserTvMovieData.user == email, UserTvMovieData.parent_tmdb == parent_tmdb_id).all()
|
||||||
UserTvMovieData.parent_tmdb == parent_tmdb_id).all()
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def db_get_current_tv_show_episode_and_data(parent_tmdb_id, episodes):
|
def db_get_current_tv_show_episode_and_data(parent_tmdb_id, episodes):
|
||||||
session = Session()
|
session = Session()
|
||||||
email = current_user.email
|
email = current_user.email
|
||||||
result = session.query(UserTvMovieData).filter(UserTvMovieData.user == email,
|
result = session.query(UserTvMovieData).filter(UserTvMovieData.user == email, UserTvMovieData.parent_tmdb == parent_tmdb_id).all()
|
||||||
UserTvMovieData.parent_tmdb == parent_tmdb_id).all()
|
|
||||||
if not result:
|
if not result:
|
||||||
return episodes[0], None
|
return episodes[0], None
|
||||||
most_recent_data = result[0]
|
most_recent_data = result[0]
|
||||||
@ -873,8 +857,7 @@ def db_search_comics(query):
|
|||||||
|
|
||||||
results = db_search_table_columns_by_query(query, Comic, [Comic.publisher, Comic.title, Comic.series, Comic.year])
|
results = db_search_table_columns_by_query(query, Comic, [Comic.publisher, Comic.title, Comic.series, Comic.year])
|
||||||
series_results = db_search_table_columns_by_query(
|
series_results = db_search_table_columns_by_query(
|
||||||
query, Comic, [Comic.publisher, Comic.title, Comic.series, Comic.year], group=[Comic.series, Comic.seriesyear],
|
query, Comic, [Comic.publisher, Comic.title, Comic.series, Comic.year], group=[Comic.series, Comic.seriesyear], order=[Comic.issue]
|
||||||
order=[Comic.issue]
|
|
||||||
)
|
)
|
||||||
for row in results["publisher"]:
|
for row in results["publisher"]:
|
||||||
if row["publisher"] not in publishers:
|
if row["publisher"] not in publishers:
|
||||||
@ -893,8 +876,7 @@ def db_search_comics(query):
|
|||||||
|
|
||||||
|
|
||||||
def db_search_movies(query):
|
def db_search_movies(query):
|
||||||
results = db_search_table_columns_by_query(query, Movie, [Movie.title, Movie.year, Movie.description],
|
results = db_search_table_columns_by_query(query, Movie, [Movie.title, Movie.year, Movie.description], order=[Movie.title])
|
||||||
order=[Movie.title])
|
|
||||||
movies = []
|
movies = []
|
||||||
for movie in results["title"]:
|
for movie in results["title"]:
|
||||||
if movie not in movies:
|
if movie not in movies:
|
||||||
@ -907,15 +889,13 @@ def db_search_movies(query):
|
|||||||
movies.append(movie)
|
movies.append(movie)
|
||||||
session = Session()
|
session = Session()
|
||||||
email = current_user.email
|
email = current_user.email
|
||||||
movies = [(i, session.execute("SELECT rpiwebapp.is_movie_finished({}, '{}')".format(i.tmdb_id, email)).first()[0])
|
movies = [(i, session.execute("SELECT rpiwebapp.is_movie_finished({}, '{}')".format(i.tmdb_id, email)).first()[0]) for i in movies]
|
||||||
for i in movies]
|
|
||||||
|
|
||||||
return movies
|
return movies
|
||||||
|
|
||||||
|
|
||||||
def db_search_tv_shows(query):
|
def db_search_tv_shows(query):
|
||||||
results = db_search_table_columns_by_query(query, TvShow, [TvShow.title, TvShow.year, TvShow.description],
|
results = db_search_table_columns_by_query(query, TvShow, [TvShow.title, TvShow.year, TvShow.description], order=[TvShow.title])
|
||||||
order=[TvShow.title])
|
|
||||||
tv_shows = []
|
tv_shows = []
|
||||||
for show in results["title"]:
|
for show in results["title"]:
|
||||||
if show not in tv_shows:
|
if show not in tv_shows:
|
||||||
@ -928,8 +908,7 @@ def db_search_tv_shows(query):
|
|||||||
tv_shows.append(show)
|
tv_shows.append(show)
|
||||||
session = Session()
|
session = Session()
|
||||||
email = current_user.email
|
email = current_user.email
|
||||||
shows = [(i, session.execute("SELECT rpiwebapp.is_tv_show_finished({}, '{}')".format(i.tmdb_id, email)).first()[0])
|
shows = [(i, session.execute("SELECT rpiwebapp.is_tv_show_finished({}, '{}')".format(i.tmdb_id, email)).first()[0]) for i in tv_shows]
|
||||||
for i in tv_shows]
|
|
||||||
return shows
|
return shows
|
||||||
|
|
||||||
|
|
||||||
|
37
func.py
37
func.py
@ -3,10 +3,11 @@ import json
|
|||||||
import os
|
import os
|
||||||
import pathlib
|
import pathlib
|
||||||
import re
|
import re
|
||||||
|
from datetime import timedelta
|
||||||
|
|
||||||
import enzyme
|
import enzyme
|
||||||
import pathvalidate
|
import pathvalidate
|
||||||
import requests
|
import requests
|
||||||
from datetime import timedelta
|
|
||||||
from blinker import Namespace
|
from blinker import Namespace
|
||||||
from comicapi import comicarchive
|
from comicapi import comicarchive
|
||||||
from flask import current_app
|
from flask import current_app
|
||||||
@ -173,7 +174,20 @@ def get_movie(absolute_path: pathlib.Path):
|
|||||||
poster_path = info["poster_path"]
|
poster_path = info["poster_path"]
|
||||||
backdrop_path = info["backdrop_path"]
|
backdrop_path = info["backdrop_path"]
|
||||||
|
|
||||||
movies.append((str(relative_path), tmdb_id, title, year, description, extended, directors_cut, poster_path, backdrop_path, res_4k,))
|
movies.append(
|
||||||
|
[
|
||||||
|
str(relative_path),
|
||||||
|
tmdb_id,
|
||||||
|
title,
|
||||||
|
year,
|
||||||
|
description,
|
||||||
|
extended,
|
||||||
|
directors_cut,
|
||||||
|
poster_path,
|
||||||
|
backdrop_path,
|
||||||
|
res_4k,
|
||||||
|
]
|
||||||
|
)
|
||||||
movie_loaded.send("anonymous", movies=movies.copy())
|
movie_loaded.send("anonymous", movies=movies.copy())
|
||||||
current_app.logger.info("finish loading movie")
|
current_app.logger.info("finish loading movie")
|
||||||
result["added"] = 1
|
result["added"] = 1
|
||||||
@ -225,14 +239,14 @@ def get_tv_shows():
|
|||||||
tmdb_id = info["id"]
|
tmdb_id = info["id"]
|
||||||
description = info["overview"]
|
description = info["overview"]
|
||||||
poster_path = info["poster_path"]
|
poster_path = info["poster_path"]
|
||||||
tv_show_data = (
|
tv_show_data = [
|
||||||
tmdb_id,
|
tmdb_id,
|
||||||
series_name,
|
series_name,
|
||||||
series_year,
|
series_year,
|
||||||
description,
|
description,
|
||||||
poster_path,
|
poster_path,
|
||||||
str(relative_path),
|
str(relative_path),
|
||||||
)
|
]
|
||||||
tv_show_loaded.send("anonymous", tv_show=tv_show_data)
|
tv_show_loaded.send("anonymous", tv_show=tv_show_data)
|
||||||
current_app.logger.info("finished loading tv shows.")
|
current_app.logger.info("finished loading tv shows.")
|
||||||
|
|
||||||
@ -279,7 +293,16 @@ def get_tv_episode(absolute_path: pathlib.Path):
|
|||||||
episode_description = info["overview"]
|
episode_description = info["overview"]
|
||||||
episode_still_path = info["still_path"]
|
episode_still_path = info["still_path"]
|
||||||
episodes.append(
|
episodes.append(
|
||||||
(episode_tmdb_id, tv_show.tmdb_id, episode_name, season, episode, episode_description, episode_still_path, str(relative_path),)
|
[
|
||||||
|
episode_tmdb_id,
|
||||||
|
tv_show.tmdb_id,
|
||||||
|
episode_name,
|
||||||
|
season,
|
||||||
|
episode,
|
||||||
|
episode_description,
|
||||||
|
episode_still_path,
|
||||||
|
str(relative_path),
|
||||||
|
]
|
||||||
)
|
)
|
||||||
tv_episodes_loaded.send("anonymous", tv_episodes=episodes)
|
tv_episodes_loaded.send("anonymous", tv_episodes=episodes)
|
||||||
current_app.logger.info("finished loading tv episode")
|
current_app.logger.info("finished loading tv episode")
|
||||||
@ -405,7 +428,7 @@ def get_game(path: pathlib.Path):
|
|||||||
mac = True
|
mac = True
|
||||||
if "linux" in info.keys():
|
if "linux" in info.keys():
|
||||||
linux = True
|
linux = True
|
||||||
game = (
|
game = [
|
||||||
info["name"],
|
info["name"],
|
||||||
game_id,
|
game_id,
|
||||||
description,
|
description,
|
||||||
@ -415,7 +438,7 @@ def get_game(path: pathlib.Path):
|
|||||||
mac,
|
mac,
|
||||||
linux,
|
linux,
|
||||||
pathvalidate.sanitize_filename(info["name"]),
|
pathvalidate.sanitize_filename(info["name"]),
|
||||||
)
|
]
|
||||||
games.append(game)
|
games.append(game)
|
||||||
games_loaded.send("anonymous", games=games)
|
games_loaded.send("anonymous", games=games)
|
||||||
current_app.logger.info(f"finished loading game: {info['name']}:{info['id']}")
|
current_app.logger.info(f"finished loading game: {info['name']}:{info['id']}")
|
||||||
|
5
pyproject.toml
Normal file
5
pyproject.toml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
[tool.black]
|
||||||
|
line-length = 150
|
||||||
|
|
||||||
|
[tool.isort]
|
||||||
|
line_length = 150
|
@ -3,7 +3,6 @@ import datetime
|
|||||||
import inspect
|
import inspect
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
|
||||||
import pathlib
|
import pathlib
|
||||||
import threading
|
import threading
|
||||||
from urllib.parse import urljoin, urlsplit, urlunsplit
|
from urllib.parse import urljoin, urlsplit, urlunsplit
|
||||||
@ -11,16 +10,16 @@ from urllib.parse import urljoin, urlsplit, urlunsplit
|
|||||||
import inotify.adapters
|
import inotify.adapters
|
||||||
import inotify.constants
|
import inotify.constants
|
||||||
import requests
|
import requests
|
||||||
from flask import Flask, Response, current_app, flash, g, redirect, render_template, request, url_for, make_response
|
from flask import Flask, Response, current_app, flash, g, make_response, redirect, render_template, request, url_for
|
||||||
from flask_login import LoginManager, current_user, login_required, login_user, logout_user
|
from flask_login import LoginManager, current_user, login_required, login_user, logout_user
|
||||||
from oauthlib.oauth2 import WebApplicationClient
|
from oauthlib.oauth2 import WebApplicationClient
|
||||||
from werkzeug.middleware.proxy_fix import ProxyFix
|
from werkzeug.middleware.proxy_fix import ProxyFix
|
||||||
|
|
||||||
|
import database
|
||||||
import func
|
import func
|
||||||
from admin import admin
|
from admin import admin
|
||||||
from comics import comics
|
from comics import comics
|
||||||
from games import games
|
from games import games
|
||||||
import database
|
|
||||||
from tv_movies import tv_movies
|
from tv_movies import tv_movies
|
||||||
|
|
||||||
|
|
||||||
@ -84,7 +83,6 @@ def get_comics():
|
|||||||
new_dirs.clear()
|
new_dirs.clear()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_movies():
|
def get_movies():
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
i = inotify.adapters.InotifyTree(str(func.MOVIES_DIRECTORY))
|
i = inotify.adapters.InotifyTree(str(func.MOVIES_DIRECTORY))
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from database import Session, Comic, Movie, TvShow, Game, TvEpisode, DupComic
|
|
||||||
|
from database import Comic, DupComic, Game, Movie, Session, TvEpisode, TvShow
|
||||||
|
|
||||||
OLD_COMICS_DIRECTORY = Path("/usb/storage/media/Comics/")
|
OLD_COMICS_DIRECTORY = Path("/usb/storage/media/Comics/")
|
||||||
OLD_MOVIES_DIRECTORY = Path("/usb/storage/media/Videos/Movies/")
|
OLD_MOVIES_DIRECTORY = Path("/usb/storage/media/Videos/Movies/")
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
import datetime
|
import datetime
|
||||||
import inspect
|
import inspect
|
||||||
|
|
||||||
from flask import Blueprint, current_app, make_response, render_template, request, send_from_directory, abort
|
from flask import Blueprint, abort, current_app, make_response, render_template, request, send_from_directory
|
||||||
from flask_login import login_required
|
from flask_login import login_required
|
||||||
|
|
||||||
import func
|
|
||||||
import database
|
import database
|
||||||
|
import func
|
||||||
|
|
||||||
TV_Movies = Blueprint("tv_movies", __name__, template_folder="templates")
|
TV_Movies = Blueprint("tv_movies", __name__, template_folder="templates")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user