11import os
2+ import subprocess
23import xml .etree .ElementTree as ET
34from xml .dom import minidom
45from datetime import datetime
56
7+
68# Define the RSS file and folder containing articles
79docs_folder = "docs"
810rss_file = os .path .join (docs_folder , "rss.xml" ) # Adjust path to rss.xml
1214# Get the current timestamp in GMT
1315current_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
1629def 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