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