-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.py
More file actions
23 lines (18 loc) · 693 Bytes
/
Copy pathutils.py
File metadata and controls
23 lines (18 loc) · 693 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import json
import os
from typing import List
from session import Session
def save_sessions_to_file(sessions: List[Session]):
with open("sessions.json", "w", encoding="utf-8") as f:
sessions_dict = [
session.to_dict() for session in sessions
if session.user_id != -1
]
json.dump(sessions_dict, f, indent=4, ensure_ascii=False)
def load_sessions_for_file() -> List[Session]:
if os.path.exists("sessions.json"):
with open("sessions.json", "r", encoding="utf-8") as f:
sessions_dict = json.load(f)
return [Session(source_dict=session_dict) for session_dict in sessions_dict]
else:
return []