Skip to content

Commit

Permalink
Persona class
Browse files Browse the repository at this point in the history
Signed-off-by: Choonho Son <[email protected]>
  • Loading branch information
Choonho Son committed Oct 27, 2023
1 parent 2ad57da commit 9e2b6e4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
28 changes: 11 additions & 17 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,26 @@
# This is main function
import os
import persona
from persona import Persona

persona_name = os.environ.get('PERSONA', 'Wonny')
persona_name = os.environ.get('PERSONA', 'Belty')

def _list_all_jellys():
directory_path = './jellys'
contents = os.listdir(directory_path)
result = []
for item in contents:
result.append(item)
return result
script_path = os.path.abspath(__file__)
script_directory = os.path.dirname(script_path)

kargs = {
'persona_dir': os.path.join(script_directory, 'jellys'),
}

def _run_jelly(persona_name):
try:
print(f"Run {persona_name} jelly...")
persona.main(persona_name)
p = Persona(persona_name, **kargs)
p.load_persona()
except Exception as e:
print(e)

def main(persona_name):
if persona_name == 'Wonny':
jellys = _list_all_jellys()
else:
jellys = [persona_name]

for jelly in jellys:
_run_jelly(jelly)
_run_jelly(persona_name)


if __name__ == "__main__":
Expand Down
19 changes: 14 additions & 5 deletions src/persona.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,22 @@

persona_file = "CHARACTER.yml"

def load_persona(name):
persona_path = f"./jellys/{name}/{persona_file}"
data = yaml.safe_load(open(persona_path))
print(data)
class Persona:
def __init__(self, name, **kwargs):
self.name = name
for k, v in kwargs.items():
setattr(self, k, v)


def load_persona(self):
persona_path = f"{self.persona_dir}/{self.name}/{persona_file}"
data = yaml.safe_load(open(persona_path))
print(data)

def main(name):
load_persona(name)

if __name__ == "__main__":
main("Belty")
name = "Belty"
p = Persona(name, directory_path=f"./jellys")
p.load_persona()

0 comments on commit 9e2b6e4

Please sign in to comment.