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'
|
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|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue