introduced: requirements.txt, colored output (with ANSI escape codes), baked in failsafe when config file does not exist, slight improvements to ythdd.py

This commit is contained in:
2024-11-02 01:21:06 +01:00
parent 1fb14a5718
commit c60f7db698
3 changed files with 62 additions and 15 deletions

View File

@@ -2,17 +2,19 @@
from flask import Flask, render_template
from flask_sqlalchemy import SQLAlchemy
from markupsafe import escape
#from argparse import ArgumentParser
from ythdd_globals import config, colors
import requests, json, toml, time
import views, downloader, ythdd_api, ythdd_globals, ythdd_db
ythdd_globals.starttime = int(time.time())
ythdd_globals.apiRequests = 0
ythdd_globals.apiFailedRequests = 0
ythdd_globals.isProxied = ythdd_globals.config['general']['is_proxied']
ythdd_globals.isProxied = config['general']['is_proxied']
ythdd_globals.outsideApiHits = 0
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = f"sqlite:///{ythdd_globals.config["general"]["db_file_path"]}"
app.config['SQLALCHEMY_DATABASE_URI'] = f"sqlite:///{config['general']['db_file_path']}"
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.add_url_rule('/', view_func=views.index)
app.add_url_rule('/index.html', view_func=views.index)
@@ -30,11 +32,23 @@ def blank(val):
#users = db.session.query(LocalUsers).all()
#return users
def main():
print(f"{colors.BOLD + colors.HEADER}Welcome to ythdd ({ythdd_globals.version})!{colors.ENDC}")
print(f"To run in development mode (to see changes updated live), use: {colors.OKCYAN}flask --app ythdd run --debug{colors.ENDC}.")
print("To run locally, use IP 127.0.0.1. To run on all interfaces, use 0.0.0.0.\n")
print("Enter hostname:port to run Flask app on [127.0.0.1:5000]:")
try:
host_port = input('> ').split(':')
if host_port == ['']:
host_port = ['127.0.0.1', '5000'] # defaults
except KeyboardInterrupt:
print(" ...exiting gracefully."), quit() # handle Ctrl+C
app.run(host=host_port[0], port=int(host_port[1]))
if __name__ == "__main__":
print("welcome to ythdd")
print("to run locally, use ip 127.0.0.1. to run on all interfaces, use 0.0.0.0.")
print("enter hostname:port to run flask app on:")
host_port = input('> ').split(':')
#app.run(host="127.0.0.1", port=5000)
#app.run(host="0.0.0.0", port=5000)
app.run(host=host_port[0], port=int(host_port[1]))
# TODO: add argument parser to load config files, etc.
main()