generated from CogitoNTNU/README-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Create file management for user_data
- Loading branch information
1 parent
c906612
commit d3efeac
Showing
9 changed files
with
54 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
# Custom Ignores | ||
user_data | ||
|
||
|
||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
class Ai_message: | ||
def __init__(self, message:str, token_count:int) -> None: | ||
self.message = message | ||
self.token_count = token_count | ||
self.token_count = token_count |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import os | ||
import json | ||
|
||
def read_chat(id): | ||
''' | ||
Uses chat_id to get the entire chat JSON file | ||
''' | ||
dirname = os.path.dirname(os.path.dirname(__file__)) # Creates folder in core named user_data | ||
filepath = os.path.join(dirname, f'user_data/chats/{id}.json') | ||
# Open and read the JSON file | ||
with open(filepath, 'r') as file: | ||
data = json.load(file) | ||
|
||
# Print the data | ||
print(data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import os | ||
|
||
def check_folders(): | ||
main_folder = "user_data/" | ||
pathsToCheck = ["chats", "images", "pdfs", "fbx"] | ||
for directory in pathsToCheck: | ||
path = main_folder + directory # creates path user_data/chats for example. Everything should be under user_data as its gitignored. | ||
check_and_create_folder(path) # Does a relative folder check, and builds the directory if it doesn't exist | ||
|
||
def check_and_create_folder(path): | ||
dirname = os.path.dirname(os.path.dirname(__file__)) # Creates folder in core named user_data | ||
relativedir = os.path.join(dirname, path) | ||
if not os.path.exists(relativedir): | ||
try: | ||
print("Created user_data director under core folder. This is first-time setup.") | ||
os.makedirs(path) | ||
except Exception as e: | ||
print(e) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters