From 22013a7b3e3d637523e919c06d3fccde435f7496 Mon Sep 17 00:00:00 2001 From: Marcel Dechert Date: Mon, 18 Apr 2022 22:50:19 +0100 Subject: [PATCH] init with copied files from markdown-tagebuch --- .idea/.gitignore | 137 ++++++++++++++++++++++++ .idea/runConfigurations/rest_server.xml | 24 +++++ README.md | 11 ++ config.yml | 4 + config_parser.py | 20 ++++ config_prod.yml | 5 + requirements.txt | 12 +++ rest_server.py | 56 ++++++++++ templates/base.html | 35 ++++++ templates/index.html | 8 ++ templates/yt.html | 16 +++ 11 files changed, 328 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/runConfigurations/rest_server.xml create mode 100644 config.yml create mode 100644 config_parser.py create mode 100644 config_prod.yml create mode 100644 requirements.txt create mode 100644 rest_server.py create mode 100644 templates/base.html create mode 100644 templates/index.html create mode 100644 templates/yt.html diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..2700692 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,137 @@ +# Default ignored files +/shelf/ +/workspace.xml + +.idea +mdtagebuchenv + +# ---> Python +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ diff --git a/.idea/runConfigurations/rest_server.xml b/.idea/runConfigurations/rest_server.xml new file mode 100644 index 0000000..de74201 --- /dev/null +++ b/.idea/runConfigurations/rest_server.xml @@ -0,0 +1,24 @@ + + + + + \ No newline at end of file diff --git a/README.md b/README.md index db733c6..844a2b1 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,13 @@ # yt2podcast +## Automation + - paste URL into web UI + - trigger download via youtube dl Material API + - upload downloaded file via PodcastGenerator + - https://podcasts.swaghausen.de/admin/episodes_upload.php + - PHP SessId + - OR script to Edit Feed.xml and create xml assoicated with mp3 + +admin +test123 + diff --git a/config.yml b/config.yml new file mode 100644 index 0000000..9445ff4 --- /dev/null +++ b/config.yml @@ -0,0 +1,4 @@ +auth: + username: admin + hashedPassword: pbkdf2:sha256:260000$2xn3u8v9EFHM7oj1$65a9126ae01129a8adc5ca74ec6c006388f3d7f0176d015dccf8e0bf1f5e2523 +prod: False diff --git a/config_parser.py b/config_parser.py new file mode 100644 index 0000000..4eb1eb2 --- /dev/null +++ b/config_parser.py @@ -0,0 +1,20 @@ +import yaml +import os + +DEFAULT_CONFIG_FILE_NAME = "config.yml" + +if os.environ['ENV'] == 'prod': + config_file_to_load = "config_prod.yml" +else: + config_file_to_load = DEFAULT_CONFIG_FILE_NAME + +# BASE_FODLER = "/code/markdowntagebuch" +BASE_FODLER = os.path.dirname(os.path.abspath(__file__)) + +path_to_config = os.path.join(BASE_FODLER, config_file_to_load) +print("opening config file " + path_to_config) +with open(path_to_config, "r") as ymlfile: + cfg = yaml.load(ymlfile, Loader=yaml.FullLoader) + +credentials = cfg["auth"] +prod_mode = cfg["prod"] diff --git a/config_prod.yml b/config_prod.yml new file mode 100644 index 0000000..1f27691 --- /dev/null +++ b/config_prod.yml @@ -0,0 +1,5 @@ +auth: + username: admin + # hashedPassword: pbkdf2:sha256:150000$gWnHgdeJ$778d54af56408b434fdd7151f4d8ea88e1ad7525d47326aa70671962e1f654a1 + hashedPassword: pbkdf2:sha256:260000$2xn3u8v9EFHM7oj1$65a9126ae01129a8adc5ca74ec6c006388f3d7f0176d015dccf8e0bf1f5e2523 +prod: True diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..a4537c0 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,12 @@ +click==8.1.2 +colorama==0.4.4 +Flask==2.1.1 +importlib-metadata==4.11.3 +itsdangerous==2.1.2 +MarkupSafe==2.1.1 +zipp==3.8.0 +Flask-Cors==3.0.10 +Flask-HTTPAuth==4.3.0 +# pin dependency to have werkzeug.security.safe_str_cmp +Werkzeug==2.0.0 +jinja2==3.0.3 diff --git a/rest_server.py b/rest_server.py new file mode 100644 index 0000000..b8bc665 --- /dev/null +++ b/rest_server.py @@ -0,0 +1,56 @@ +import os + +import flask +from flask import render_template +from flask import request +from flask import url_for +from flask_cors import CORS +from flask_httpauth import HTTPBasicAuth +from werkzeug.security import check_password_hash +# import main +# from werkzeug.utils import redirect + +import config_parser + +app = flask.Flask(__name__) +auth = HTTPBasicAuth() +app.config["DEBUG"] = True +CORS(app) + +URL_BASE_PATH = "/" +# URL_BASE_PATH = "/tagebuch" + + +@auth.verify_password +def verify_password(username, password): + if username == config_parser.credentials['username'] and \ + check_password_hash(config_parser.credentials['hashedPassword'], password): + return username + + +@app.route(URL_BASE_PATH + 'home', methods=['GET']) +# @auth.login_required +def api_show_form(): + return render_template("index.html") + + +@app.route(URL_BASE_PATH, methods=['POST', 'GET']) +@auth.login_required +def handle_yt_url(): + if request.method == "POST": + user_input = request.form['ytlink'] + # return redirect(url_for("return_result", ytlink=user_input)) + print(user_input) + return render_template("yt.html") + else: + return render_template("yt.html") + + +if __name__ == '__main__': + flask_options = dict( + host='0.0.0.0', + debug=True, + port=4001, + threaded=True, + ) + app.run(**flask_options) diff --git a/templates/base.html b/templates/base.html new file mode 100644 index 0000000..f17840e --- /dev/null +++ b/templates/base.html @@ -0,0 +1,35 @@ + + + + + + + + + {% block title %} {% endblock %} + + + +
+
+
+

{% block pageHeader %} {% endblock %}

+
+ + +

{% block content %} {% endblock %}

+ + + + + +
+
+
+ + + \ No newline at end of file diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..bd8eec3 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,8 @@ +{% extends "base.html" %} +{% block content %} Home Page {% endblock %} + + + + + + diff --git a/templates/yt.html b/templates/yt.html new file mode 100644 index 0000000..9e94838 --- /dev/null +++ b/templates/yt.html @@ -0,0 +1,16 @@ +{% extends "base.html" %} +{% block title %} Youtube 2 Podcast RSS {% endblock %} +{% block pageHeader %} Youtube 2 Podcast RSS {% endblock %} + + +{% block content %} +

Input youtube URL

+
+

+

+
+{% endblock %} + + + +