Fix some bugs in the AO3 script
- ID
5087700- date
2024-02-14 23:13:51+00:00- author
Alex Chan <alex@alexwlchan.net>- parent
7ccd420- message
Fix some bugs in the AO3 script- changed files
1 file, 13 additions, 2 deletions
Changed files
web/save_ao3_links.py (1945) → web/save_ao3_links.py (2160)
diff --git a/web/save_ao3_links.py b/web/save_ao3_links.py
index a8512f0..e8a9208 100755
--- a/web/save_ao3_links.py
+++ b/web/save_ao3_links.py
@@ -7,13 +7,24 @@ import subprocess
import sys
import tarfile
+import hyperlink
+
BACKUP_ROOT = pathlib.Path("/Volumes/Media (Sapphire)/backups/ao3")
-def save_ao3_url(url: str):
+def get_ao3_id(url: str) -> str:
# e.g. 'https://archiveofourown.org/works/1234' ~> '1234'
- ao3_id = url.split("/")[-1]
+ u = hyperlink.DecodedURL.from_text(url)
+
+ if u.path[0] == 'works' and u.path[1].isnumeric():
+ return u.path[1]
+ else:
+ raise ValueError(url)
+
+
+def save_ao3_url(url: str):
+ ao3_id = get_ao3_id(url)
# Check if the fic is already downloaded -- if it is, nothing to do.
if any(