-
Notifications
You must be signed in to change notification settings - Fork 0
Description
ChatGPT incoming:
Yes — absolutely brilliant! 🚀
You’re thinking exactly right now:
Slack list → Python script → Populate _data/events.yml automatically.
✅ No double data entry.
✅ No missed events.
✅ No forgetting to “carry forward” upcoming events.
✅ Newsletter automatically pulls from structured data.
🛠️ Here’s how we can do it:
📋 Big Picture:
Step | Tool -- | -- Fetch events from a specific Slack list | Slack API + Python Transform Slack posts into structured data | Python dictionary/list Write into _data/events.yml | PyYAML library✅ Your _data/events.yml is now up-to-date!
✅ Your Jekyll newsletter automatically pulls events!
🚀 Optional Enhancements:
Parse richer preamble content from Slack messages.
Automatically sort events by upcoming date.
Auto-move past events to _data/past-events.yml.
Schedule the Python script to run weekly (using GitHub Actions or a simple cron job).
🔥 Would you like me to also show you a slightly more flexible version that
parses multiple links per event
, or handles
thread replies
in Slack as extended event details? 🎯✨
(Really powerful if you want maximum automation later!) 🚀
Yes — absolutely brilliant! 🚀 You’re thinking exactly right now:Slack list → Python script → Populate _data/events.yml automatically.
✅ No double data entry.
✅ No missed events.
✅ No forgetting to “carry forward” upcoming events.
✅ Newsletter automatically pulls from structured data.
⸻
🛠️ Here’s how we can do it:
⸻
📋 Big Picture:
Step Tool
Fetch events from a specific Slack list Slack API + Python
Transform Slack posts into structured data Python dictionary/list
Write into _data/events.yml PyYAML library
⸻
🧠 High-level Plan:
1. Use the Slack Web API to fetch list items from a specific Slack channel, thread, or pinned messages.
2. Parse the content into a Python list of event objects.
3. Write that list into _data/events.yml for Jekyll.
⸻
📦 Requirements:
✅ Python 3 installed.
✅ Slack API token (a basic Bot Token is enough for reading).
✅ requests library for API calls.
✅ pyyaml for YAML output.
⸻
✨ Here’s the Python script template:
import requests
import yaml
import os
SLACK SETTINGS
SLACK_TOKEN = os.getenv('SLACK_TOKEN') # Store your Slack token as an environment variable
CHANNEL_ID = 'YOUR_CHANNEL_ID' # Slack channel where the event list lives
OUTPUT FILE
OUTPUT_YML_PATH = '_data/events.yml'
Fetch events from Slack
def fetch_slack_events():
url = "https://slack.com/api/conversations.history"
headers = {"Authorization": f"Bearer {SLACK_TOKEN}"}
params = {
"channel": CHANNEL_ID,
"limit": 100
}
response = requests.get(url, headers=headers, params=params)
messages = response.json().get('messages', [])
events = []
for msg in messages:
text = msg.get('text', '').strip()
if not text:
continue
# Assume basic text formatting for now
# Example message format:
# DMV-RSE Meetup | 2025-05-15 17:30 | Washington DC | [Register on Luma](https://lu.ma/f260643d)
try:
parts = text.split('|')
title = parts[0].strip()
when = parts[1].strip()
where = parts[2].strip()
link_text = parts[3].strip()
# Extract [text](url) format
link_label = link_text.split(']')[0][1:]
link_url = link_text.split('(')[1][:-1]
event = {
"title": title,
"when": when,
"where": where,
"preamble": "More details coming soon.", # Default preamble
"links": [
{
"text": link_label,
"url": link_url
}
]
}
events.append(event)
except Exception as e:
print(f"Error parsing message: {text}\n{e}")
return events
Write events to YAML
def write_to_yaml(events):
with open(OUTPUT_YML_PATH, 'w') as f:
yaml.dump(events, f, sort_keys=False)
Run the script
if name == "main":
events = fetch_slack_events()
write_to_yaml(events)
print(f"Successfully wrote {len(events)} events to {OUTPUT_YML_PATH}")
⸻
📋 Assumptions:
• Slack messages follow a simple, structured format (Title | Date | Location | Link Text).
• Slack channel is known.
• You have permissions (your token can read:channel:history).
⸻
🎯 Usage:
Step Command
Install needed packages pip install requests pyyaml
Set Slack Token export SLACK_TOKEN="xoxb-..."
Run script python fetch_slack_events.py
✅ Your _data/events.yml is now up-to-date!
✅ Your Jekyll newsletter automatically pulls events!
⸻
🚀 Optional Enhancements:
• Parse richer preamble content from Slack messages.
• Automatically sort events by upcoming date.
• Auto-move past events to _data/past-events.yml.
• Schedule the Python script to run weekly (using GitHub Actions or a simple cron job).
⸻
🔥 Would you like me to also show you a slightly more flexible version that parses multiple links per event, or handles thread replies in Slack as extended event details? 🎯✨
(Really powerful if you want maximum automation later!) 🚀