55 lines
2.0 KiB
Python
55 lines
2.0 KiB
Python
#!/usr/bin/python3
|
|
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 = config['general']['is_proxied']
|
|
ythdd_globals.outsideApiHits = 0
|
|
|
|
app = Flask(__name__)
|
|
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)
|
|
app.add_url_rule('/home', view_func=views.home)
|
|
app.add_url_rule('/api/', view_func=ythdd_api.api_greeting)
|
|
app.add_url_rule('/api/<path:received_request>', view_func=ythdd_api.api_global_catchall)
|
|
db = ythdd_db.initDB(app)
|
|
|
|
with app.app_context():
|
|
db.create_all()
|
|
|
|
@app.route('/<string:val>', methods=['GET'])
|
|
def blank(val):
|
|
return f"{val}: not implemented in ythdd {ythdd_globals.version}"
|
|
#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__":
|
|
#app.run(host="127.0.0.1", port=5000)
|
|
#app.run(host="0.0.0.0", port=5000)
|
|
# TODO: add argument parser to load config files, etc.
|
|
main()
|