-
-
Notifications
You must be signed in to change notification settings - Fork 34
/
pyShelf.py
executable file
·58 lines (45 loc) · 1.32 KB
/
pyShelf.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python3
import asyncio
import sys
from pathlib import Path
import websockets
from src.backend.lib.config import Config
from src.backend.pyShelf_MakeCollections import MakeCollections
from src.backend.pyShelf_ScanLibrary import execute_scan
root = Path.cwd()
config = Config(root)
PRG_PATH = Path.cwd().__str__()
sys.path.insert(0, PRG_PATH)
tx = None
async def RunImport():
"""
Begin live import of books
"""
execute_scan(PRG_PATH, config=config)
MakeCollections(PRG_PATH, config=config)
return "Import Complete"
async def socketio(websocket, path):
"""
Web Socket Controller
"""
async for message in websocket:
config.logger.info("Message Processing")
if message == "ping":
config.logger.info("<< Ping")
tx = pong()
elif message == "importBooks":
config.logger.info("Starting Import")
tx = "Starting Import . . ."
await websocket.send(tx)
await RunImport()
tx = "complete"
await websocket.send(tx)
def pong():
"""
Respond to incoming pings
"""
config.logger.info(">> Pong")
return "pong"
start_server = websockets.serve(socketio, "127.0.0.1", 1337)
asyncio.get_event_loop().run_until_complete(start_server)
asyncio.get_event_loop().run_forever()