Skip to content

Commit

Permalink
use regex
Browse files Browse the repository at this point in the history
  • Loading branch information
bhagyasharma committed Jul 2, 2024
1 parent 42c4635 commit fab6891
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions scripts/copy_readme.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import re


FRONT_MATTER = "---\ntitle: Python Library\nslug: python-library-1\n---\n\n"


Expand All @@ -8,21 +11,16 @@ def main():
input_readme = "README.md"
output_file = "README_COPY.md"
with open(input_readme, "r") as file:
readme_lines = file.readlines()
readme_content = file.read()

# remove links
for line in readme_lines:
if line.startswith(("![Logo]", "![GitHub Tag]", "![PyPI - Downloads]")):
readme_lines.remove(line)
readme_content = re.sub("!\[.*]\(.*\)\n", "", readme_content)

# remove irrelavant sections
readme_content = "".join(readme_lines)
count = 0
for section in readme_content.split("\n### "):
if section.startswith("Parcl Labs Data Overview"):
full_section = "\n### " + section
readme_content = readme_content.replace(full_section, "")
count += 1

with open(output_file, "w") as f:
f.write(FRONT_MATTER + readme_content)
Expand Down

0 comments on commit fab6891

Please sign in to comment.