Add pyproject.toml

Run isort and block
This commit is contained in:
Matthew Welch 2022-01-23 16:01:19 -08:00
parent 7155240be5
commit ef50a1b7c3
8 changed files with 71 additions and 65 deletions

View File

@ -8,8 +8,8 @@ import pytz
from flask import Blueprint, current_app, make_response, render_template, request
from flask_login import login_required
import func
import database
import func
Comics = Blueprint("comics", __name__, template_folder="templates")

View File

@ -7,8 +7,7 @@ import sqlalchemy
from comicapi.issuestring import IssueString
from flask import current_app
from flask_login import UserMixin, current_user
from sqlalchemy import ARRAY, TIMESTAMP, Boolean, Column, DateTime, Integer, Numeric, String, create_engine, \
func, over, REAL
from sqlalchemy import ARRAY, REAL, TIMESTAMP, Boolean, Column, DateTime, Integer, Numeric, String, create_engine, func, over
from sqlalchemy.dialects.postgresql import BYTEA
from sqlalchemy.exc import IntegrityError
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()
return user_data
else:
data = UserTvMovieData(
(email, tmdb_id, parent_id, time, length, finished, datetime.datetime.now(), extended, directors_cut))
data = UserTvMovieData((email, tmdb_id, parent_id, time, length, finished, datetime.datetime.now(), extended, directors_cut))
session.add(data)
session.commit()
return data
@ -536,8 +534,7 @@ def db_get_all_comics():
def db_get_series_by_publisher(publisher):
session = Session()
result = (
session.query(Comic).filter(Comic.publisher == publisher).order_by(Comic.series, Comic.seriesyear,
Comic.issue).distinct(Comic.series).all()
session.query(Comic).filter(Comic.publisher == publisher).order_by(Comic.series, Comic.seriesyear, Comic.issue).distinct(Comic.series).all()
)
series = result
return series
@ -546,8 +543,7 @@ def db_get_series_by_publisher(publisher):
def db_get_comics_in_series(series, publisher, series_year):
session = Session()
result = (
session.query(Comic).filter(Comic.publisher == publisher, Comic.series == series,
Comic.seriesyear == series_year).order_by(Comic.issue).all()
session.query(Comic).filter(Comic.publisher == publisher, Comic.series == series, Comic.seriesyear == series_year).order_by(Comic.issue).all()
)
comics = result
return comics
@ -568,8 +564,7 @@ def db_get_comic_by_id(comic_id):
def db_get_thumbnail_by_id_page(comic_id, pageNumber):
session = Session()
thumbnail = session.query(ComicThumbnail).filter(ComicThumbnail.comic_id == comic_id,
ComicThumbnail.pagenumber == pageNumber).one_or_none()
thumbnail = session.query(ComicThumbnail).filter(ComicThumbnail.comic_id == comic_id, ComicThumbnail.pagenumber == pageNumber).one_or_none()
return thumbnail
@ -684,16 +679,15 @@ def db_get_all_movies():
movies = session.query(Movie).order_by(Movie.title, Movie.year).all()
if current_user:
email = current_user.email
movies = [(movie,
session.execute("SELECT rpiwebapp.is_movie_finished({}, '{}')".format(movie.tmdb_id, email)).first()[
0]) for movie in movies]
movies = [
(movie, session.execute("SELECT rpiwebapp.is_movie_finished({}, '{}')".format(movie.tmdb_id, email)).first()[0]) for movie in movies
]
return movies
def db_get_movie_by_tmdb_id(tmdb_id, extended=False, directors_cut=False):
session = Session()
result = session.query(Movie).filter(Movie.tmdb_id == tmdb_id, Movie.extended == extended,
Movie.directors_cut == directors_cut).one_or_none()
result = session.query(Movie).filter(Movie.tmdb_id == tmdb_id, Movie.extended == extended, Movie.directors_cut == directors_cut).one_or_none()
return result
@ -709,12 +703,8 @@ def get_all_tv_movies():
shows = session.query(TvShow).order_by(TvShow.title, TvShow.year).all()
if current_user:
email = current_user.email
shows = [
(i, session.execute("SELECT rpiwebapp.is_tv_show_finished({}, '{}')".format(i.tmdb_id, email)).first()[0])
for i in shows]
movies = [
(i, session.execute("SELECT rpiwebapp.is_movie_finished({}, '{}')".format(i.tmdb_id, email)).first()[0]) for
i in movies]
shows = [(i, session.execute("SELECT rpiwebapp.is_tv_show_finished({}, '{}')".format(i.tmdb_id, email)).first()[0]) 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 = sorted(tv_movies, key=tv_movie_sort)
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):
session = Session()
result = session.query(Movie).filter(Movie.tmdb_id == tmdb_id, Movie.extended == extended,
Movie.directors_cut == directors_cut).one_or_none()
result = session.query(Movie).filter(Movie.tmdb_id == tmdb_id, Movie.extended == extended, Movie.directors_cut == directors_cut).one_or_none()
if not result:
result = session.query(TvShow).filter(TvShow.tmdb_id == tmdb_id).one_or_none()
return result
@ -738,9 +727,7 @@ def get_all_tv_shows():
result = session.query(TvShow).order_by(TvShow.title, TvShow.year).all()
if current_user:
email = current_user.email
shows = [
(i, session.execute("SELECT rpiwebapp.is_tv_show_finished({}, {})".format(i.tmdb_id, email)).first()[0]) for
i in result]
shows = [(i, session.execute("SELECT rpiwebapp.is_tv_show_finished({}, {})".format(i.tmdb_id, email)).first()[0]) for i in result]
else:
shows = result
return shows
@ -754,8 +741,7 @@ def get_tv_show(tmdb_id):
def get_tv_show_episodes_by_tmdb_id(tmdb_id):
session = Session()
result = session.query(TvEpisode).filter(TvEpisode.parent_tmdb_id == tmdb_id).order_by(TvEpisode.season,
TvEpisode.episode).all()
result = session.query(TvEpisode).filter(TvEpisode.parent_tmdb_id == tmdb_id).order_by(TvEpisode.season, TvEpisode.episode).all()
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:
session = Session()
email = current_user.email
result = session.query(UserTvMovieData).filter(UserTvMovieData.user == email,
UserTvMovieData.parent_tmdb == parent_tmdb_id).all()
result = session.query(UserTvMovieData).filter(UserTvMovieData.user == email, UserTvMovieData.parent_tmdb == parent_tmdb_id).all()
return result
def db_get_current_tv_show_episode_and_data(parent_tmdb_id, episodes):
session = Session()
email = current_user.email
result = session.query(UserTvMovieData).filter(UserTvMovieData.user == email,
UserTvMovieData.parent_tmdb == parent_tmdb_id).all()
result = session.query(UserTvMovieData).filter(UserTvMovieData.user == email, UserTvMovieData.parent_tmdb == parent_tmdb_id).all()
if not result:
return episodes[0], None
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])
series_results = db_search_table_columns_by_query(
query, Comic, [Comic.publisher, Comic.title, Comic.series, Comic.year], group=[Comic.series, Comic.seriesyear],
order=[Comic.issue]
query, Comic, [Comic.publisher, Comic.title, Comic.series, Comic.year], group=[Comic.series, Comic.seriesyear], order=[Comic.issue]
)
for row in results["publisher"]:
if row["publisher"] not in publishers:
@ -893,8 +876,7 @@ def db_search_comics(query):
def db_search_movies(query):
results = db_search_table_columns_by_query(query, Movie, [Movie.title, Movie.year, Movie.description],
order=[Movie.title])
results = db_search_table_columns_by_query(query, Movie, [Movie.title, Movie.year, Movie.description], order=[Movie.title])
movies = []
for movie in results["title"]:
if movie not in movies:
@ -907,15 +889,13 @@ def db_search_movies(query):
movies.append(movie)
session = Session()
email = current_user.email
movies = [(i, session.execute("SELECT rpiwebapp.is_movie_finished({}, '{}')".format(i.tmdb_id, email)).first()[0])
for i in movies]
movies = [(i, session.execute("SELECT rpiwebapp.is_movie_finished({}, '{}')".format(i.tmdb_id, email)).first()[0]) for i in movies]
return movies
def db_search_tv_shows(query):
results = db_search_table_columns_by_query(query, TvShow, [TvShow.title, TvShow.year, TvShow.description],
order=[TvShow.title])
results = db_search_table_columns_by_query(query, TvShow, [TvShow.title, TvShow.year, TvShow.description], order=[TvShow.title])
tv_shows = []
for show in results["title"]:
if show not in tv_shows:
@ -928,8 +908,7 @@ def db_search_tv_shows(query):
tv_shows.append(show)
session = Session()
email = current_user.email
shows = [(i, session.execute("SELECT rpiwebapp.is_tv_show_finished({}, '{}')".format(i.tmdb_id, email)).first()[0])
for i in tv_shows]
shows = [(i, session.execute("SELECT rpiwebapp.is_tv_show_finished({}, '{}')".format(i.tmdb_id, email)).first()[0]) for i in tv_shows]
return shows

