forked from academicpages/academicpages.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_publication.py
More file actions
116 lines (91 loc) · 3.02 KB
/
add_publication.py
File metadata and controls
116 lines (91 loc) · 3.02 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
112
113
114
115
116
#!/usr/bin/env python3
"""Interactively add a new publication to publications.json and regenerate HTML."""
import json
import sys
from pathlib import Path
SCRIPT_DIR = Path(__file__).resolve().parent
JSON_PATH = SCRIPT_DIR / "publications.json"
VALID_TYPES = {
"1": "journal",
"2": "archival-conference",
"3": "workshop",
"4": "book-chapter",
"5": "policy-report",
}
TYPE_LABELS = {
"1": "Peer-Reviewed Journal Article",
"2": "Archival Conference Paper",
"3": "Workshop Paper / Extended Abstract",
"4": "Book Chapter",
"5": "Policy Report",
}
def prompt(label, required=True, default=None):
"""Prompt user for input."""
suffix = f" [{default}]" if default else ""
suffix += ": " if required else " (optional, press Enter to skip): "
while True:
value = input(f" {label}{suffix}").strip()
if not value and default:
return default
if not value and not required:
return None
if not value and required:
print(" This field is required.")
continue
return value
def main():
print("\n=== Add New Publication ===\n")
title = prompt("Title")
authors_str = prompt("Authors (comma-separated)")
authors = [a.strip() for a in authors_str.split(",")]
venue = prompt("Venue (e.g., 'Research Policy, 49(2), 2020')")
venue_es = prompt("Venue (Spanish override)", required=False)
while True:
print("\n Publication type:")
for k, label in TYPE_LABELS.items():
print(f" {k}. {label}")
choice = input(" Enter number (1-5): ").strip()
if choice in VALID_TYPES:
pub_type = VALID_TYPES[choice]
break
print(" Invalid choice. Please enter 1-5.")
while True:
year_str = prompt("Year (or press Enter for forthcoming)", required=False)
if year_str is None:
year = None
break
try:
year = int(year_str)
break
except ValueError:
print(" Please enter a valid year number.")
url = prompt("URL (DOI or link)", required=False)
slides_link = None
if pub_type == "workshop":
slides_link = prompt("Slides link", required=False)
pub = {
"title": title,
"authors": authors,
"venue": venue,
"year": year,
"publication_type": pub_type,
"url": url,
"slides_link": slides_link,
}
if venue_es:
pub["venue_es"] = venue_es
# Load existing, add, save
with open(JSON_PATH, "r", encoding="utf-8") as f:
pubs = json.load(f)
pubs.append(pub)
with open(JSON_PATH, "w", encoding="utf-8", newline="\n") as f:
json.dump(pubs, f, indent=2, ensure_ascii=False)
f.write("\n")
print(f"\nAdded to {JSON_PATH}")
# Regenerate HTML
print("Regenerating HTML...")
from generate_html import main as generate
generate()
print("\nDone! Review the changes and commit when ready.")
if __name__ == "__main__":
main()