aboutsummaryrefslogtreecommitdiff
path: root/roka.py
diff options
context:
space:
mode:
Diffstat (limited to 'roka.py')
-rwxr-xr-xroka.py24
1 files changed, 15 insertions, 9 deletions
diff --git a/roka.py b/roka.py
index 05091ee..aafc3a3 100755
--- a/roka.py
+++ b/roka.py
@@ -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)