]> git.phdru.name Git - m_librarian.git/blob - scripts/ml-web.py
Feat(web): Show books by an author
[m_librarian.git] / scripts / ml-web.py
1 #! /usr/bin/env python
2
3 import argparse
4 import time
5 import webbrowser
6
7 from bottle import thread  # portable import
8
9 from m_librarian.db import open_db
10 import m_librarian.web.app  # noqa: F401 imported but unused
11 from m_librarian.web.server import run_server
12 from m_librarian.web.utils import get_open_port
13
14
15 def start_browser(port):
16     time.sleep(1)  # A small timeout to allow the main thread to run the server
17     webbrowser.open_new('http://localhost:%d/' % port)
18
19
20 if __name__ == '__main__':
21     parser = argparse.ArgumentParser(description='Init')
22     parser.add_argument('-p', '--port', help='HTTP server port')
23     args = parser.parse_args()
24
25     if args.port:
26         port = args.port
27     else:
28         port = get_open_port()
29
30     open_db()
31     thread.start_new_thread(start_browser, (port,))
32     run_server(port=port)