-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
64f7946
commit 91c6fa0
Showing
7 changed files
with
132 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
from datetime import datetime | ||
from bs4 import BeautifulSoup | ||
import os | ||
import markdown | ||
import argparse | ||
|
||
# Set up argument parsing to accept the markdown file path | ||
parser = argparse.ArgumentParser(description="Process a markdown file to generate formatted release notes.") | ||
parser.add_argument('version', type=str, help='Path to the markdown file') | ||
args = parser.parse_args() | ||
|
||
markdown_file_path = os.path.join(os.getcwd(), 'changelog', args.version.replace('mikroSDK-', ''), 'changelog.md') | ||
|
||
# Read the markdown content from the file path provided as a command-line argument | ||
with open(markdown_file_path, 'r', encoding='utf-8') as file: | ||
markdown_content = file.read() | ||
|
||
# Convert markdown to HTML and parse it with BeautifulSoup | ||
html_content = markdown.markdown(markdown_content) | ||
soup = BeautifulSoup(html_content, 'html.parser') | ||
|
||
# Function to extract sections dynamically based on headers, excluding unwanted sections | ||
def extract_sections(soup): | ||
sections = {} | ||
current_section = None | ||
for tag in soup.find_all(['h3', 'p', 'ul']): | ||
if tag.name == 'h3': | ||
current_section = tag.get_text(strip=True) | ||
# Exclude the "NEW HARDWARE" section | ||
if current_section.lower() == 'new hardware': | ||
current_section = None | ||
else: | ||
sections[current_section] = [] | ||
elif current_section and tag.name in ['p', 'ul']: | ||
# Join text contents with spaces to avoid missing spaces between elements | ||
text_content = ' '.join(tag.stripped_strings) | ||
sections[current_section].append(text_content) | ||
return sections | ||
|
||
# Extract sections from the parsed markdown, excluding specified sections | ||
sections = extract_sections(soup) | ||
|
||
# Format the extracted sections | ||
formatted_sections = [] | ||
for section, content in sections.items(): | ||
formatted_sections.append(f"+ {section}") | ||
for line in content: | ||
formatted_sections.append(f" + {line}") | ||
|
||
# Combine all formatted sections | ||
formatted_message_content = "\n".join(formatted_sections) | ||
|
||
# Get the current date and time | ||
release_date = datetime.now().strftime("%a %b %d %H:%M:%S CEST %Y") | ||
|
||
# Create the final formatted message | ||
formatted_message = f""" | ||
NECTO SDK Release for {release_date}: | ||
Update notes: | ||
{formatted_message_content} | ||
> For more information on today's release, visit following [README](https://github.com/MikroElektronika/mikrosdk_v2/blob/master/changelog/v2.11.2/new_hw/2024-09-27.md) | ||
""" | ||
|
||
# Print the formatted message | ||
print(formatted_message) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters