Skip to content

Commit

Permalink
allow returning uploading response
Browse files Browse the repository at this point in the history
  • Loading branch information
lolipopshock committed Feb 20, 2022
1 parent 6639639 commit fd11fea
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/notion_df/_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def to_notion(
errors: str = "strict",
resolve_relation_values: bool = False,
create_new_rows_in_relation_target: bool = False,
return_response: bool = False,
api_key: str = None,
):

Expand Down Expand Up @@ -104,6 +105,9 @@ def to_notion(
If True, then notion-df will try to create new rows in the target
the relation table if the relation column value is not found there.
Defaults to False.
return_response (bool, optional):
If True, then the function will return a list of responses for
the updates from Notion.
api_key (str, optional):
The API key of the Notion integration.
Defaults to None.
Expand All @@ -119,6 +123,7 @@ def to_notion(
errors=errors,
resolve_relation_values=resolve_relation_values,
create_new_rows_in_relation_target=create_new_rows_in_relation_target,
return_response=return_response,
api_key=api_key,
)

Expand Down
16 changes: 11 additions & 5 deletions src/notion_df/agent.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List, Dict, Optional
from typing import List, Dict, Optional, Union, Tuple
from datetime import datetime
import warnings
import os
Expand Down Expand Up @@ -234,7 +234,7 @@ def create_database(
return response


def upload_row_to_database(row, database_id, schema, client):
def upload_row_to_database(row, database_id, schema, client) -> Dict:

properties = PageProperty.from_series(row, schema).query_dict()
response = client.pages.create(
Expand All @@ -243,7 +243,7 @@ def upload_row_to_database(row, database_id, schema, client):
return response


def upload_to_database(df, databse_id, schema, client, errors):
def upload_to_database(df, databse_id, schema, client, errors) -> List[Dict]:
all_response = []
for _, row in df[::NOT_REVERSE_DATAFRAME].iterrows():
try:
Expand Down Expand Up @@ -276,10 +276,11 @@ def upload(
errors: str = "strict",
resolve_relation_values: bool = False,
create_new_rows_in_relation_target: bool = False,
return_response: bool = False,
*,
api_key: str = None,
client: Client = None,
):
) -> Union[str, Tuple[str, List[Dict]]]:
"""Upload a dataframe to the specified Notion database.
Args:
Expand Down Expand Up @@ -326,6 +327,9 @@ def upload(
If True, then notion-df will try to create new rows in the target
the relation table if the relation column value is not found there.
Defaults to False.
return_response (bool, optional):
If True, then the function will return a list of responses for
the updates from Notion.
api_key (str, optional):
The API key of the Notion integration.
Defaults to None.
Expand Down Expand Up @@ -427,7 +431,9 @@ def upload(
lambda row: [obj_string_to_id[ele] for ele in row if ele in obj_string_to_id]
)

upload_to_database(df, databse_id, schema, client, errors)
response = upload_to_database(df, databse_id, schema, client, errors)

print(f"Your dataframe has been uploaded to the Notion page: {notion_url} .")
if return_response:
return notion_url, response
return notion_url

0 comments on commit fd11fea

Please sign in to comment.