-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactions.py
39 lines (31 loc) · 1.42 KB
/
actions.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
import os
from completion import generate_completion
# A function that takes an action and adds it to our actions folder, for easy use in the future
def add_action(action_string, action_folder="actions"):
# Check if the actions folder exists, and create it if it doesn't
if not os.path.exists(action_folder):
os.makedirs(action_folder)
# Assign a unique ID to the action based on the number of existing actions
action_id = len(os.listdir(action_folder)) + 1
action_filename = f"{action_folder}/action_{action_id}.txt"
with open(action_filename, 'w') as file:
file.write(action_string)
# A function that retrieves the contents of a file in the actions folder
def get_action(action_id, action_folder="actions"):
action_filename = f"{action_folder}/action_{action_id}.txt"
if os.path.exists(action_filename):
with open(action_filename, 'r') as file:
return file.read()
else:
return None
def get_actions(action_folder="actions"):
actions = []
if os.path.exists(action_folder):
action_files = os.listdir(action_folder)
for action_file in action_files:
action_filename = os.path.join(action_folder, action_file)
if os.path.isfile(action_filename):
with open(action_filename, 'r') as file:
action_content = file.read()
actions.append(action_content)
return actions