-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisplay.py
31 lines (27 loc) · 1.03 KB
/
display.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import webbrowser
import threading
import requests
from web import WebApp, Paginator
from config import get_config
class ImageGalleryApp:
def __init__(self):
self.args = get_config()
self.web_app = WebApp(self.args)
def input_listener(self) -> None:
print('Press Q to quit...')
while True:
if input().lower() == 'q':
try:
requests.post(f'http://127.0.0.1:{self.args.port}/shutdown')
except Exception as e:
self.web_app.app.logger.error(f"Shutdown failed: {str(e)}")
finally:
break
def run(self):
threading.Timer(1, lambda: webbrowser.open(f'http://127.0.0.1:{self.args.port}')).start()
input_thread = threading.Thread(target=self.input_listener, daemon=True)
input_thread.start()
self.web_app.app.run(host=self.args.host, port=self.args.port, debug=self.args.debug, use_reloader=False)
if __name__ == '__main__':
app = ImageGalleryApp()
app.run()