-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist_recent_coauthors.py
More file actions
67 lines (52 loc) · 1.83 KB
/
Copy pathlist_recent_coauthors.py
File metadata and controls
67 lines (52 loc) · 1.83 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
#!/usr/bin/env python3
"""Print coauthors who have published with me in the last two years.
This script reads ``_data/co-authors.yml`` and outputs the names of all
coauthors whose most recent collaboration year is within the past two
years relative to the current calendar year.
The script tries to use PyYAML if available but falls back to a minimal
parser so it has no external dependencies.
"""
from __future__ import annotations
import datetime as _dt
from pathlib import Path
from typing import List, Dict, Any
try: # pragma: no cover - optional dependency
import yaml # type: ignore
except ModuleNotFoundError: # pragma: no cover - optional dependency
yaml = None # type: ignore
def _load_entries(path: Path) -> List[Dict[str, Any]]:
text = path.read_text(encoding="utf-8")
if yaml is not None:
return yaml.safe_load(text) or []
# Fallback minimal parser tailored for the file's simple structure
entries: List[Dict[str, Any]] = []
current: Dict[str, Any] = {}
for raw_line in text.splitlines():
line = raw_line.strip()
if not line:
continue
if line.startswith("- "):
if current:
entries.append(current)
current = {}
line = line[2:].strip()
if ":" in line:
key, value = line.split(":", 1)
current[key.strip()] = value.strip()
if current:
entries.append(current)
return entries
def main() -> None:
data_path = Path("_data") / "co-authors.yml"
entries = _load_entries(data_path)
current_year = _dt.date.today().year
cutoff = current_year - 4
recent = [
item.get("name")
for item in entries
if int(item.get("last_coauthored", 0)) >= cutoff
]
for name in recent:
print(name)
if __name__ == "__main__":
main()