diff --git a/.gitignore b/.gitignore index 99bad6f..4465593 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,6 @@ static dist books-2023 +output +cookbooks +calvin-and-hobbes \ No newline at end of file diff --git a/bookshelf.html b/bookshelf.html index a5ddc3d..3453049 100644 --- a/bookshelf.html +++ b/bookshelf.html @@ -2,23 +2,71 @@ -
- bookshelf -
+ +
+
+ 2023 +
{% for book in books %}
diff --git a/calvin-and-hobbes.html b/calvin-and-hobbes.html new file mode 100644 index 0000000..52f746f --- /dev/null +++ b/calvin-and-hobbes.html @@ -0,0 +1,88 @@ + + + + + + + + +
+
+ Calvin & Hobbes +
+{% for book in books %} + +
+
+ +
+
+ {{ book.title }} by {{ book.author }} {% if book.published_year %} ({{book.published_year}}) {% endif %} +
+
+ +{% endfor %} + +
+ + + \ No newline at end of file diff --git a/cookbooks.html b/cookbooks.html new file mode 100644 index 0000000..0d7469f --- /dev/null +++ b/cookbooks.html @@ -0,0 +1,88 @@ + + + + + + + + +
+
+ Cookbooks +
+{% for book in books %} + +
+
+ +
+
+ {{ book.title }} by {{ book.author }} {% if book.published_year %} ({{book.published_year}}) {% endif %} +
+
+ +{% endfor %} + +
+ + + \ No newline at end of file diff --git a/main.py b/main.py index 0e49d39..8c2520d 100644 --- a/main.py +++ b/main.py @@ -25,6 +25,8 @@ def build_site(output_dir, images_dir, relative_template_path, template_vars): # copy over static files input_static_dir = images_dir + if not os.path.exists(output_dir): + os.makedirs(output_dir) output_static_dir = os.path.join(output_dir, 'static') if os.path.exists(output_static_dir): os.system('rm -r {}'.format(output_static_dir)) @@ -107,7 +109,9 @@ def process_list(list_url): to_print += " ({})".format(published_year) print(to_print) print("cover: {}".format(cover_url)) - image_title = book.get("title").replace(" ", "-") + image_title = book.get("title") + image_title = ''.join(c for c in image_title if (c.isalnum() or c == " ")) + image_title = image_title.replace(" ", "-") image_title = image_title.replace(":", "") image_path = "{}.jpg".format(image_title) # return item @@ -161,13 +165,20 @@ if __name__ == '__main__': bookwyrm_parser = subparsers.add_parser('bookwyrm-download') # bookwyrm-download subparser - bookwyrm_parser.add_argument('list_url') # bookwyrm list url to use as a source input - bookwyrm_parser.add_argument('output_dir') # path where images should be downloaded and csv should be written + required_bookwyrm_args = bookwyrm_parser.add_argument_group('required named arguments') + required_bookwyrm_args.add_argument('-l', '--list-url', help="bookwyrm list url to use as a source input", + required=True) + required_bookwyrm_args.add_argument('-o', '--output-dir', + help="path where images should be downloaded and yaml should be written", + required=True) # generate-html subparser - build_parser.add_argument('images_dir') # path to folder containing cover images - build_parser.add_argument('yaml_path') # yaml path to use as input - build_parser.add_argument('-t', '--template') # path to jinja file to use as a template for the html + required_build_args = build_parser.add_argument_group('required named arguments') + required_build_args.add_argument('-i', '--images-dir', help="path to folder containing cover images", required=True) + required_build_args.add_argument('-y', '--yaml-path', help="yaml path to use as input", required=True) + required_build_args.add_argument('-t', '--template', help="path to jinja file to use as a template for the html", + required=True) + required_build_args.add_argument('-o', '--output-path', help="path to generate html inside of", required=True) # parse args args = parser.parse_args() @@ -188,8 +199,9 @@ if __name__ == '__main__': else: yaml_path = args.yaml_path images_dir = args.images_dir + output_path = args.output_path template_vars = load_yaml(yaml_path) - build_site(output_dir=OUTPUT_DIR, images_dir=images_dir, relative_template_path=args.template, template_vars=template_vars) + build_site(output_dir=output_path, images_dir=images_dir, relative_template_path=args.template, template_vars=template_vars) diff --git a/run.sh b/run.sh index b1ee6ee..f95486d 100755 --- a/run.sh +++ b/run.sh @@ -1,5 +1,11 @@ # download -#python3 main.py bookwyrm-download "https://bookwyrm.social/list/2458/s/notplants-2023" "books-2023" +#python3 main.py bookwyrm-download --list-url="https://bookwyrm.social/list/2458/s/notplants-2023" --output-dir="books-2023" +# python3 main.py generate-html --yaml-path="books-2023/books.yaml" --images-dir="books-2023" --template="bookshelf.html" --output-path="output/notplants-2023" -# build - python3 main.py generate-html "example.yaml" --template="bookshelf.html" +#python3 main.py bookwyrm-download --list-url="https://bookwyrm.social/list/2634/s/calvin-and-hobbes" --output-dir="calvin-and-hobbes" +#python3 main.py generate-html --yaml-path="calvin-and-hobbes/books.yaml" --images-dir="calvin-and-hobbes" --template="calvin-and-hobbes.html" --output-path="output/calvin-and-hobbes" + + + +python3 main.py bookwyrm-download --list-url="https://bookwyrm.social/list/2609/s/cookbooks" --output-dir="cookbooks" +python3 main.py generate-html --yaml-path="cookbooks/books.yaml" --images-dir="cookbooks" --template="cookbooks.html" --output-path="output/cookbooks" \ No newline at end of file diff --git a/templates/minimal.html b/templates/minimal.html new file mode 100644 index 0000000..bf5b14c --- /dev/null +++ b/templates/minimal.html @@ -0,0 +1,34 @@ + + + + + + +
+{% for book in books %} + +
+
+ +
+
+ {{ book.title }} by {{ book.author }} {% if book.published_year %} ({{book.published_year}}) {% endif %} +
+
+ +{% endfor %} +
+ + + \ No newline at end of file diff --git a/templates/unending-lila.html b/templates/unending-lila.html new file mode 100644 index 0000000..ead16f4 --- /dev/null +++ b/templates/unending-lila.html @@ -0,0 +1,71 @@ + + + + + + + + +
+
+ 2023 +
+{% for book in books %} + +
+
+ +
+
+ {{ book.title }} by {{ book.author }} {% if book.published_year %} ({{book.published_year}}) {% endif %} +
+
+ +{% endfor %} +
+ + + \ No newline at end of file