Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- """
- 檢查今天是否已經更新過維基百科統計
- 返回碼:0 = 需要更新, 1 = 已更新
- """
- import sys
- from datetime import datetime
- from pathlib import Path
- def check_if_updated_today():
- """
- 檢查今天是否已更新
- 實作方式可以是:
- 1. 檢查日誌文件中最後成功的時間戳
- 2. 檢查維基百科頁面的最後編輯時間
- 3. 檢查本地狀態文件
- 這裡提供一個基於狀態文件的簡單實作
- """
- # 狀態文件路徑
- state_file = Path(__file__).parent / ".last_update_status.txt"
- today = datetime.now().strftime("%Y-%m-%d")
- try:
- if state_file.exists():
- last_update = state_file.read_text().strip()
- if last_update == today:
- print(f"今日({today})已完成更新")
- return True
- print(f"今日({today})尚未更新")
- return False
- except Exception as e:
- print(f"檢查狀態時出錯: {e}")
- # 發生錯誤時假設未更新,繼續執行
- return False
- if __name__ == "__main__":
- updated = check_if_updated_today()
- sys.exit(0 if updated else 1)
Advertisement
Add Comment
Please, Sign In to add comment