def save(self): save_str = json_stringify(self.chart.data) iso_time = datetime.now().replace(microsecond=0).isoformat().replace( ":", "-") out_path = config.SAVE_DIR / f"{self.name}_{iso_time}.json" self.last_save = save_str self.last_save_file = out_path print(ansi.success("Saving to " + str(out_path))) out_path.write_text(save_str)
async def load_from_old_file_a(self, idx): files = sorted(config.SAVE_DIR.glob(f"{self.name}_*.json")) if not files: return False file = files[idx] print(ansi.success("Loading from file " + str(file))) self.last_save_file = file self.last_save = file.read_text() self.chart.load_json(self.last_save) await self.chart.reset_state_a() return True
async def main(self): try: self.repl = await start_repl_a() self.startup = utils.bind(self, startup) print( ansi.success( f"""Starting server. Listening on port {self.port}. Visit "localhost:{self.port}/<channel_name>/<file_name>" to use.""" )) Executor.add_to_global_namespace(self.serve) Executor.add_to_global_namespace("app", self.app) self.startup() except Exception as e: self.critical_error(e) raise e
def save_over_previous_version(self): save_str = json_stringify(self.chart.data) out_path = self.last_save_file self.last_save = save_str print(ansi.success("Overwriting " + str(out_path))) out_path.write_text(save_str)
from fastapi import FastAPI, Request, WebSocket from fastapi.responses import HTMLResponse, FileResponse, Response from fastapi.templating import Jinja2Templates import logging logger = logging.getLogger(__name__) from . import config from .repl import start_repl_a, ReplAgent from .channels import (DemoChannel, InteractChannel, PresentationChannel, SlideshowChannel, SseqChannel) from message_passing_tree import SocketReceiver, ansi from spectralsequence_chart import SseqSocketReceiver # from spectralsequence_chart.utils import print(ansi.success("Starting server")) app = FastAPI() def run_main(f): asyncio.ensure_future(f()) return f @run_main async def main(): repl = await start_repl_a() channels = {} templates = Jinja2Templates(directory=str(config.TEMPLATE_DIR))
def save(self, name): save_str = json_stringify(self.chart.data) # iso_time = datetime.now().replace(microsecond=0).isoformat().replace(":", "-") out_path = config.SAVE_DIR / f"{name}.json" print(ansi.success("Saving to " + str(out_path))) out_path.write_text(save_str)