Enough bits to deploy the site (mostly)
authorAlex Chan <alex@alexwlchan.net>
Tue, 4 Feb 2020 17:54:15 +0000 (17:54 +0000)
committerAlex Chan <alex@alexwlchan.net>
Tue, 4 Feb 2020 17:54:15 +0000 (17:54 +0000)
scripts/add_book.py
scripts/deploy.sh
scripts/render_html.py

index cd59c10..ad3cde9 100755 (executable)
@@ -123,15 +123,28 @@ def get_review_info():
 
 
 def save_cover(slug, cover_image_url):
-    filename, _ = urlretrieve(cover_image_url)
+    filename, headers = urlretrieve(cover_image_url)
+
+    if headers["Content-Type"] == "image/jpeg":
+        extension = ".jpg"
+    elif headers["Content-Type"] == "image/png":
+        extension = ".png"
+    elif headers["Content-Type"] == "image/gif":
+        extension = ".gif"
+    else:
+        print(headers)
+        assert 0
+
+        url_path = hyperlink.URL.from_text(cover_image_url).path
+        extension = os.path.splitext(url_path[-1])[-1]
 
-    url_path = hyperlink.URL.from_text(cover_image_url).path
-    extension = os.path.splitext(url_path[-1])[-1]
     cover_name = f"{slug}{extension}"
-    os.rename(filename, f"src/covers/{cover_name}")
+    dst_path = f"src/covers/{cover_name}"
 
-    return cover_name
+    if not os.path.exists(dst_path):
+        os.rename(filename, f"src/covers/{cover_name}")
 
+    return cover_name
 
 if __name__ == "__main__":
     book_info = get_book_info()
index dcd58fd..993c6b6 100755 (executable)
@@ -8,3 +8,7 @@ python3 scripts/render_html.py
 
 rsync --archive --verbose --compress --delete \
   _html/ alexwlchan@helene.linode:sites/books.alexwlchan.net
+
+ssh alexwlchan@helene.linode 'chmod 644 ~/sites/books.alexwlchan.net/static/*'
+ssh alexwlchan@helene.linode 'chmod 644 ~/sites/books.alexwlchan.net/covers/*'
+ssh alexwlchan@helene.linode 'chmod 644 ~/sites/books.alexwlchan.net/**/*.html'
index 0cbb13f..573c14d 100755 (executable)
@@ -36,7 +36,7 @@ class Book:
 class Review:
     date_read = attr.ib()
     text = attr.ib()
-    format = attr.ib()
+    format = attr.ib(default=None)
     rating = attr.ib(default=None)
     did_not_finish = attr.ib(default=False)