Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- """
- 維基詞典統計自動更新機器人
- 從 wikistats.wmcloud.org 的 CSV API 獲取統計數據
- """
- import time
- from datetime import datetime, timezone
- from stats_updater_base import BaseStatsUpdater
- class WikipediaStatsUpdater(BaseStatsUpdater):
- """維基詞典統計更新器"""
- def __init__(self, username: str, password: str):
- """初始化維基詞典統計更新器"""
- super().__init__(
- username=username,
- password=password,
- site_domain='zh.wikipedia.org',
- target_languages=['pl', 'arz', 'zh', 'ja', 'uk'],
- csv_api_url='https://wikistats.wmcloud.org/api.php?action=dump&table=wikipedias&format=csv',
- page_title='Wikipedia:统计/与邻近条目数量的语言版本比较',
- log_filename='wikipedia_bot.log'
- )
- def _get_edit_summary(self, date: str) -> str:
- """獲取編輯摘要"""
- return f"機器人:更新每日統計數據 ({date})"
- def _is_bot_account(self) -> bool:
- """是否為機器人帳號"""
- return True # 維基詞典版本使用機器人帳號
- def main():
- """主函數"""
- # 機器人帳號憑證
- username = "USERNAME"
- password = "PASSWORD"
- # 檢查是否在正確的時間執行(UTC 1:15 之後)
- current_time = datetime.now(timezone.utc)
- target_time = current_time.replace(hour=1, minute=15, second=0, microsecond=0)
- if current_time < target_time:
- print(f"當前時間 {current_time.strftime('%H:%M')} UTC,等待到 01:15 UTC 後執行")
- sleep_seconds = (target_time - current_time).total_seconds()
- time.sleep(sleep_seconds)
- # 創建並運行機器人
- updater = WikipediaStatsUpdater(username, password)
- success = updater.run()
- if not success:
- exit(1)
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment