-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsierra.py
More file actions
74 lines (61 loc) · 1.8 KB
/
Copy pathsierra.py
File metadata and controls
74 lines (61 loc) · 1.8 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import asyncio
import logging
import sys
from threading import Thread
from glob import glob
from input import sierra
import plugins
from play.sessions import Session
from utils.logging import log
class Service:
"""
`Service` class to represent a service.
"""
def __init__(self):
self.thread = Thread(target=Service.thread)
@staticmethod
def thread():
"""
`thread` method to start the service.
"""
log.info('Starting Session ...')
asyncio.run(session.gather())
def start(self):
"""
`start` method to start the service.
"""
self.thread.start()
class API:
"""
`API` class to represent an API.
"""
def __init__(self):
self.thread = Thread(target=API.thread)
@staticmethod
def thread():
"""
`thread` method to start the API.
"""
log.info('Starting API ...')
sierra.run(port=8008)
def start(self):
"""
`start` method to start the API.
"""
self.thread.start()
if __name__ == '__main__':
sys.modules['flask.cli'].show_server_banner = lambda *x: None
logging.getLogger('werkzeug').setLevel(logging.ERROR)
logging.getLogger('httpx').setLevel(logging.ERROR)
with Session() as session:
plugins.hook(plugins.HookType.INITIALIZE, session, None)
saves = glob('saves/*.sierra')
if saves:
if input('Load history from previous session? (y/N): ').lower().startswith('y'):
log.info(''.join([f'{i}: {save}\n' for i, save in enumerate(saves)]))
index = int(input('Load save: '))
session.load(saves[index])
session.windows.associate(session)
Service().start()
API().start()
session.windows.start()