aboutsummaryrefslogtreecommitdiff
path: root/src/main.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.py')
-rw-r--r--src/main.py56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/main.py b/src/main.py
new file mode 100644
index 0000000..618cc5a
--- /dev/null
+++ b/src/main.py
@@ -0,0 +1,56 @@
+# Manage book library.
+#
+# Required dependencies:
+#
+# - python >= 3.11
+# - requests
+# - pillow
+# - ebook-convert CLI (from calibre)
+
+import sys
+import os
+
+import library.command
+import view.command
+
+def print_help(title='Manage book library'):
+ print(f"""{title}
+
+- Print library metadata as json:
+
+ $ python {sys.argv[0]} library
+
+- View books in web page:
+
+ $ python {sys.argv[0]} view browser-cmd
+
+Environment variables:
+
+ BOOK_LIBRARY: path to book library.""")
+
+def get_book_library():
+ path = os.getenv('BOOK_LIBRARY')
+ if path is None or not os.path.isdir(path):
+ print_help(title='BOOK_LIBRARY environment variable is required.')
+ exit(1)
+ else:
+ return path
+
+def main():
+ match sys.argv:
+ case [ _, 'library' ]:
+ book_library = get_book_library()
+ library.command.run(book_library)
+ case [ _, 'view', browser_cmd ]:
+ book_library = get_book_library()
+ view.command.run(book_library, browser_cmd)
+ case [ _, '--help' ]:
+ print_help()
+ case [ _, '-h' ]:
+ print_help()
+ case _:
+ print_help('Command not found.')
+ exit(1)
+
+if __name__ == "__main__":
+ main()