diff --git a/update-notion-database/action.yml b/update-notion-database/action.yml index 32f5f98..93cf6bb 100644 --- a/update-notion-database/action.yml +++ b/update-notion-database/action.yml @@ -27,7 +27,7 @@ runs: - name: Install dependencies shell: bash run: | - pip install notion-client pandas + pip install notion-client pandas python-dateutil - name: Update Notion Database shell: python @@ -43,6 +43,17 @@ runs: from notion_client import Client import pandas as pd from datetime import datetime + from dateutil import parser + + def format_date(date_str): + """Convert various date formats to Notion's expected ISO format""" + try: + # Parse the date string + parsed_date = parser.parse(date_str) + # Format for Notion (ISO 8601) + return parsed_date.strftime('%Y-%m-%d') + except: + return None def get_property_value(property_item): property_type = property_item['type'] @@ -57,7 +68,9 @@ runs: elif property_type == 'multi_select': return [option['name'] for option in property_item['multi_select']] elif property_type == 'date': - return property_item['date']['start'] if property_item['date'] else None + if property_item['date']: + return property_item['date']['start'] + return None elif property_type == 'checkbox': return property_item['checkbox'] return None @@ -76,7 +89,10 @@ runs: return {'multi_select': [{'name': str(v)} for v in value]} return {'multi_select': [{'name': str(value)}]} elif property_type == 'date': - return {'date': {'start': value}} + formatted_date = format_date(value) + if formatted_date: + return {'date': {'start': formatted_date}} + return {'date': None} elif property_type == 'checkbox': return {'checkbox': bool(value)} return {'rich_text': [{'text': {'content': str(value)}}]} @@ -151,14 +167,15 @@ runs: if field_name in properties: prop_type = properties[field_name]['type'] new_properties[field_name] = create_property_value(field_value, prop_type) + print(f"Processing field: {field_name}, type: {prop_type}, value: {field_value}") + print(f"Converted to: {new_properties[field_name]}") # Create new page print("Creating new page...") - notion.pages.create( + response = notion.pages.create( parent={'database_id': database_id}, properties=new_properties ) - print("Successfully updated Notion database") except Exception as e: