summaryrefslogtreecommitdiff
path: root/get-commit-dates.py
diff options
context:
space:
mode:
Diffstat (limited to 'get-commit-dates.py')
-rw-r--r--get-commit-dates.py95
1 files changed, 95 insertions, 0 deletions
diff --git a/get-commit-dates.py b/get-commit-dates.py
new file mode 100644
index 0000000..53485d5
--- /dev/null
+++ b/get-commit-dates.py
@@ -0,0 +1,95 @@
+#!/usr/bin/env python3
+import json
+import subprocess
+
+INPUT_FILE = "static/js/data.json"
+OUTPUT_FILE = "data_with_dates.json"
+
+def get_git_info(filepath):
+ try:
+ cmd = [
+ "git", "log",
+ "--diff-filter=A",
+ "--follow",
+ "--reverse",
+ "--format=%ad|%an",
+ "--date=format:%Y-%m-%d",
+ "--", filepath
+ ]
+
+ output = subprocess.check_output(cmd, text=True).strip()
+ if not output:
+ return None, None
+
+ first_line = output.splitlines()[0]
+ date, author = first_line.split("|", 1)
+ return date, author
+
+ except subprocess.CalledProcessError:
+ return None, None
+
+
+with open(INPUT_FILE, "r", encoding="utf-8") as f:
+ data = json.load(f)
+
+
+cache = {}
+
+for key, entry in data.items():
+ image = entry.get("image")
+ if not image:
+ continue
+
+ if image not in cache:
+ cache[image] = get_git_info(image)
+
+ date, author = cache[image]
+
+ if date:
+ entry["date"] = date
+# if author:
+# entry["committer"] = author
+
+
+with open(OUTPUT_FILE, "w", encoding="utf-8") as f:
+ json.dump(data, f, indent=2, ensure_ascii=False)
+
+
+#import subprocess
+#import json
+#from pathlib import Path
+#
+#repo_path = Path(".")
+#images_path = repo_path / "static/images"
+#
+#result = {}
+#
+#for image in images_path.glob("*"):
+# try:
+# cmd = [
+# "git", "log",
+# "--diff-filter=A",
+# "--follow",
+# "--reverse",
+# "--format=%ad|%an",
+# "--date=format:%Y-%m-%d",
+# "--", str(image)
+# ]
+#
+# output = subprocess.check_output(cmd, text=True).strip()
+# if not output:
+# continue
+#
+# first_line = output.splitlines()[0]
+# date, author = first_line.split("|", 1)
+#
+# result[str(image)] = {
+# "date": date,
+# "committer": author
+# }
+#
+# except subprocess.CalledProcessError:
+# continue
+#
+#print(json.dumps(result, indent=2))
+#