Skip to content

Commit

Permalink
fix date
Browse files Browse the repository at this point in the history
  • Loading branch information
liyaka committed Jan 1, 2025
1 parent 1e7a1c9 commit 6f2531e
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions update-notion-database/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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']
Expand All @@ -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
Expand All @@ -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)}}]}
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 6f2531e

Please sign in to comment.