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