-
Notifications
You must be signed in to change notification settings - Fork 1
/
history.py
executable file
·47 lines (38 loc) · 1.21 KB
/
history.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
from typing import Tuple
from find import find_dir
from pathlib import Path
import json
import os
hist_path = os.path.dirname(__file__) + "/" + ".history"
path = Path(hist_path)
if not path.exists():
path.touch()
path.write_text("{}")
def form_history(ser_name: str) -> Tuple[int, int]:
ser_name = find_dir(ser_name)
season, episode = load_history(ser_name)
return season, episode
def load_history(ser_name: str) -> Tuple[int, int]:
ser_name = find_dir(ser_name)
with open(hist_path, "r") as f:
history = json.load(f)
if ser_name in history:
season = history[ser_name]["season"]
episode = history[ser_name]["episode"]
else:
season = 1
episode = 1
return season, episode
def save_history(ser_name: str, season: int, episode: int) -> None:
ser_name = find_dir(ser_name)
with open(hist_path, "r") as f:
history = json.load(f)
history[ser_name] = {"season": season, "episode": episode}
history["LAST_SER"] = ser_name
with open(hist_path, "w") as f:
json.dump(history, f, indent=4)
def get_last_ser() -> str:
with open(hist_path, "r") as f:
history = json.load(f)
name = history["LAST_SER"]
return name