diff options
author | Dylan Garrett <dylan.garrett@gmail.com> | 2021-06-06 15:42:03 -0700 |
---|---|---|
committer | Dylan Garrett <dylan.garrett@gmail.com> | 2021-06-06 15:42:03 -0700 |
commit | b8838edda4e9c9a9fd68ab61ecef868218b44f36 (patch) | |
tree | 8a12bf3cd7cfafb13646daa40b92045e8d98f188 | |
parent | cc431d59650897dc363b5bc0e34c89dfe004fea0 (diff) | |
download | roka-b8838edda4e9c9a9fd68ab61ecef868218b44f36.tar.gz roka-b8838edda4e9c9a9fd68ab61ecef868218b44f36.zip |
Takes base URL and static location from args
-rwxr-xr-x | roka.py | 24 |
1 files changed, 15 insertions, 9 deletions
@@ -12,9 +12,6 @@ app = Flask(__name__) app.config.from_pyfile(os.path.join(abs_path, 'app.cfg')) cache_path = os.path.join(abs_path, 'cache') json_path = os.path.join(cache_path, 'audiobooks.json') -static_path = os.path.join(abs_path, 'static') -static_index_path = os.path.join(static_path, 'index.html') -base_url = "blah.com/" @app.route('/') def list_books(): @@ -55,6 +52,7 @@ def list_books(): return render_template('index.html', books=books) +# TODO does this really need to be here? def my_render_template( app, template_name_or_list, **context ) -> str: @@ -74,9 +72,12 @@ def my_render_template( app, ) -def generate(): +def generate(static_path, base_url): + static_index_path = os.path.join(static_path, 'index.html') + books = Books() books.scan_books() + # TODO avoid writing and reading cache books.write_cache() books = read_cache(json_path) index = my_render_template(app, 'index.html', books=books, static=True) @@ -100,7 +101,6 @@ def generate(): for f_key, file in book['files'].items(): f_path = file['path'] copy_path = os.path.join(book_dir, f_key + '.mp3') - # print("File: {} {} {}".format(f_key, f_path, copy_path)) shutil.copyfile(f_path, copy_path) if __name__ == '__main__': @@ -109,16 +109,22 @@ if __name__ == '__main__': parser.add_argument('--scan', dest='scan', action='store_true', help='scan audiobooks directory for new books', required=False) - parser.add_argument('--generate', dest='generate', action='store_true', - help='', + parser.add_argument('--generate', dest='static_path', type=str, action='store', + help='Output directory to generate static files', + required=False) + parser.add_argument('--base_url', dest='base_url', type=str, action='store', + help='Base URL to use in static files', required=False) args = parser.parse_args() + if args.static_path and not args.base_url or args.base_url and not args.static_path: + parser.error("--generate and --base_url must both be included") + if args.scan: books = Books() books.scan_books() books.write_cache() - elif args.generate: - generate() + elif args.static_path: + generate(args.static_path, args.base_url) else: app.run(host='127.0.0.1', port='8085', threaded=True) |