Add a cron job that runs at 5am to refresh the corpus

This commit is contained in:
Eryn Wells 2015-05-15 22:39:23 -07:00
parent f87a14f0b9
commit c1b56efb28

24
bots.rb
View file

@ -1,5 +1,7 @@
require 'fileutils'
require 'twitter_ebooks'
# Information about a particular Twitter user we know
class UserInfo
attr_reader :username
@ -14,6 +16,7 @@ class UserInfo
end
end
class ERWEbooksBot < Ebooks::Bot
attr_accessor :original, :model, :model_path
@ -31,10 +34,16 @@ class ERWEbooksBot < Ebooks::Bot
def on_startup
load_model!
scheduler.cron '0 0 * * *' do
# Each day at midnight, post a single tweet
scheduler.cron '23 6-23 * * *' do
# Post a tweet 23 minutes after every fourth hour.
tweet(model.make_statement)
end
scheduler.cron '0 5 * * *' do
# Every day at 5am update the corpus
archive!
load_model!
end
end
def on_message(dm)
@ -118,13 +127,18 @@ class ERWEbooksBot < Ebooks::Bot
private
def load_model!
return if @model
@model_path ||= "model/#{original}.model"
log "Loading model #{model_path}"
@model = Ebooks::Model.load(model_path)
end
private
def archive!
archive_path = "model/#{original}.json"
log "Archiving tweets #{archive_path}"
Ebooks::Archive.new(@original, archive_path).sync
Ebooks::Model.consume(archive_path).save(model_path)
end
end
ERWEbooksBot.new("erw_ebooks") do |bot|