Skip to content

Commit b6c660b

Browse files
authored
Update generate_rss.py
1 parent a0b9092 commit b6c660b

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

generate_rss.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import os
2+
import subprocess
23
import xml.etree.ElementTree as ET
34
from xml.dom import minidom
45
from datetime import datetime
56

7+
68
# Define the RSS file and folder containing articles
79
docs_folder = "docs"
810
rss_file = os.path.join(docs_folder, "rss.xml") # Adjust path to rss.xml
@@ -12,6 +14,17 @@
1214
# Get the current timestamp in GMT
1315
current_date = datetime.utcnow().strftime("%a, %d %b %Y %H:%M:%S GMT")
1416

17+
def get_git_last_modified_time(file_path):
18+
try:
19+
# Get the last commit timestamp in UTC for the file
20+
output = subprocess.check_output(
21+
["git", "log", "-1", "--format=%ct", "--", file_path],
22+
text=True
23+
).strip()
24+
return int(output) # UNIX timestamp
25+
except Exception as e:
26+
print(f"Failed to get git modified time for {file_path}: {e}")
27+
return 0
1528

1629
def create_empty_rss_file(file_path):
1730
"""
@@ -34,11 +47,12 @@ def is_file_updated(file_path, existing_pub_date):
3447
:param existing_pub_date: Existing publication date in RSS feed.
3548
:return: True if the file has been updated, False otherwise.
3649
"""
37-
file_mod_time = os.path.getmtime(file_path)
50+
# file_mod_time = os.path.getmtime(file_path)
51+
git_mod_time = get_git_last_modified_time(file_path)
3852
existing_time = datetime.strptime(existing_pub_date, "%a, %d %b %Y %H:%M:%S GMT").timestamp()
39-
updated = file_mod_time > existing_time
53+
updated = git_mod_time > existing_time
4054
if updated:
41-
print(f"File {file_path} has been updated (mod_time: {file_mod_time}, existing_time: {existing_time})")
55+
print(f"File {file_path} has been updated (mod_time: {git_mod_time}, existing_time: {existing_time})")
4256
return updated
4357

4458

0 commit comments

Comments
 (0)