From ef2e1d34ef35980df917117e0b89cba7c98eaa84 Mon Sep 17 00:00:00 2001 From: dhananjaya93 Date: Thu, 25 Jul 2024 10:53:52 +0200 Subject: [PATCH] character limit was set --- parse_diff.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/parse_diff.py b/parse_diff.py index 55099595..36ef665e 100644 --- a/parse_diff.py +++ b/parse_diff.py @@ -8,6 +8,7 @@ def parse_diff(diff): new_packages = [] + # Regex package_pattern = re.compile(r'^\+\s*-\s*title:\s*(.*?)\n\+\s*version:\s*(.*?)$', re.MULTILINE) matches = package_pattern.findall(diff) @@ -17,15 +18,31 @@ def parse_diff(diff): return new_packages +def create_toot_content(new_packages, max_length=480): + base_content = "New packages in the community-archive:\n" + url_and_tags = "\ngithub.com/poseidon-framework/community-archive #aDNA #OpenData" + available_length = max_length - len(base_content) - len(url_and_tags) #tracking the remaining character limit. + + toot_content = base_content #initial cha + for package in new_packages: + if len(toot_content) + len(package) + 2 > available_length: # +2 for ", " + toot_content += "..." + break + if toot_content != base_content: + toot_content += "\n" + toot_content += package + + toot_content += url_and_tags + return toot_content + if __name__ == "__main__": diff = sys.stdin.read() new_packages = parse_diff(diff) if new_packages: - toot_content = "New packages in the community-archive:\n" - toot_content += "\n".join(new_packages) - toot_content += "\ngithub.com/poseidon-framework/community-archive #aDNA #OpenData" + toot_content = create_toot_content(new_packages) + # console print(toot_content) else: + print("No new package information has been found in this PR") -