37
func.py
View File

@ -3,10 +3,11 @@ import json
import os
import pathlib
import re
from datetime import timedelta
import enzyme
import pathvalidate
import requests
from datetime import timedelta
from blinker import Namespace
from comicapi import comicarchive
from flask import current_app
@ -173,7 +174,20 @@ def get_movie(absolute_path: pathlib.Path):
poster_path = info["poster_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())
current_app.logger.info("finish loading movie")
result["added"] = 1
@ -225,14 +239,14 @@ def get_tv_shows():
tmdb_id = info["id"]
description = info["overview"]
poster_path = info["poster_path"]
tv_show_data = (
tv_show_data = [
tmdb_id,
series_name,
series_year,
description,
poster_path,
str(relative_path),
)
]
tv_show_loaded.send("anonymous", tv_show=tv_show_data)
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_still_path = info["still_path"]
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)
current_app.logger.info("finished loading tv episode")
@ -405,7 +428,7 @@ def get_game(path: pathlib.Path):
mac = True
if "linux" in info.keys():
linux = True
game = (
game = [
info["name"],
game_id,
description,
@ -415,7 +438,7 @@ def get_game(path: pathlib.Path):
mac,
linux,
pathvalidate.sanitize_filename(info["name"]),
)
]
games.append(game)
games_loaded.send("anonymous", games=games)
current_app.logger.info(f"finished loading game: {info['name']}:{info['id']}")

5
pyproject.toml Normal file
View File

@ -0,0 +1,5 @@
[tool.black]
line-length = 150
[tool.isort]
line_length = 150

View File

@ -3,7 +3,6 @@ import datetime
import inspect
import json
import logging
import os
import pathlib
import threading
from urllib.parse import urljoin, urlsplit, urlunsplit
@ -11,16 +10,16 @@ from urllib.parse import urljoin, urlsplit, urlunsplit
import inotify.adapters
import inotify.constants
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 oauthlib.oauth2 import WebApplicationClient
from werkzeug.middleware.proxy_fix import ProxyFix
import database
import func
from admin import admin
from comics import comics
from games import games
import database
from tv_movies import tv_movies
@ -84,7 +83,6 @@ def get_comics():
new_dirs.clear()
def get_movies():
with app.app_context():
i = inotify.adapters.InotifyTree(str(func.MOVIES_DIRECTORY))

View File

@ -1,5 +1,6 @@
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_MOVIES_DIRECTORY = Path("/usb/storage/media/Videos/Movies/")

View File

@ -1,11 +1,11 @@
import datetime
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
import func
import database
import func
TV_Movies = Blueprint("tv_movies", __name__, template_folder="templates")