From 9b198c48986c0e354c6458ff74cd75474f612930 Mon Sep 17 00:00:00 2001 From: Preston Richey Date: Mon, 12 Jan 2015 23:06:16 -0600 Subject: [PATCH 01/39] Fix deprecation warning --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 139f4f9..abad733 100644 --- a/README.md +++ b/README.md @@ -135,10 +135,10 @@ The secondary function is the "interesting keywords" list. For example, I use th ``` ruby top100 = model.keywords.take(100) -tokens = Ebooks::NLP.tokenize(tweet[:text]) +tokens = Ebooks::NLP.tokenize(tweet.text) if tokens.find { |t| top100.include?(t) } - bot.favorite(tweet[:id]) + favorite(tweet) end ``` From 3352e3d6d420f574b4c473a4c9b6385946cc4119 Mon Sep 17 00:00:00 2001 From: Brett O'Connor Date: Tue, 19 May 2015 10:08:42 -0600 Subject: [PATCH 02/39] binary now shows version number when requested --- bin/ebooks | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/bin/ebooks b/bin/ebooks index 24a5120..c564df8 100755 --- a/bin/ebooks +++ b/bin/ebooks @@ -28,6 +28,7 @@ Usage: ebooks gen [input] ebooks archive [path] ebooks tweet + ebooks version STR def self.help(command=nil) @@ -275,6 +276,17 @@ STR require 'pry'; Ebooks.module_exec { pry } end + HELP.version = <<-STR + Usage: ebooks version + + Shows you twitter_ebooks' version number. + STR + + def self.version + require File.expand_path('../../lib/twitter_ebooks/version', __FILE__) + log Ebooks::VERSION + end + HELP.start = <<-STR Usage: ebooks s[tart] [botname] @@ -378,6 +390,7 @@ STR when "start" then start(args[1]) when "s" then start(args[1]) when "help" then help(args[1]) + when "version" then version else log "No such command '#{args[0]}'" help From d16ee04d5aebb804d574c3ac2082afb280a193ae Mon Sep 17 00:00:00 2001 From: Brett O'Connor Date: Tue, 19 May 2015 15:48:48 -0600 Subject: [PATCH 03/39] added append command usage is: ebooks append model path/to/corpus.csv --- bin/ebooks | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/bin/ebooks b/bin/ebooks index c564df8..9ce5a53 100755 --- a/bin/ebooks +++ b/bin/ebooks @@ -25,6 +25,7 @@ Usage: ebooks auth ebooks consume [corpus_path2] [...] ebooks consume-all [corpus_path2] [...] + ebooks append ebooks gen [input] ebooks archive [path] ebooks tweet @@ -116,6 +117,24 @@ STR log "Corpuses consumed to #{outpath}" end + HELP.append = <<-STR + Usage: ebooks append + + Process then append the provided corpus to the model + instead of overwriting. + STR + + def self.append(name, path) + if !name || !path + help :append + exit 1 + end + + Ebooks::Model.consume(path).append(File.join(APP_PATH,'model',"#{name}.model")) + log "Corpus appended to #{name}.model" + end + + HELP.jsonify = <<-STR Usage: ebooks jsonify [tweets.csv2] [...] @@ -380,6 +399,7 @@ STR when "new" then new(args[1]) when "consume" then consume(args[1..-1]) when "consume-all" then consume_all(args[1], args[2..-1]) + when "append" then append(args[1],args[2]) when "gen" then gen(args[1], args[2..-1].join(' ')) when "archive" then archive(args[1], args[2]) when "tweet" then tweet(args[1], args[2]) From 43491cb668b5eba3d016af6345532236905e9d05 Mon Sep 17 00:00:00 2001 From: Brett O'Connor Date: Tue, 19 May 2015 15:49:35 -0600 Subject: [PATCH 04/39] added append method which reads and adds to an existing model file --- lib/twitter_ebooks/model.rb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/lib/twitter_ebooks/model.rb b/lib/twitter_ebooks/model.rb index b3bbb13..2366379 100644 --- a/lib/twitter_ebooks/model.rb +++ b/lib/twitter_ebooks/model.rb @@ -69,6 +69,35 @@ module Ebooks self end + # Append a generated model to existing model file instead of overwriting it + # @param path [String] + def append(path) + existing = File.file?(path) + if !existing + log "No existing model found at #{path}" + return + else + #read-in and deserialize existing model + props = Marshal.load(File.open(path,'rb') { |old| old.read }) + old_tokens = props[:tokens] + old_sentences = props[:sentences] + old_mentions = props[:mentions] + old_keywords = props[:keywords] + + #append existing properties to new ones and overwrite with new model + File.open(path, 'wb') do |f| + f.write(Marshal.dump({ + tokens: @tokens.concat(old_tokens), + sentences: @sentences.concat(old_sentences), + mentions: @mentions.concat(old_mentions), + keywords: @keywords.concat(old_keywords) + })) + end + end + self + end + + def initialize @tokens = [] From a885d5fe228945639a7a3767fbde3fd3ff3512fd Mon Sep 17 00:00:00 2001 From: Joshua Charles Campbell Date: Thu, 4 Jun 2015 10:46:01 -0600 Subject: [PATCH 05/39] stuff I had to change to get the bot working --- lib/twitter_ebooks/model.rb | 15 ++++++++++++--- lib/twitter_ebooks/nlp.rb | 2 +- lib/twitter_ebooks/suffix.rb | 3 +++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/twitter_ebooks/model.rb b/lib/twitter_ebooks/model.rb index b3bbb13..8849118 100644 --- a/lib/twitter_ebooks/model.rb +++ b/lib/twitter_ebooks/model.rb @@ -80,7 +80,13 @@ module Ebooks # @param token [String] # @return [Integer] def tikify(token) - @tikis[token] or (@tokens << token and @tikis[token] = @tokens.length-1) + if @tikis.has_key?(token) then + return @tikis[token] + else + (@tokens.length+1)%1000 == 0 and puts "#{@tokens.length+1} tokens" + @tokens << token + return @tikis[token] = @tokens.length-1 + end end # Convert a body of text into arrays of tikis @@ -143,8 +149,8 @@ module Ebooks end end - text = statements.join("\n") - mention_text = mentions.join("\n") + text = statements.join("\n").encode('UTF-8', :invalid => :replace) + mention_text = mentions.join("\n").encode('UTF-8', :invalid => :replace) lines = nil; statements = nil; mentions = nil # Allow garbage collection @@ -155,6 +161,7 @@ module Ebooks log "Ranking keywords" @keywords = NLP.keywords(text).top(200).map(&:to_s) + log "Top keywords: #{@keywords[0]} #{@keywords[1]} #{@keywords[2]}" self end @@ -218,6 +225,7 @@ module Ebooks tweet = "" while (tikis = generator.generate(3, :bigrams)) do + log "Attempting to produce tweet try #{retries+1}/#{retry_limit}" next if tikis.length <= 3 && !responding break if valid_tweet?(tikis, limit) @@ -226,6 +234,7 @@ module Ebooks end if verbatim?(tikis) && tikis.length > 3 # We made a verbatim tweet by accident + log "Attempting to produce unigram tweet try #{retries+1}/#{retry_limit}" while (tikis = generator.generate(3, :unigrams)) do break if valid_tweet?(tikis, limit) && !verbatim?(tikis) diff --git a/lib/twitter_ebooks/nlp.rb b/lib/twitter_ebooks/nlp.rb index 541720b..b65e162 100644 --- a/lib/twitter_ebooks/nlp.rb +++ b/lib/twitter_ebooks/nlp.rb @@ -1,6 +1,7 @@ # encoding: utf-8 require 'fast-stemmer' require 'highscore' +require 'htmlentities' module Ebooks module NLP @@ -42,7 +43,6 @@ module Ebooks # Lazily load HTML entity decoder # @return [HTMLEntities] def self.htmlentities - require 'htmlentities' @htmlentities ||= HTMLEntities.new end diff --git a/lib/twitter_ebooks/suffix.rb b/lib/twitter_ebooks/suffix.rb index ff57f97..aa2b791 100644 --- a/lib/twitter_ebooks/suffix.rb +++ b/lib/twitter_ebooks/suffix.rb @@ -19,6 +19,9 @@ module Ebooks @bigrams = {} @sentences.each_with_index do |tikis, i| + if (i % 10000 == 0) then + log ("Building: sentence #{i} of #{sentences.length}") + end last_tiki = INTERIM tikis.each_with_index do |tiki, j| @unigrams[last_tiki] ||= [] From e95d63e14c27efdcb11c3012ce30003e814c6f18 Mon Sep 17 00:00:00 2001 From: Jaiden Mispy Date: Fri, 25 Sep 2015 01:29:44 -0700 Subject: [PATCH 06/39] Explicitly require twitter gem ~> 5.15 due to #91 --- twitter_ebooks.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/twitter_ebooks.gemspec b/twitter_ebooks.gemspec index 9e2550a..3d7ea22 100644 --- a/twitter_ebooks.gemspec +++ b/twitter_ebooks.gemspec @@ -22,7 +22,7 @@ Gem::Specification.new do |gem| gem.add_development_dependency 'pry-byebug' gem.add_development_dependency 'yard' - gem.add_runtime_dependency 'twitter', '~> 5.0' + gem.add_runtime_dependency 'twitter', '~> 5.15' gem.add_runtime_dependency 'rufus-scheduler' gem.add_runtime_dependency 'gingerice' gem.add_runtime_dependency 'htmlentities' From 0e557ff7b468742e33f8c85d2095ce189fd60a53 Mon Sep 17 00:00:00 2001 From: Jaiden Mispy Date: Fri, 25 Sep 2015 01:30:48 -0700 Subject: [PATCH 07/39] 3.1.1 --- lib/twitter_ebooks/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/twitter_ebooks/version.rb b/lib/twitter_ebooks/version.rb index fe65e50..b666bf5 100644 --- a/lib/twitter_ebooks/version.rb +++ b/lib/twitter_ebooks/version.rb @@ -1,3 +1,3 @@ module Ebooks - VERSION = "3.1.0" + VERSION = "3.1.1" end From feab8383cc6cafa93ed13829d7bb3a2d6abc2340 Mon Sep 17 00:00:00 2001 From: Jaiden Mispy Date: Fri, 25 Sep 2015 01:35:24 -0700 Subject: [PATCH 08/39] ...rather, require twitter 5.14 due to #91 --- twitter_ebooks.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/twitter_ebooks.gemspec b/twitter_ebooks.gemspec index 3d7ea22..40ea64e 100644 --- a/twitter_ebooks.gemspec +++ b/twitter_ebooks.gemspec @@ -22,7 +22,7 @@ Gem::Specification.new do |gem| gem.add_development_dependency 'pry-byebug' gem.add_development_dependency 'yard' - gem.add_runtime_dependency 'twitter', '~> 5.15' + gem.add_runtime_dependency 'twitter', '= 5.14' gem.add_runtime_dependency 'rufus-scheduler' gem.add_runtime_dependency 'gingerice' gem.add_runtime_dependency 'htmlentities' From 17d5c266d0b95180ea3509881a114b83a348efb0 Mon Sep 17 00:00:00 2001 From: Jaiden Mispy Date: Fri, 25 Sep 2015 01:36:37 -0700 Subject: [PATCH 09/39] 3.1.2 --- lib/twitter_ebooks/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/twitter_ebooks/version.rb b/lib/twitter_ebooks/version.rb index b666bf5..14b6392 100644 --- a/lib/twitter_ebooks/version.rb +++ b/lib/twitter_ebooks/version.rb @@ -1,3 +1,3 @@ module Ebooks - VERSION = "3.1.1" + VERSION = "3.1.2" end From 3402506dd3a5013c3e37a3c2230818ea9e462cf3 Mon Sep 17 00:00:00 2001 From: Alina Saalfeld Date: Tue, 29 Sep 2015 16:52:46 +0200 Subject: [PATCH 10/39] Fix utf-8 in keywords --- lib/twitter_ebooks/nlp.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/twitter_ebooks/nlp.rb b/lib/twitter_ebooks/nlp.rb index b65e162..3fb9ea3 100644 --- a/lib/twitter_ebooks/nlp.rb +++ b/lib/twitter_ebooks/nlp.rb @@ -99,7 +99,7 @@ module Ebooks #set :vowels, 1 # => default: 0 = not considered #set :consonants, 5 # => default: 0 = not considered #set :ignore_case, true # => default: false - set :word_pattern, /(? default: /\w+/ + set :word_pattern, /(? default: /\w+/ #set :stemming, true # => default: false end From 18922ee3b5c4c93738370dc3bacd883af792ff92 Mon Sep 17 00:00:00 2001 From: Alina Saalfeld Date: Tue, 29 Sep 2015 17:17:30 +0200 Subject: [PATCH 11/39] Move stopwords.txt to be accessable by bot developer --- lib/twitter_ebooks/nlp.rb | 4 ++-- {data => skeleton}/stopwords.txt | 0 2 files changed, 2 insertions(+), 2 deletions(-) rename {data => skeleton}/stopwords.txt (100%) diff --git a/lib/twitter_ebooks/nlp.rb b/lib/twitter_ebooks/nlp.rb index 3fb9ea3..f971f0c 100644 --- a/lib/twitter_ebooks/nlp.rb +++ b/lib/twitter_ebooks/nlp.rb @@ -14,10 +14,10 @@ module Ebooks # to be using it all of the time # Lazily loads an array of stopwords - # Stopwords are common English words that should often be ignored + # Stopwords are common words that should often be ignored # @return [Array] def self.stopwords - @stopwords ||= File.read(File.join(DATA_PATH, 'stopwords.txt')).split + @stopwords ||= File.exists?('stopwords.txt') ? File.read('stopwords.txt').split : [] end # Lazily loads an array of known English nouns diff --git a/data/stopwords.txt b/skeleton/stopwords.txt similarity index 100% rename from data/stopwords.txt rename to skeleton/stopwords.txt From 05f47d4bd04624d80347a0453565fb70d88b243a Mon Sep 17 00:00:00 2001 From: Jaiden Mispy Date: Mon, 2 Nov 2015 17:10:30 -0800 Subject: [PATCH 12/39] Make model dir on consume if not exist Fixes #93 --- bin/ebooks | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/bin/ebooks b/bin/ebooks index 9ce5a53..e4cdb30 100755 --- a/bin/ebooks +++ b/bin/ebooks @@ -93,7 +93,9 @@ STR filename = File.basename(path) shortname = filename.split('.')[0..-2].join('.') + FileUtils.mkdir_p(File.join(APP_PATH, 'model')) outpath = File.join(APP_PATH, 'model', "#{shortname}.model") + Ebooks::Model.consume(path).save(outpath) log "Corpus consumed to #{outpath}" end @@ -120,7 +122,7 @@ STR HELP.append = <<-STR Usage: ebooks append - Process then append the provided corpus to the model + Process then append the provided corpus to the model instead of overwriting. STR @@ -133,7 +135,7 @@ STR Ebooks::Model.consume(path).append(File.join(APP_PATH,'model',"#{name}.model")) log "Corpus appended to #{name}.model" end - + HELP.jsonify = <<-STR Usage: ebooks jsonify [tweets.csv2] [...] @@ -300,7 +302,7 @@ STR Shows you twitter_ebooks' version number. STR - + def self.version require File.expand_path('../../lib/twitter_ebooks/version', __FILE__) log Ebooks::VERSION From b3ab5665c8e80e66e5cab3813a9c7cc68a44f8f5 Mon Sep 17 00:00:00 2001 From: Jaiden Mispy Date: Mon, 14 Dec 2015 16:38:47 -0800 Subject: [PATCH 13/39] Add note about ~/.ebooksrc to archive help --- bin/ebooks | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/bin/ebooks b/bin/ebooks index e4cdb30..31b9907 100755 --- a/bin/ebooks +++ b/bin/ebooks @@ -211,6 +211,11 @@ STR Output defaults to corpus/.json Due to API limitations, this can only receive up to ~3000 tweets into the past. + + The first time you run archive, you will need to enter the auth + details of some account to use for accessing the API. This info + will then be stored in ~/.ebooksrc for later use, and can be + modified there if needed. STR def self.archive(username, outpath=nil) From cbec61510835fdf28becc133cbc6484a359b546d Mon Sep 17 00:00:00 2001 From: Rachel Hyman Date: Fri, 8 Jan 2016 16:33:05 -0600 Subject: [PATCH 14/39] Don't reply to blacklisted users --- lib/twitter_ebooks/bot.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/twitter_ebooks/bot.rb b/lib/twitter_ebooks/bot.rb index 29e6814..9526cac 100644 --- a/lib/twitter_ebooks/bot.rb +++ b/lib/twitter_ebooks/bot.rb @@ -267,6 +267,8 @@ module Ebooks if blacklisted?(ev.user.screen_name) log "Blocking blacklisted user @#{ev.user.screen_name}" @twitter.block(ev.user.screen_name) + # we don't want to reply to blacklisted users, so return + return end # Avoid responding to duplicate tweets From 25e3724f4d22b84675212136592ead889bae6601 Mon Sep 17 00:00:00 2001 From: Jaiden Mispy Date: Tue, 12 Jan 2016 23:28:53 -0800 Subject: [PATCH 15/39] Raise memory expectation in test slightly --- lib/twitter_ebooks/model.rb | 4 ++-- spec/model_spec.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/twitter_ebooks/model.rb b/lib/twitter_ebooks/model.rb index a40b046..092098b 100644 --- a/lib/twitter_ebooks/model.rb +++ b/lib/twitter_ebooks/model.rb @@ -96,7 +96,7 @@ module Ebooks end self end - + def initialize @tokens = [] @@ -113,7 +113,7 @@ module Ebooks return @tikis[token] else (@tokens.length+1)%1000 == 0 and puts "#{@tokens.length+1} tokens" - @tokens << token + @tokens << token return @tikis[token] = @tokens.length-1 end end diff --git a/spec/model_spec.rb b/spec/model_spec.rb index a8a85f7..2d2d039 100644 --- a/spec/model_spec.rb +++ b/spec/model_spec.rb @@ -36,7 +36,7 @@ describe Ebooks::Model do report2 = MemoryUsage.report do model = Ebooks::Model.load(file.path) end - expect(report2.total_memsize).to be < 3000000 + expect(report2.total_memsize).to be < 4000000 expect(model.tokens[0]).to be_a String expect(model.sentences[0][0]).to be_a Fixnum From 554aa2654ce883f374f7ee63ebaea2a8452e924a Mon Sep 17 00:00:00 2001 From: Jaiden Mispy Date: Tue, 12 Jan 2016 23:36:21 -0800 Subject: [PATCH 16/39] Monkeypatch to fix #91 with current twitter gem --- lib/twitter_ebooks/bot.rb | 10 ++++++++-- twitter_ebooks.gemspec | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/twitter_ebooks/bot.rb b/lib/twitter_ebooks/bot.rb index 9526cac..b7596e8 100644 --- a/lib/twitter_ebooks/bot.rb +++ b/lib/twitter_ebooks/bot.rb @@ -2,6 +2,14 @@ require 'twitter' require 'rufus/scheduler' +# Monkeypatch hack to fix upstream dependency issue +# https://github.com/sferik/twitter/issues/709 +class HTTP::URI + def port + 443 if self.https? + end +end + module Ebooks class ConfigurationError < Exception end @@ -267,8 +275,6 @@ module Ebooks if blacklisted?(ev.user.screen_name) log "Blocking blacklisted user @#{ev.user.screen_name}" @twitter.block(ev.user.screen_name) - # we don't want to reply to blacklisted users, so return - return end # Avoid responding to duplicate tweets diff --git a/twitter_ebooks.gemspec b/twitter_ebooks.gemspec index 40ea64e..3d7ea22 100644 --- a/twitter_ebooks.gemspec +++ b/twitter_ebooks.gemspec @@ -22,7 +22,7 @@ Gem::Specification.new do |gem| gem.add_development_dependency 'pry-byebug' gem.add_development_dependency 'yard' - gem.add_runtime_dependency 'twitter', '= 5.14' + gem.add_runtime_dependency 'twitter', '~> 5.15' gem.add_runtime_dependency 'rufus-scheduler' gem.add_runtime_dependency 'gingerice' gem.add_runtime_dependency 'htmlentities' From 14f82a716f8401a391a71e94bbf6aa6f8940e11c Mon Sep 17 00:00:00 2001 From: Jaiden Mispy Date: Wed, 13 Jan 2016 00:06:41 -0800 Subject: [PATCH 17/39] Don't infinite loop for very small tweets. #78 --- lib/twitter_ebooks/model.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/twitter_ebooks/model.rb b/lib/twitter_ebooks/model.rb index 092098b..0b45baf 100644 --- a/lib/twitter_ebooks/model.rb +++ b/lib/twitter_ebooks/model.rb @@ -255,8 +255,7 @@ module Ebooks while (tikis = generator.generate(3, :bigrams)) do log "Attempting to produce tweet try #{retries+1}/#{retry_limit}" - next if tikis.length <= 3 && !responding - break if valid_tweet?(tikis, limit) + break if (tikis.length > 3 || responding) && valid_tweet?(tikis, limit) retries += 1 break if retries >= retry_limit From 473d84ba2222faae3e38b6010c7f2b0f7f77c124 Mon Sep 17 00:00:00 2001 From: Jaiden Mispy Date: Wed, 13 Jan 2016 00:12:16 -0800 Subject: [PATCH 18/39] 3.1.3 --- lib/twitter_ebooks/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/twitter_ebooks/version.rb b/lib/twitter_ebooks/version.rb index 14b6392..7577d26 100644 --- a/lib/twitter_ebooks/version.rb +++ b/lib/twitter_ebooks/version.rb @@ -1,3 +1,3 @@ module Ebooks - VERSION = "3.1.2" + VERSION = "3.1.3" end From 8320576ab3e7ea2a58497d7ed2ceb3775c5a1097 Mon Sep 17 00:00:00 2001 From: Jaiden Mispy Date: Wed, 13 Jan 2016 00:34:38 -0800 Subject: [PATCH 19/39] Don't run more passes if no variant. Fixes #79 --- lib/twitter_ebooks/suffix.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/twitter_ebooks/suffix.rb b/lib/twitter_ebooks/suffix.rb index aa2b791..d44d88d 100644 --- a/lib/twitter_ebooks/suffix.rb +++ b/lib/twitter_ebooks/suffix.rb @@ -89,7 +89,11 @@ module Ebooks break if variant end - tikis = variant if variant + # If we failed to produce a variation from any alternative, there + # is no use running additional passes-- they'll have the same result. + break if variant.nil? + + tikis = variant end tikis From 951669e972d77b608ee923979c2e17fa6573c04c Mon Sep 17 00:00:00 2001 From: Jaiden Mispy Date: Wed, 13 Jan 2016 00:58:38 -0800 Subject: [PATCH 20/39] Error before archive download if file inaccessible Fixes #85 --- lib/twitter_ebooks/archive.rb | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/twitter_ebooks/archive.rb b/lib/twitter_ebooks/archive.rb index 29829e2..c822fbe 100644 --- a/lib/twitter_ebooks/archive.rb +++ b/lib/twitter_ebooks/archive.rb @@ -50,7 +50,8 @@ module Ebooks @client = client || make_client if File.exists?(@path) - @tweets = JSON.parse(File.read(@path, :encoding => 'utf-8'), symbolize_names: true) + @filetext = File.read(@path, :encoding => 'utf-8') + @tweets = JSON.parse(@filetext, symbolize_names: true) log "Currently #{@tweets.length} tweets for #{@username}" else @tweets.nil? @@ -59,6 +60,21 @@ module Ebooks end def sync + # We use this structure to ensure that + # a) if there's an issue opening the file, we error out before download + # b) if there's an issue during download we restore the original + File.open(@path, 'w') do |file| + begin + sync_to(file) + rescue Exception + file.seek(0) + file.write(@filetext) + raise + end + end + end + + def sync_to(file) retries = 0 tweets = [] max_id = nil @@ -93,9 +109,7 @@ module Ebooks @tweets = tweets.map(&:attrs).each { |tw| tw.delete(:entities) } + @tweets - File.open(@path, 'w') do |f| - f.write(JSON.pretty_generate(@tweets)) - end + file.write(JSON.pretty_generate(@tweets)) end end end From 20dff3a148e7a2c4b9b8ad730044a90a8585b6da Mon Sep 17 00:00:00 2001 From: Jaiden Mispy Date: Wed, 13 Jan 2016 01:29:33 -0800 Subject: [PATCH 21/39] Fire event when someone retweets us. Fixes #76 --- lib/twitter_ebooks/bot.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/twitter_ebooks/bot.rb b/lib/twitter_ebooks/bot.rb index b7596e8..af00d3b 100644 --- a/lib/twitter_ebooks/bot.rb +++ b/lib/twitter_ebooks/bot.rb @@ -270,6 +270,12 @@ module Ebooks return unless ev.text # If it's not a text-containing tweet, ignore it return if ev.user.id == @user.id # Ignore our own tweets + if ev.retweet? && ev.retweeted_tweet.user.id == @user.id + # Someone retweeted our tweet! + fire(:retweet, ev) + return + end + meta = meta(ev) if blacklisted?(ev.user.screen_name) From 7f74849d0f941ca2785462c1bf144624a80982aa Mon Sep 17 00:00:00 2001 From: Jaiden Mispy Date: Wed, 13 Jan 2016 02:27:24 -0800 Subject: [PATCH 22/39] Add on_retweet to skeleton/README --- README.md | 10 ++++++++++ skeleton/bots.rb | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/README.md b/README.md index e8e1f88..c6f4934 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,16 @@ class MyBot < Ebooks::Bot # Reply to a tweet in the bot's timeline # reply(tweet, meta(tweet).reply_prefix + "nice tweet") end + + def on_favorite(user, tweet) + # Follow user who just favorited bot's tweet + # follow(user.screen_name) + end + + def on_retweet(tweet) + # Follow user who just retweeted bot's tweet + # follow(tweet.user.screen_name) + end end # Make a MyBot and attach it to an account diff --git a/skeleton/bots.rb b/skeleton/bots.rb index 1d1f313..12cdfa7 100644 --- a/skeleton/bots.rb +++ b/skeleton/bots.rb @@ -51,6 +51,11 @@ class MyBot < Ebooks::Bot # Follow user who just favorited bot's tweet # follow(user.screen_name) end + + def on_retweet(tweet) + # Follow user who just retweeted bot's tweet + # follow(tweet.user.screen_name) + end end # Make a MyBot and attach it to an account From 9976b6ddb7be19e5ca3e11f4261ec0cdcf4642a7 Mon Sep 17 00:00:00 2001 From: Jaiden Mispy Date: Wed, 13 Jan 2016 02:51:31 -0800 Subject: [PATCH 23/39] Force unix line endings on checkout --- .gitattributes | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..e895a20 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Require \n style line endings +* text eol=lf From 52f2dbd8ffad1d1a2d5b2d8be86652b3da4ed8f4 Mon Sep 17 00:00:00 2001 From: Jaiden Mispy Date: Wed, 13 Jan 2016 02:53:56 -0800 Subject: [PATCH 24/39] Require Ruby 2.1+ for GC::INTERNAL_CONSTANTS --- .travis.yml | 2 +- README.md | 2 +- twitter_ebooks.gemspec | 70 ++++++++++++++++++++++-------------------- 3 files changed, 38 insertions(+), 36 deletions(-) diff --git a/.travis.yml b/.travis.yml index df0c8fd..e31cc43 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ rvm: - - 2.1.4 + - 2.1.7 script: - rspec spec notifications: diff --git a/README.md b/README.md index c6f4934..07d1c2b 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Note that 3.0 is not backwards compatible with 2.x, so upgrade carefully! In par ## Installation -Requires Ruby 2.0+ +Requires Ruby 2.1+. Ruby 2.3+ is recommended. ```bash gem install twitter_ebooks diff --git a/twitter_ebooks.gemspec b/twitter_ebooks.gemspec index 3d7ea22..6cb0200 100644 --- a/twitter_ebooks.gemspec +++ b/twitter_ebooks.gemspec @@ -1,34 +1,36 @@ -# -*- encoding: utf-8 -*- -require File.expand_path('../lib/twitter_ebooks/version', __FILE__) - -Gem::Specification.new do |gem| - gem.authors = ["Jaiden Mispy"] - gem.email = ["^_^@mispy.me"] - gem.description = %q{Markov chains for all your friends~} - gem.summary = %q{Markov chains for all your friends~} - gem.homepage = "" - - gem.files = `git ls-files`.split($\) - gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) } - gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) - gem.name = "twitter_ebooks" - gem.require_paths = ["lib"] - gem.version = Ebooks::VERSION - - gem.add_development_dependency 'rspec' - gem.add_development_dependency 'rspec-mocks' - gem.add_development_dependency 'memory_profiler' - gem.add_development_dependency 'timecop' - gem.add_development_dependency 'pry-byebug' - gem.add_development_dependency 'yard' - - gem.add_runtime_dependency 'twitter', '~> 5.15' - gem.add_runtime_dependency 'rufus-scheduler' - gem.add_runtime_dependency 'gingerice' - gem.add_runtime_dependency 'htmlentities' - gem.add_runtime_dependency 'engtagger' - gem.add_runtime_dependency 'fast-stemmer' - gem.add_runtime_dependency 'highscore' - gem.add_runtime_dependency 'pry' - gem.add_runtime_dependency 'oauth' -end +# -*- encoding: utf-8 -*- +require File.expand_path('../lib/twitter_ebooks/version', __FILE__) + +Gem::Specification.new do |gem| + gem.required_ruby_version = '~> 2.1' + + gem.authors = ["Jaiden Mispy"] + gem.email = ["^_^@mispy.me"] + gem.description = %q{Markov chains for all your friends~} + gem.summary = %q{Markov chains for all your friends~} + gem.homepage = "" + + gem.files = `git ls-files`.split($\) + gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) } + gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) + gem.name = "twitter_ebooks" + gem.require_paths = ["lib"] + gem.version = Ebooks::VERSION + + gem.add_development_dependency 'rspec' + gem.add_development_dependency 'rspec-mocks' + gem.add_development_dependency 'memory_profiler' + gem.add_development_dependency 'timecop' + gem.add_development_dependency 'pry-byebug' + gem.add_development_dependency 'yard' + + gem.add_runtime_dependency 'twitter', '~> 5.15' + gem.add_runtime_dependency 'rufus-scheduler' + gem.add_runtime_dependency 'gingerice' + gem.add_runtime_dependency 'htmlentities' + gem.add_runtime_dependency 'engtagger' + gem.add_runtime_dependency 'fast-stemmer' + gem.add_runtime_dependency 'highscore' + gem.add_runtime_dependency 'pry' + gem.add_runtime_dependency 'oauth' +end From ee6fd9c4c41c0e6ee34676becc1f5c564fddf578 Mon Sep 17 00:00:00 2001 From: Jaiden Mispy Date: Wed, 13 Jan 2016 03:16:40 -0800 Subject: [PATCH 25/39] 3.1.4 --- lib/twitter_ebooks/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/twitter_ebooks/version.rb b/lib/twitter_ebooks/version.rb index 7577d26..4202773 100644 --- a/lib/twitter_ebooks/version.rb +++ b/lib/twitter_ebooks/version.rb @@ -1,3 +1,3 @@ module Ebooks - VERSION = "3.1.3" + VERSION = "3.1.4" end From 21f2f84a790dd3660ffc9c9363aa5de0c27fd0e4 Mon Sep 17 00:00:00 2001 From: Jaiden Mispy Date: Fri, 15 Jan 2016 15:59:16 -0800 Subject: [PATCH 26/39] Don't zero the archive file if no new tweets (ick) --- lib/twitter_ebooks/archive.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/twitter_ebooks/archive.rb b/lib/twitter_ebooks/archive.rb index c822fbe..4a7a872 100644 --- a/lib/twitter_ebooks/archive.rb +++ b/lib/twitter_ebooks/archive.rb @@ -109,8 +109,8 @@ module Ebooks @tweets = tweets.map(&:attrs).each { |tw| tw.delete(:entities) } + @tweets - file.write(JSON.pretty_generate(@tweets)) end + file.write(JSON.pretty_generate(@tweets)) end end end From dbae6d3499116678f1cd50d376ca6d3e4c66947d Mon Sep 17 00:00:00 2001 From: Jaiden Mispy Date: Fri, 15 Jan 2016 15:59:50 -0800 Subject: [PATCH 27/39] 3.1.5 --- lib/twitter_ebooks/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/twitter_ebooks/version.rb b/lib/twitter_ebooks/version.rb index 4202773..2042b2d 100644 --- a/lib/twitter_ebooks/version.rb +++ b/lib/twitter_ebooks/version.rb @@ -1,3 +1,3 @@ module Ebooks - VERSION = "3.1.4" + VERSION = "3.1.5" end From a272bd69ca1b4731ee917ac5220d0097bb57f8f7 Mon Sep 17 00:00:00 2001 From: Jaiden Mispy Date: Thu, 21 Jan 2016 12:51:33 -0800 Subject: [PATCH 28/39] Handle edge-case corpuses with short sentences --- lib/twitter_ebooks/model.rb | 6 +++--- lib/twitter_ebooks/suffix.rb | 2 +- spec/model_spec.rb | 14 ++++++++++++++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/twitter_ebooks/model.rb b/lib/twitter_ebooks/model.rb index 0b45baf..cfb56a5 100644 --- a/lib/twitter_ebooks/model.rb +++ b/lib/twitter_ebooks/model.rb @@ -183,7 +183,7 @@ module Ebooks lines = nil; statements = nil; mentions = nil # Allow garbage collection - log "Tokenizing #{text.count('\n')} statements and #{mention_text.count('\n')} mentions" + log "Tokenizing #{text.count("\n")} statements and #{mention_text.count("\n")} mentions" @sentences = mass_tikify(text) @mentions = mass_tikify(mention_text) @@ -254,7 +254,7 @@ module Ebooks tweet = "" while (tikis = generator.generate(3, :bigrams)) do - log "Attempting to produce tweet try #{retries+1}/#{retry_limit}" + #log "Attempting to produce tweet try #{retries+1}/#{retry_limit}" break if (tikis.length > 3 || responding) && valid_tweet?(tikis, limit) retries += 1 @@ -262,7 +262,7 @@ module Ebooks end if verbatim?(tikis) && tikis.length > 3 # We made a verbatim tweet by accident - log "Attempting to produce unigram tweet try #{retries+1}/#{retry_limit}" + #log "Attempting to produce unigram tweet try #{retries+1}/#{retry_limit}" while (tikis = generator.generate(3, :unigrams)) do break if valid_tweet?(tikis, limit) && !verbatim?(tikis) diff --git a/lib/twitter_ebooks/suffix.rb b/lib/twitter_ebooks/suffix.rb index d44d88d..6ac30a4 100644 --- a/lib/twitter_ebooks/suffix.rb +++ b/lib/twitter_ebooks/suffix.rb @@ -14,7 +14,7 @@ module Ebooks end def initialize(sentences) - @sentences = sentences.reject { |s| s.length < 2 } + @sentences = sentences @unigrams = {} @bigrams = {} diff --git a/spec/model_spec.rb b/spec/model_spec.rb index 2d2d039..5ff9f39 100644 --- a/spec/model_spec.rb +++ b/spec/model_spec.rb @@ -70,5 +70,19 @@ describe Ebooks::Model do file.unlink end + + it 'handles strange unicode edge-cases' do + file = Tempfile.new('unicode') + file.write("šŸ’ž\nšŸ’ž") + file.close + + model = Ebooks::Model.consume(file.path) + expect(model.mentions.count).to eq 0 + expect(model.sentences.count).to eq 2 + + file.unlink + + p model.make_statement + end end end From 2cbd7949697003576fe5eda2a6d0724cb9eb54a5 Mon Sep 17 00:00:00 2001 From: Jaiden Mispy Date: Fri, 22 Jan 2016 07:58:19 +1100 Subject: [PATCH 29/39] 3.1.6 --- lib/twitter_ebooks/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/twitter_ebooks/version.rb b/lib/twitter_ebooks/version.rb index 2042b2d..b4a936d 100644 --- a/lib/twitter_ebooks/version.rb +++ b/lib/twitter_ebooks/version.rb @@ -1,3 +1,3 @@ module Ebooks - VERSION = "3.1.5" + VERSION = "3.1.6" end From 7df08f95318181d940c3758e30f4e64d92be9652 Mon Sep 17 00:00:00 2001 From: Jaiden Mispy Date: Thu, 4 Feb 2016 18:11:50 +1100 Subject: [PATCH 30/39] There may still be empty sentences in suffix model --- lib/twitter_ebooks/suffix.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/twitter_ebooks/suffix.rb b/lib/twitter_ebooks/suffix.rb index 6ac30a4..f409588 100644 --- a/lib/twitter_ebooks/suffix.rb +++ b/lib/twitter_ebooks/suffix.rb @@ -14,7 +14,7 @@ module Ebooks end def initialize(sentences) - @sentences = sentences + @sentences = sentences.reject { |s| s.empty? } @unigrams = {} @bigrams = {} From 36a64736bf45eac179b8b4c150fb9ac4aa3d25ad Mon Sep 17 00:00:00 2001 From: Jaiden Mispy Date: Fri, 5 Feb 2016 05:37:37 +1100 Subject: [PATCH 31/39] Add note to suffix.rb about tikis --- lib/twitter_ebooks/suffix.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/twitter_ebooks/suffix.rb b/lib/twitter_ebooks/suffix.rb index f409588..5c250c0 100644 --- a/lib/twitter_ebooks/suffix.rb +++ b/lib/twitter_ebooks/suffix.rb @@ -1,12 +1,15 @@ # encoding: utf-8 module Ebooks - # This generator uses data identical to a markov model, but + # This generator uses data similar to a Markov model, but # instead of making a chain by looking up bigrams it uses the - # positions to randomly replace suffixes in one sentence with - # matching suffixes in another + # positions to randomly replace token array suffixes in one sentence + # with matching suffixes in another class SuffixGenerator # Build a generator from a corpus of tikified sentences + # "tikis" are token indexes-- a way of representing words + # and punctuation as their integer position in a big array + # of such tokens # @param sentences [Array>] # @return [SuffixGenerator] def self.build(sentences) @@ -45,7 +48,6 @@ module Ebooks self end - # Generate a recombined sequence of tikis # @param passes [Integer] number of times to recombine # @param n [Symbol] :unigrams or :bigrams (affects how conservative the model is) From 55143feed46e54b6343fd8b97a60a1ebad6ed068 Mon Sep 17 00:00:00 2001 From: Effy Elden Date: Mon, 22 Feb 2016 23:12:25 +0800 Subject: [PATCH 32/39] Fixed bug where an empty corpus .json would cause archive command to fail --- lib/twitter_ebooks/archive.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/twitter_ebooks/archive.rb b/lib/twitter_ebooks/archive.rb index 4a7a872..d0776e3 100644 --- a/lib/twitter_ebooks/archive.rb +++ b/lib/twitter_ebooks/archive.rb @@ -49,7 +49,7 @@ module Ebooks @client = client || make_client - if File.exists?(@path) + if (File.exists?(@path) && !File.zero?(@path)) @filetext = File.read(@path, :encoding => 'utf-8') @tweets = JSON.parse(@filetext, symbolize_names: true) log "Currently #{@tweets.length} tweets for #{@username}" From 8bbe22f55cf624e183de4b0605a96ebcc999161f Mon Sep 17 00:00:00 2001 From: Jaiden Mispy Date: Tue, 23 Feb 2016 06:59:35 +1100 Subject: [PATCH 33/39] Less strict anti-bot strategies --- lib/twitter_ebooks/bot.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/twitter_ebooks/bot.rb b/lib/twitter_ebooks/bot.rb index af00d3b..ffacaca 100644 --- a/lib/twitter_ebooks/bot.rb +++ b/lib/twitter_ebooks/bot.rb @@ -37,12 +37,10 @@ module Ebooks usertweets = @tweets.select { |t| t.user.screen_name.downcase == username.downcase } if usertweets.length > 2 - if (usertweets[-1].created_at - usertweets[-3].created_at) < 10 + if username.include?('ebooks') || (usertweets[-1].created_at - usertweets[-3].created_at) < 12 return true end end - - username.include?("ebooks") end # Figure out whether to keep this user in the reply prefix From 8bf15d2a1b269e515a4b3f321898cb274b125b91 Mon Sep 17 00:00:00 2001 From: Effy Elden Date: Fri, 26 Feb 2016 06:18:53 +1100 Subject: [PATCH 34/39] Added sync command --- bin/ebooks | 21 +++++++++++++++ lib/twitter_ebooks.rb | 1 + lib/twitter_ebooks/sync.rb | 52 ++++++++++++++++++++++++++++++++++++++ twitter_ebooks.gemspec | 1 + 4 files changed, 75 insertions(+) create mode 100644 lib/twitter_ebooks/sync.rb diff --git a/bin/ebooks b/bin/ebooks index 31b9907..9fada60 100755 --- a/bin/ebooks +++ b/bin/ebooks @@ -28,6 +28,7 @@ Usage: ebooks append ebooks gen [input] ebooks archive [path] + ebooks sync [username] ebooks tweet ebooks version STR @@ -227,6 +228,25 @@ STR Ebooks::Archive.new(username, outpath).sync end + HELP.sync = <<-STR + Usage: ebooks sync + + Copies and flips 's avatar and cover photo, uploading them to 's profile. + + Stores saved avatar's and covers in image/. + + STR + + def self.sync(botname, username) + if botname.nil? + help :sync + exit 1 + end + + load File.join(APP_PATH, 'bots.rb') + Ebooks::Sync::run(botname, username) + end + HELP.tweet = <<-STR Usage: ebooks tweet @@ -409,6 +429,7 @@ STR when "append" then append(args[1],args[2]) when "gen" then gen(args[1], args[2..-1].join(' ')) when "archive" then archive(args[1], args[2]) + when "sync" then sync(args[1], args[2]) when "tweet" then tweet(args[1], args[2]) when "jsonify" then jsonify(args[1..-1]) when "auth" then auth diff --git a/lib/twitter_ebooks.rb b/lib/twitter_ebooks.rb index 9d9652f..f086418 100644 --- a/lib/twitter_ebooks.rb +++ b/lib/twitter_ebooks.rb @@ -16,6 +16,7 @@ end require 'twitter_ebooks/nlp' require 'twitter_ebooks/archive' +require 'twitter_ebooks/sync' require 'twitter_ebooks/suffix' require 'twitter_ebooks/model' require 'twitter_ebooks/bot' diff --git a/lib/twitter_ebooks/sync.rb b/lib/twitter_ebooks/sync.rb new file mode 100644 index 0000000..b3f2322 --- /dev/null +++ b/lib/twitter_ebooks/sync.rb @@ -0,0 +1,52 @@ +#!/usr/bin/env ruby +# encoding: utf-8 + +require 'twitter' +require 'json' +require 'mini_magick' +require 'open-uri' +require 'pry' + +module Ebooks + class Sync + + def self.run(botname, username) + bot = Ebooks::Bot.get(botname) + bot.configure + source_user = username + ebooks_user = bot.username + user = bot.twitter.user(source_user) + if user.profile_image_url then + Ebooks::Sync::get(user.profile_image_url(:original), "image/#{source_user}_avatar") + avatar = MiniMagick::Image.open("image/#{source_user}_avatar") + avatar.flip + avatar.write("image/#{ebooks_user}_avatar") + avatar64 = Base64.encode64(File.read("image/#{ebooks_user}_avatar")) + bot.twitter.update_profile_image(avatar64) + p "Updated profile image for #{ebooks_user} from #{source_user}." + else + p "#{source_user} does not have a profile image to clone." + end + if user.profile_banner_url then + Ebooks::Sync::get(user.profile_banner_url, "image/#{source_user}banner") + banner = MiniMagick::Image.open("image/#{source_user}banner") + banner.flip + banner.write("image/#{ebooks_user}_banner") + banner64 = Base64.encode64(File.read("image/#{ebooks_user}_banner")) + bot.twitter.update_profile_banner(banner64) + p "Updated cover image for #{ebooks_user} from #{source_user}." + else + p "#{source_user} does not have a cover image to clone." + end + end + + def self.get(url, destination) + File.open(destination, "wb") do |saved_file| + open(url, "rb") do |read_file| + saved_file.write(read_file.read) + end + end + end + + end +end diff --git a/twitter_ebooks.gemspec b/twitter_ebooks.gemspec index 6cb0200..3f3508c 100644 --- a/twitter_ebooks.gemspec +++ b/twitter_ebooks.gemspec @@ -33,4 +33,5 @@ Gem::Specification.new do |gem| gem.add_runtime_dependency 'highscore' gem.add_runtime_dependency 'pry' gem.add_runtime_dependency 'oauth' + gem.add_runtime_dependency 'mini_magick' end From b9118919640e02d6d2224ec615785e362ef6a757 Mon Sep 17 00:00:00 2001 From: Effy Elden Date: Fri, 26 Feb 2016 06:21:33 +1100 Subject: [PATCH 35/39] Added image folder to skeleton. --- skeleton/image/.gitignore | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 skeleton/image/.gitignore diff --git a/skeleton/image/.gitignore b/skeleton/image/.gitignore new file mode 100644 index 0000000..e69de29 From 29be84607ab92ddbf74749717f3994b2330c8447 Mon Sep 17 00:00:00 2001 From: Ross Penman Date: Wed, 2 Mar 2016 01:31:55 +0000 Subject: [PATCH 36/39] Waaaaaayyyyy more efficient delaying --- lib/twitter_ebooks/bot.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/twitter_ebooks/bot.rb b/lib/twitter_ebooks/bot.rb index ffacaca..6b47650 100644 --- a/lib/twitter_ebooks/bot.rb +++ b/lib/twitter_ebooks/bot.rb @@ -375,7 +375,7 @@ module Ebooks # Delay an action for a variable period of time # @param range [Range, Integer] range of seconds to choose for delay def delay(range=@delay_range, &b) - time = range.to_a.sample unless range.is_a? Integer + time = rand(range) unless range.is_a? Integer sleep time b.call end From f8e62f9bd86f52f9c54a1bfd65c45d03639848da Mon Sep 17 00:00:00 2001 From: Effy Elden Date: Fri, 19 Aug 2016 23:33:46 +1000 Subject: [PATCH 37/39] Change output of ebooks auth so it can be copy-pasted into bots.rb --- bin/ebooks | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/ebooks b/bin/ebooks index 9fada60..22df53e 100755 --- a/bin/ebooks +++ b/bin/ebooks @@ -306,8 +306,8 @@ STR access_token = request_token.get_access_token(oauth_verifier: pin) log "Account authorized successfully. Make sure to put these in your bots.rb!\n" + - " access token: #{access_token.token}\n" + - " access token secret: #{access_token.secret}" + " bot.access_token = \"#{access_token.token}\"\n" + + " bot.access_token_secret = \"#{access_token.secret}\"" end HELP.console = <<-STR From 50daa5ab0356e1784374f545dd99bc7e4fea80d7 Mon Sep 17 00:00:00 2001 From: Jaiden Mispy Date: Sun, 21 Aug 2016 22:44:26 +1000 Subject: [PATCH 38/39] Add error message if you tweet from nonexistent bot --- bin/ebooks | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bin/ebooks b/bin/ebooks index 22df53e..9f2fc70 100755 --- a/bin/ebooks +++ b/bin/ebooks @@ -264,6 +264,10 @@ STR model = Ebooks::Model.load(modelpath) statement = model.make_statement bot = Ebooks::Bot.get(botname) + if bot.nil? + log "No such bot configured in bots.rb: #{botname}" + exit 1 + end bot.configure bot.tweet(statement) end From 75566103d45ef116a947aa8321304672e04af2b2 Mon Sep 17 00:00:00 2001 From: Jaiden Mispy Date: Sun, 21 Aug 2016 23:37:44 +1000 Subject: [PATCH 39/39] Case-insensitive Bot::get --- lib/twitter_ebooks/bot.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/twitter_ebooks/bot.rb b/lib/twitter_ebooks/bot.rb index 6b47650..64b0246 100644 --- a/lib/twitter_ebooks/bot.rb +++ b/lib/twitter_ebooks/bot.rb @@ -168,7 +168,7 @@ module Ebooks # @param username [String] # @return [Ebooks::Bot] def self.get(username) - all.find { |bot| bot.username == username } + all.find { |bot| bot.username.downcase == username.downcase } end # Logs info to stdout in the context of this bot