diff --git a/.github/scripts/check_update_paper.py b/.github/scripts/check_update_paper.py new file mode 100644 index 0000000..33b2077 --- /dev/null +++ b/.github/scripts/check_update_paper.py @@ -0,0 +1,87 @@ +from datetime import datetime +import glob +import re +import os +import requests +from bs4 import BeautifulSoup + +def get_latest_version(): + # Fetches and returns the latest version of PaperMC from its downloads page. + url = 'https://papermc.io/downloads/paper' + response = requests.get(url) + soup = BeautifulSoup(response.content, 'html.parser') + version_element = soup.find('span', class_='text-blue-600') + if version_element: + version_text = version_element.text.strip() + print(f"Latest version found: {version_text}") + return version_text + else: + print("No version found on the page.") + return None + +def is_valid_version(version): + # Checks if the given version string matches the expected version pattern. + return bool(re.match(r'^\d+\.\d+\.\d+$', version)) + +def get_date_suffix(day): + # Returns the appropriate ordinal suffix for a given day of the month. + return 'th' if 11 <= day <= 13 else {1: 'st', 2: 'nd', 3: 'rd'}.get(day % 10, 'th') + +def update_readme(latest_version): + # Updates the README.md file with the latest version information under the update history section. + today = datetime.now() + date_suffix = get_date_suffix(today.day) + formatted_date = today.strftime(f'%B %d{date_suffix} %Y') + update_entry = f"\n
  • {formatted_date}
  • \n \n" + + with open('README.md', 'r+') as file: + content = file.read() + updated_content = re.sub(r'(

    Update History

    \n