-
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.
Refactor configuration handling to separate schema and tasks for Noti…
…on database operations - Extracted schema from task-specific configurations to improve modularity and reusability. - Introduced `load_schema` and `load_tasks` functions for better separation of concerns. - Updated `create_database.py` and `update_database.py` to reflect changes in configuration loading. - Renamed `fashion_recommender_tasks_schema.json` to `fashion_recommender_tasks.json` to better match its content. - Improved error handling and code readability across the board.
- Loading branch information
1 parent
2724410
commit 1642c48
Showing
6 changed files
with
107 additions
and
145 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
53 changes: 0 additions & 53 deletions
53
...igs/fashion_recommender_tasks_schema.json → ...se_configs/fashion_recommender_tasks.json
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,53 @@ | ||
{ | ||
"title": "Fashion Recommender App Development", | ||
"properties": { | ||
"Name": { | ||
"title": {} | ||
}, | ||
"Description": { | ||
"rich_text": {} | ||
}, | ||
"Status": { | ||
"select": { | ||
"options": [ | ||
{ "name": "To Do", "color": "default" }, | ||
{ "name": "In Progress", "color": "blue" }, | ||
{ "name": "Done", "color": "green" } | ||
] | ||
} | ||
}, | ||
"Due Date": { | ||
"date": {} | ||
}, | ||
"Task Type": { | ||
"select": { | ||
"options": [ | ||
{ "name": "Cataloging", "color": "red" }, | ||
{ "name": "Database Design", "color": "green" }, | ||
{ "name": "Backend Development", "color": "yellow" }, | ||
{ "name": "Frontend Development", "color": "blue" }, | ||
{ "name": "Testing", "color": "purple" } | ||
] | ||
} | ||
}, | ||
"Priority": { | ||
"select": { | ||
"options": [ | ||
{ "name": "High", "color": "red" }, | ||
{ "name": "Medium", "color": "orange" }, | ||
{ "name": "Low", "color": "green" } | ||
] | ||
} | ||
}, | ||
"Estimated Time": { | ||
"select": { | ||
"options": [ | ||
{ "name": "Less than 1 hour", "color": "yellow" }, | ||
{ "name": "1-2 hours", "color": "orange" }, | ||
{ "name": "2-3 hours", "color": "red" }, | ||
{ "name": "More than 3 hours", "color": "purple" } | ||
] | ||
} | ||
} | ||
} | ||
} |
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,24 +1,25 @@ | ||
# create_database.py | ||
import argparse | ||
from notion_utils.NotionUtils import load_database_config, create_database, create_task | ||
from notion_utils.NotionUtils import load_schema, load_tasks, create_database, create_task | ||
|
||
def main(config_name): | ||
def main(schema_name, tasks_name): | ||
try: | ||
config = load_database_config(config_name) | ||
database_id = create_database(config) | ||
schema = load_schema(schema_name) # Load schema configuration | ||
tasks = load_tasks(tasks_name) # Load tasks configuration | ||
|
||
database_id = create_database(schema) | ||
if database_id: | ||
tasks = config["tasks"] | ||
schema_properties = config["schema"]["properties"] | ||
for task in tasks: | ||
schema_properties = schema["properties"] | ||
for task in tasks["tasks"]: | ||
create_task(database_id, task, schema_properties) | ||
except FileNotFoundError as e: | ||
print(e) | ||
except ValueError as e: | ||
print(f"Validation Error: {e}") | ||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser(description="Create a Notion database using a specified template.") | ||
parser.add_argument('template', type=str, help="The name of the template to use (without .json extension).") | ||
parser = argparse.ArgumentParser(description="Create a Notion database using a specified schema and tasks template.") | ||
parser.add_argument('schema', type=str, help="The name of the schema template to use (without .json extension).") | ||
parser.add_argument('tasks', type=str, help="The name of the tasks template to use (without .json extension).") | ||
|
||
args = parser.parse_args() | ||
main(args.template) | ||
main(args.schema, args.tasks) |
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,24 +1,30 @@ | ||
# update_database.py | ||
import argparse | ||
from notion_utils.NotionUtils import create_task, load_database_config, update_database | ||
from notion_utils.NotionUtils import load_schema, load_tasks, update_database, create_task | ||
|
||
def main(database_id, config_name): | ||
def main(database_id, schema_name, tasks_name): | ||
try: | ||
config = load_database_config(config_name) | ||
update_database(database_id, config) | ||
tasks = config["tasks"] | ||
schema_properties = config["schema"]["properties"] | ||
for task in tasks: | ||
# Load schema and tasks configuration | ||
schema = load_schema(schema_name) | ||
tasks = load_tasks(tasks_name) | ||
|
||
# Update the database with the provided schema | ||
update_database(database_id, schema) | ||
|
||
# Add tasks to the updated database | ||
schema_properties = schema["properties"] | ||
for task in tasks["tasks"]: | ||
create_task(database_id, task, schema_properties) | ||
|
||
except FileNotFoundError as e: | ||
print(e) | ||
except ValueError as e: | ||
print(f"Validation Error: {e}") | ||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser(description="Update an existing Notion database using a specified template.") | ||
parser = argparse.ArgumentParser(description="Update an existing Notion database using specified schema and tasks templates.") | ||
parser.add_argument('database_id', type=str, help="The ID of the database to update.") | ||
parser.add_argument('template', type=str, help="The name of the template to use (without .json extension).") | ||
parser.add_argument('schema', type=str, help="The name of the schema template to use (without .json extension).") | ||
parser.add_argument('tasks', type=str, help="The name of the tasks template to use (without .json extension).") | ||
|
||
args = parser.parse_args() | ||
main(args.database_id, args.template) | ||
main(args.database_id, args.schema, args.tasks) |