Skip to content

Commit f199cc5

Browse files
tomvannuenenclaude
andcommitted
Update fetch_google_sheets.py to parse time from evsprk__Start_Time__c field
- Add support for parsing Salesforce time format (HH:MM:SS.sssZ) - Update available-now.html to display actual time from data instead of datetime_iso - Handle various time formats with proper fallback to "See event page for details" - Format time as user-friendly 12-hour format (e.g., "10:00 AM") 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent a374df7 commit f199cc5

File tree

2 files changed

+49
-6
lines changed

2 files changed

+49
-6
lines changed

available-now.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ <h3>Upcoming Session Schedule</h3>
7575
<td><strong>{{ session.title }}</strong></td>
7676
<td>
7777
{{ session.datetime_iso | date: "%B %d, %Y" }}<br>
78-
<small class="text-muted">{{ session.datetime_iso | date: "%I:%M %p" }}</small>
78+
<small class="text-muted">{{ session.time }}</small>
7979
</td>
8080
<td>{{ session.location | default: "Online" }}</td>
8181
<td>

scripts/fetch_google_sheets.py

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import json
77
import os
88
import sys
9-
from datetime import datetime, timezone
9+
from datetime import datetime, timezone, time
1010
from pathlib import Path
1111
from typing import List, Dict, Optional
1212
from google.oauth2 import service_account
@@ -80,6 +80,7 @@ def parse_workshop_data(raw_data: List[Dict]) -> List[Dict]:
8080
Expected columns from Salesforce export:
8181
- evsprk__Event_Title__c: Workshop title
8282
- evsprk__Start_Date__c: Start date (YYYY-MM-DD)
83+
- evsprk__Start_Time__c: Start time
8384
- evsprk__Event_Homepage_Link__c: HTML link containing registration URL
8485
"""
8586
workshops = []
@@ -98,10 +99,52 @@ def parse_workshop_data(raw_data: List[Dict]) -> List[Dict]:
9899
if not date_str:
99100
continue
100101

101-
# Convert date to datetime (assuming workshops are during business hours)
102+
# Parse time from Start_Time field
103+
time_str = row.get('evsprk__Start_Time__c', '').strip()
104+
105+
# Convert date to datetime
102106
workshop_date = datetime.strptime(date_str, "%Y-%m-%d")
103-
# Set a default time of 9 AM PST (5 PM UTC)
104-
workshop_datetime = workshop_date.replace(hour=17, minute=0, tzinfo=timezone.utc)
107+
108+
# Parse time if available, otherwise use default
109+
if time_str:
110+
try:
111+
# Handle Salesforce time format (HH:MM:SS.sssZ)
112+
if time_str.endswith('Z'):
113+
# Remove 'Z' and parse time
114+
time_str_clean = time_str.rstrip('Z')
115+
# Split off milliseconds if present
116+
if '.' in time_str_clean:
117+
time_str_clean = time_str_clean.split('.')[0]
118+
119+
time_obj = datetime.strptime(time_str_clean, "%H:%M:%S").time()
120+
workshop_datetime = datetime.combine(workshop_date, time_obj)
121+
122+
# Store formatted time for display (convert from UTC if needed)
123+
time_str = workshop_datetime.strftime("%I:%M %p")
124+
else:
125+
# Try other time formats
126+
for fmt in ["%I:%M %p", "%H:%M", "%I:%M%p", "%H:%M:%S"]:
127+
try:
128+
time_obj = datetime.strptime(time_str, fmt).time()
129+
workshop_datetime = datetime.combine(workshop_date, time_obj)
130+
break
131+
except ValueError:
132+
continue
133+
else:
134+
# If no format matched, use default time
135+
print(f"Could not parse time '{time_str}', using default")
136+
workshop_datetime = workshop_date.replace(hour=9, minute=0)
137+
except Exception as e:
138+
print(f"Error parsing time '{time_str}': {e}")
139+
workshop_datetime = workshop_date.replace(hour=9, minute=0)
140+
time_str = "See event page for details"
141+
else:
142+
# Default time if not provided
143+
workshop_datetime = workshop_date.replace(hour=9, minute=0)
144+
time_str = "See event page for details"
145+
146+
# Add timezone (assuming PST/PDT)
147+
workshop_datetime = workshop_datetime.replace(tzinfo=timezone.utc)
105148

106149
# Extract registration URL from HTML link
107150
registration_url = ''
@@ -118,7 +161,7 @@ def parse_workshop_data(raw_data: List[Dict]) -> List[Dict]:
118161
'datetime_iso': workshop_datetime.isoformat(),
119162
'registration_url': registration_url,
120163
'date': workshop_date.strftime("%b %d, %Y"),
121-
'time': 'See event page for details',
164+
'time': time_str,
122165
'location': 'Online',
123166
'instructor': 'D-Lab Staff'
124167
}

0 commit comments

Comments
 (0)