Skip to content

Commit

Permalink
handle whitespace and titles correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremymanning authored Jul 18, 2024
1 parent c6d936d commit a87d8d4
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions compile_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ def replace(match):
emoji_pattern = re.compile('|'.join(re.escape(key) for key in emoji_mapping.keys()))
return emoji_pattern.sub(replace, text)

def remove_last_lines(lines, n):
count = 0
for i in range(len(lines) - 1, -1, -1):
if lines[i].strip() != '':
count += 1
if count == n:
return lines[:i]
return lines

# Load events
events_df = pd.read_csv('events.tsv', delimiter='\t')
start_date = events_df.iloc[0]['Start Date']
Expand All @@ -61,14 +70,17 @@ def replace(match):
continue

with open(f'templates/{content_file}', 'r') as file:
event_content = file.read()
event_content = file.readlines()

# Extract event title from the second non-whitespace line
event_title = next(line.strip() for line in event_content if line.strip())
event_title = next(line.strip() for line in event_content if line.strip())

# Remove the first line (title) and the last two non-whitespace lines
event_content = remove_last_lines(event_content[1:], 2)

# Replace placeholders with actual values
event_content = event_content.replace('{DATE}', row['Date']).replace('{TIME}', row['Time']).replace('{LOCATION}', row['Location'])

# Remove the first and last lines (last two lines specifically)
event_content_lines = event_content.split('\n')
event_content = '\n'.join(event_content_lines[1:-3]).strip()
event_content = ''.join(event_content).replace('{DATE}', row['Date']).replace('{TIME}', row['Time']).replace('{LOCATION}', row['Location'])

# Adjust formatting for Date, Time, Location
event_content = event_content.replace('**Date:**', '\n**Date:**')
Expand All @@ -78,7 +90,7 @@ def replace(match):
# Replace emojis
event_content = replace_emojis(event_content)

events_markdown += f"## {row['Event Name']}\n\n"
events_markdown += f"## {event_title}\n\n"
events_markdown += event_content + "\n\n"
events_markdown += "---\n\n"

Expand Down

0 comments on commit a87d8d4

Please sign in to comment.