Skip to content

Instantly share code, notes, and snippets.

@tim-schilling
Created February 3, 2025 15:59
Show Gist options
  • Save tim-schilling/2b5b43fcecd79cc9af5d1bbdc3eb5f44 to your computer and use it in GitHub Desktop.
Save tim-schilling/2b5b43fcecd79cc9af5d1bbdc3eb5f44 to your computer and use it in GitHub Desktop.
Script from Claude to convert lettuce meeting poll to UTC hourly availabilities
from datetime import datetime, timedelta
import pytz
# Reference point: Monday at midnight UTC
# TODO: Update to the starting time of the meetup poll.
reference_point = datetime(2025, 2, 16, tzinfo=pytz.UTC)
# TODO: You'll need to reshape the availabilities from the lettuce
# meet GraphQL response to match the following
availabilities = [
{
"user": {"name": ""},
"availabilities": [
{"start": "2025-02-16T11:00:00.000Z", "end": "2025-02-16T12:30:00.000Z"},
{"start": "2025-02-18T08:00:00.000Z", "end": "2025-02-18T09:30:00.000Z"},
]
},
]
def convert_to_hours(availabilities):
# Create a dictionary to store users and their available hours
user_hours = {}
for user_data in availabilities:
name = user_data['user']['name']
user_hours[name] = set()
for availability in user_data['availabilities']:
start = datetime.fromisoformat(availability['start'])
end = datetime.fromisoformat(availability['end'])
# Calculate hours from reference point
current = start
while current < end:
# Calculate hours since reference point
hour_index = int((current - reference_point).total_seconds() / 3600)
user_hours[name].add(hour_index)
current += timedelta(hours=1)
# Convert sets to sorted lists for readability
return {name: sorted(hours) for name, hours in user_hours.items()}
# Example usage with the provided data
availabilities = [
# Your provided data here
]
result = convert_to_hours(availabilities)
for name, hours in result.items():
print(f"{name}: {hours}")
from datetime import datetime, timedelta
import pytz
def convert_to_hours(availabilities):
user_hours = {}
reference_point = datetime(2025, 2, 16, tzinfo=pytz.UTC)
for user_data in availabilities:
name = user_data['user']['name']
user_hours[name] = set()
for availability in user_data['availabilities']:
start = datetime.fromisoformat(availability['start'])
end = datetime.fromisoformat(availability['end'])
current = start
while current < end:
hour_index = int((current - reference_point).total_seconds() / 3600)
user_hours[name].add(hour_index)
current += timedelta(hours=1)
return {name: sorted(hours) for name, hours in user_hours.items()}
result = convert_to_hours(availabilities)
for name, hours in result.items():
print(f"{name}: {hours}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment