-
Notifications
You must be signed in to change notification settings - Fork 0
/
confession_database.py
32 lines (21 loc) · 973 Bytes
/
confession_database.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
import pandas as pd
from config import CONFIG
from database import Database
class ConfessionDatabase(Database):
def __init__(self):
super().__init__(CONFIG["databases"]["confession_filepath"])
def retrieve_confession_script(self, char_name: str):
if char_name is None:
raise ValueError("Character name for confession is None.")
df = self.df[self.df["Confession_ID"] == char_name].copy()
if df.empty:
raise ValueError(f"No confession script found for {char_name}.")
df['Text'] = df['Text'].str.replace("\\n", "\n")
df['Start time'] = pd.to_datetime(df['Start time'], format='%M:%S,%f')
df['Duration'] = (df['Start time'] - df['Start time'].shift(1)).shift(-1).dt.total_seconds()
df.loc[df.index[-1], 'Duration'] = 7.0
return df
if __name__ == "__main__":
conf_db = ConfessionDatabase()
txt = conf_db.retrieve_confession_script("Nozomi")
print(txt)