-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathadd_person.py
More file actions
116 lines (86 loc) · 3.42 KB
/
add_person.py
File metadata and controls
116 lines (86 loc) · 3.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import os
from shutil import copyfile
import utils
PEOPLE_PATH = "./_people"
VALID_TITLES = [
"Professor",
"Associate Professor",
"Assistant Professor",
"Postdoc",
"PhD Candidate",
"PhD Student",
"Researcher",
"Master's Student",
"Bachelor's Student",
"High School Student"
]
TITLE_PRIORITIES = {k: v for k, v in zip(VALID_TITLES,
range(len(VALID_TITLES)))}
def name_to_person_filename(name):
return name.replace(" ", "").lower().strip() + ".md"
def get_new_headshot_filename(name, headshot_path_old):
name_stripped = name.replace(" ", "").lower().strip()
_, extension = os.path.splitext(headshot_path)
new_filename = name_stripped + extension
return new_filename
# Ugly hack :()
def clean_url(url):
if "https://" not in url or "http://" not in url:
url = "https://" + url
return url
def person_exists(name):
person_path = os.path.join(PEOPLE_PATH, name_to_person_filename(name))
return os.path.exists(person_path)
def build_person(name, headshot_path, title, website=None, research_areas="",
is_visiting=False):
if not website:
website = None
else:
website = clean_url(website)
if not research_areas:
research_areas = None
else:
research_areas = research_areas.split(",")
if not headshot_path == "":
jeyll_config = utils.load_jeykll_config()
headshots_dir = os.path.join(jeyll_config["RESOURCES_PATH"], "headshots")
new_headshot_filename = get_new_headshot_filename(name, headshot_path)
new_headshot_path = os.path.join(headshots_dir, new_headshot_filename)
copyfile(headshot_path, new_headshot_path)
else:
new_headshot_filename = "dubs.png"
person = {
"name": name,
"title": title,
"site": website,
"headshot": new_headshot_filename,
"research_areas": research_areas,
"priority": TITLE_PRIORITIES[title],
"is_visiting": is_visiting
}
person_file_path = os.path.join(PEOPLE_PATH, name_to_person_filename(name))
utils.dump_dict_to_yaml(person, person_file_path)
return person_file_path
if __name__ == "__main__":
print("---------------------------")
print("""This script adds a new person to this site's 'Our Team'
section. Please provide the following information:""")
print("---------------------------")
name = input("Full Name:")
if person_exists(name):
print(name_to_person_filename(name), "already exists.")
do_exit = not utils.y_or_n("Do you want to overwrite this user?")
if do_exit:
quit()
headshot_path = input("Local path to headshot [Optional]:").strip()
while not headshot_path=="" and not os.path.exists(headshot_path):
print("File not found. Please try again.")
headshot_path = input("Path to headshot [Optional]:")
title = utils.input_options("Your title:", VALID_TITLES)
website = input("""Personal website URL [Optional]:""")
research_areas = input("Research areas, seperated by commas [Optional]:")
is_visiting = utils.y_or_n("""Are you a visitor (e.g. an intern or visiting PhD Student)?""")
out_path = build_person(name, headshot_path, title,
website, research_areas,
is_visiting=is_visiting)
print("New person created at {}".format(out_path))