|
| 1 | +# Code to remove entries |
| 2 | +import os |
| 3 | +import sys |
| 4 | +import shutil |
| 5 | +import subprocess |
| 6 | +import re |
| 7 | + |
| 8 | +JSON_FOLDER = 'jsonFiles' |
| 9 | +REMOVED_FOLDER = 'removedEntries' |
| 10 | + |
| 11 | +# Find issues with label "remove entry" |
| 12 | +def get_folder_name_from_title(issue_title): |
| 13 | + if ':' in issue_title: # Get entry name after the colon from the issue title |
| 14 | + folder_base = issue_title.split(':', 1)[1].strip() |
| 15 | + else: |
| 16 | + folder_base = issue_title.strip() |
| 17 | + # Sanitize to match folder naming convention |
| 18 | + folder_name = re.sub(r'[^A-Za-z0-9_\-]', '_', folder_base) |
| 19 | + return folder_name |
| 20 | + |
| 21 | +if __name__ == "__main__": |
| 22 | + if len(sys.argv) < 2: |
| 23 | + print("Usage: remove_entry.py <issue_title>") |
| 24 | + sys.exit(1) |
| 25 | + |
| 26 | + issue_title = sys.argv[1] |
| 27 | + # Use the title of the issue to find the associated folder in JsonFiles |
| 28 | + folder_name = get_folder_name_from_title(issue_title) |
| 29 | + src_path = os.path.join(JSON_FOLDER, folder_name) |
| 30 | + dst_path = os.path.join(REMOVED_FOLDER, folder_name) |
| 31 | + |
| 32 | + if not os.path.exists(src_path): |
| 33 | + print(f"Folder {src_path} does not exist.") |
| 34 | + sys.exit(1) |
| 35 | + |
| 36 | + os.makedirs(REMOVED_FOLDER, exist_ok=True) |
| 37 | + # Move that folder into folder "removedEntries" |
| 38 | + shutil.move(src_path, dst_path) |
| 39 | + print(f"Moved {src_path} to {dst_path}") |
| 40 | + |
| 41 | + # Update the BioEco CSV list and sitemap |
| 42 | + subprocess.run([sys.executable, "collectNamesTo_csv.py"], check=True) |
| 43 | + subprocess.run([sys.executable, "generate_sitemap.py"], check=True) |
0 commit comments