def execute
time_started = Time.now.utc
statistics_info_element = REXML::Document.new(File.new(STATISTICS_INFO_FILE_NAME), 'r').root
if @config == nil then
@config = Config.new(statistics_info_element.
get_elements('//' + STATISTICS_INFO_WORKING_DIRECTORY_ELEMENT_NAME).first.text)
end
log_file_name = @config.working_directory + '/log.txt'
logger = Logger.new([$stderr, File.new(log_file_name, 'a')])
logger.log '統計ページの更新'
date_time_format = DateTimeFormat.new()
logger.log '開始しました。 ' + date_time_format.format(time_started)
resource = Resource.new(logger)
StatisticsFetcher::STATISTICS_INFO_FILE_NAME
text = ''
text += @config.edit_header
File.new(NewStatisticsPage::FILE_NAME, 'r').readlines.each do |line|
text += line
end
bot = WikiBot.new(@config)
bot.login
bot.obtain_edit_token(@config.edit_target_page)
update_summary = statistics_info_element.
get_elements('//' + STATISTICS_INFO_UPDATE_SUMMARY_ELEMENT_NAME).first.text
logger.log '更新します。 - ' + @config.edit_target_page
bot.edit(@config.edit_target_page, text, update_summary)
logger.log '更新しました。 - ' + update_summary
bot.logout
time_ended = Time.now.utc
logger.log '終了しました。 ' + date_time_format.format(time_ended)
logger.log '要した時間: ' + (time_ended - time_started).to_s + ' 秒'
FileUtils.copy(log_file_name, '.')
end