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.
- Loading branch information
1 parent
d3efeac
commit fa14f37
Showing
3 changed files
with
23 additions
and
5 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
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,15 +1,27 @@ | ||
import os | ||
import json | ||
|
||
def read_chat(id): | ||
def read_chat(id: str) -> dict: | ||
''' | ||
Uses chat_id to get the entire chat JSON file | ||
Uses chat_id to get the chat JSON file and returns a python dict object. | ||
''' | ||
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) | ||
return data | ||
|
||
# Print the data | ||
print(data) | ||
def upsert_chat(chat_object: dict): | ||
''' | ||
Upserts a chat dictionary object, saving it as json file in the user_data folder. | ||
Upserting means to update or create if the file doesn't exist yet. Overwriting previous data. | ||
''' | ||
try: | ||
print("hey") | ||
except Exception as e: | ||
return e | ||
|
||
|
||
# json.dumps() - From python to json | ||
# json.load() - From json to python |
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