Add a cron job that runs at 5am to refresh the corpus
This commit is contained in:
parent
f87a14f0b9
commit
c1b56efb28
1 changed files with 19 additions and 5 deletions
24
bots.rb
24
bots.rb
|
@ -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|
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue