Skip to content

Commit b2fa6c4

Browse files
committed
Add a simple script to import event markdown from Github issue
1 parent 5cb5f91 commit b2fa6c4

File tree

2 files changed

+132
-0
lines changed

2 files changed

+132
-0
lines changed

scripts/import_event_from_issue.py

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
#!/usr/bin/env python3
2+
3+
import re
4+
import sys
5+
6+
# This script doesn't require anything special, but maybe should require a GitHub API?
7+
# (that, however, requires an API key?)
8+
9+
print('Please paste in the Markdown code of the issue:')
10+
contents = []
11+
while True:
12+
try:
13+
line = input()
14+
except EOFError:
15+
break
16+
contents.append(line)
17+
issue_markdown = "\n".join(contents)
18+
19+
# Stuff we're missing in the issue template..
20+
print("Please input the country:")
21+
country = input()
22+
print("Please input the city:")
23+
city = input()
24+
25+
# TODO: Some fields aren't ideal for this yet
26+
headline_mapping = {
27+
"title": "Title of the event",
28+
"short_description": "Short description",
29+
"body": "Long description",
30+
"how_to_attend": "How to attend",
31+
"event_type": "Event type",
32+
"event_category": "Event category",
33+
"event_date": "Event date",
34+
"event_date_end": "",
35+
"event_localtime": "Local time",
36+
"event_tz": "Timezone (UTC offset)",
37+
"event_host": "Host group",
38+
"event_languages": "Event language",
39+
"event_url": "RSVP Instructions or URL",
40+
"latitude": "Event latitude (optional)",
41+
"longitude": "Event longitude (optional)",
42+
"country": "",
43+
"city": "",
44+
"venue_name": "Venue name",
45+
"venue_address": "Venue address",
46+
"social_media": "Social media accounts (optional)",
47+
}
48+
49+
found_content = {k: "" for k in headline_mapping.keys()}
50+
51+
template = """
52+
---
53+
# PUT YOUR EVENT NAME HERE!
54+
title: "{title}"
55+
# PUT A SHORT DESCRIPTION!
56+
description: "{short_description}"
57+
# (NOT the event date - but the publication date, set to today's date)
58+
date: "2025-06-21"
59+
draft: false
60+
61+
params:
62+
event_type: "{event_type}"
63+
event_category: "{event_category}"
64+
event_date: "{event_date}"
65+
# Leave empty if single-day event.
66+
event_date_end: ""
67+
# Local time of event: "HH:MM", "TBD" or "" (if full day and no time)
68+
event_localtime: "{event_localtime}"
69+
# Timezone UTC offset of the localtime
70+
event_tz: "{event_tz}"
71+
# Your community's name or name of organizers
72+
event_host: "{event_host}"
73+
# Languages expected to be spoken
74+
event_languages: "{event_languages}"
75+
# Fill this in if you have a website or leave empty if not
76+
event_url: "{event_url}"
77+
# Copy values from your location on Google Maps
78+
latitude: {latitude}
79+
longitude: {longitude}
80+
# Put your country
81+
country: "{country}"
82+
city: "{city}"
83+
# If this is an in_person event_type, put the name and address
84+
venue_name: "{venue_name}"
85+
venue_address: "{venue_address}"
86+
# Does your community have social media? Put URLs here (not handles!)
87+
social_media:
88+
{social_media}
89+
# mastodon: "https://fosstodon.org/@djangodenmark/"
90+
# twitter: "..."
91+
# instagram: "..."
92+
# linkedin: "..."
93+
# bluesky: "..."
94+
---
95+
96+
# {title}
97+
98+
{body}
99+
100+
## How to attend
101+
102+
{how_to_attend}
103+
104+
## Code of Conduct
105+
106+
https://www.djangoproject.com/conduct/
107+
"""
108+
109+
blocks_by_headline = {}
110+
111+
current_headline = None
112+
for line in issue_markdown.split("\n"):
113+
if line.startswith("###"):
114+
current_headline = line[4:]
115+
print(f"Found: {current_headline}")
116+
blocks_by_headline[current_headline] = []
117+
elif current_headline in headline_mapping.values():
118+
blocks_by_headline[current_headline].append(line.strip())
119+
elif current_headline:
120+
print(f"Ignoring headline: {current_headline}")
121+
else:
122+
print(f"Ignoring line: {line}")
123+
124+
for key, headline in headline_mapping.items():
125+
126+
found_content[key] = "\n".join(blocks_by_headline.get(headline, [])).strip()
127+
128+
found_content["city"] = city
129+
found_content["country"] = country
130+
131+
print(template.format(**found_content))
132+

scripts/import_events_json.py

100644100755
File mode changed.

0 commit comments

Comments
 (0)