twitter_ebooks_poll 3.2.1 → 3.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +1 -1
- data/lib/twitter_ebooks/archive.rb +2 -1
- data/lib/twitter_ebooks/bot.rb +24 -3
- data/lib/twitter_ebooks/model.rb +4 -4
- data/lib/twitter_ebooks/version.rb +1 -1
- data/spec/model_spec.rb +2 -2
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5de05b2015541094d0ed54f1403dc8feff2d963e
|
4
|
+
data.tar.gz: 139ccbf8d45cc76ebafc193ab054402d51645ccf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c093b9226bb93cd5edf9784e08450585d47e557bee72935c5be8045ca9ff18e20fa830195a939872aad3ebf300f0e7ac3bb9ae22670d8bd2657562369d2abe5
|
7
|
+
data.tar.gz: ef74384da4c23b3857f93ec07dbd18bfacb276f3230a1cc69148b2184e609faea0c3040b008014082c18f77566fa65aa630ddc4cec5938bd02f0482ae0011e40
|
data/README.md
CHANGED
@@ -145,7 +145,7 @@ Once you have a model, the primary use is to produce statements and related resp
|
|
145
145
|
|
146
146
|
``` ruby
|
147
147
|
> model = Ebooks::Model.load("model/0xabad1dea.model")
|
148
|
-
> model.make_statement(
|
148
|
+
> model.make_statement(280)
|
149
149
|
=> "My Terrible Netbook may be the kind of person who buys Starbucks, but this Rackspace vuln is pretty straight up a backdoor"
|
150
150
|
> model.make_response("The NSA is coming!", 130)
|
151
151
|
=> "Hey - someone who claims to be an NSA conspiracy"
|
data/lib/twitter_ebooks/bot.rb
CHANGED
@@ -95,7 +95,7 @@ module Ebooks
|
|
95
95
|
@reply_mentions = ([ev.user.screen_name] + reply_mentions).uniq
|
96
96
|
|
97
97
|
@reply_prefix = @reply_mentions.map { |m| '@'+m }.join(' ') + ' '
|
98
|
-
@limit =
|
98
|
+
@limit = 280 - @reply_prefix.length
|
99
99
|
|
100
100
|
mless = ev.text
|
101
101
|
begin
|
@@ -355,15 +355,17 @@ module Ebooks
|
|
355
355
|
|
356
356
|
# Start polling timelines
|
357
357
|
def start
|
358
|
-
log
|
358
|
+
log 'starting Twitter timeline polling 3.2.2.1'
|
359
359
|
|
360
360
|
latest_tweet = 0
|
361
361
|
latest_mention = 0
|
362
|
-
options_home = {count: 800}
|
363
362
|
options_mention = {count: 200}
|
363
|
+
options_home = {count: 800}
|
364
364
|
persistence_file = "#{@username}.json"
|
365
365
|
# Read last polled tweets from a persisted file, if exists
|
366
366
|
if File.exist? persistence_file
|
367
|
+
options_mention = {count: 200}
|
368
|
+
options_home = {count: 800}
|
367
369
|
json = JSON.parse(open(persistence_file, 'r').read)
|
368
370
|
latest_tweet = json['latest_tweet']
|
369
371
|
latest_mention = json['latest_mention']
|
@@ -371,8 +373,27 @@ module Ebooks
|
|
371
373
|
options_mention[:since_id] = latest_mention
|
372
374
|
log "starting home timeline after tweet ##{latest_tweet}"
|
373
375
|
log "starting mentions after tweet ##{latest_mention}"
|
376
|
+
else
|
377
|
+
# Fresh start - fetch only newest tweet & mention id
|
378
|
+
log 'starting without persisted ids - reading newest tweet/mention ...'
|
379
|
+
tweets = twitter.home_timeline(options_home)
|
380
|
+
tweets.each do |ev|
|
381
|
+
latest_tweet = ev.id if ev.id > latest_tweet
|
382
|
+
options_home[:since_id] = latest_tweet
|
383
|
+
end
|
384
|
+
mentions = twitter.mentions_timeline(options_mention)
|
385
|
+
mentions.each do |ev|
|
386
|
+
latest_mention = ev.id if ev.id > latest_mention
|
387
|
+
options_mention[:since_id] = latest_mention
|
388
|
+
end
|
389
|
+
file = open(persistence_file, 'w')
|
390
|
+
file.puts({latest_tweet: latest_tweet, latest_mention: latest_mention}.to_json)
|
391
|
+
file.close
|
392
|
+
log '... done'
|
374
393
|
end
|
375
394
|
|
395
|
+
log 'starting timeline polling schedulers'
|
396
|
+
|
376
397
|
# Poll home timeline every 70s (rate limit is 15 GETs/15min)
|
377
398
|
scheduler.every '70s' do
|
378
399
|
tweets = twitter.home_timeline(options_home)
|
data/lib/twitter_ebooks/model.rb
CHANGED
@@ -142,7 +142,7 @@ module Ebooks
|
|
142
142
|
if path.split('.')[-1] == "json"
|
143
143
|
log "Reading json corpus from #{path}"
|
144
144
|
lines = JSON.parse(content).map do |tweet|
|
145
|
-
|
145
|
+
tweet['text'] || tweet['full_text']
|
146
146
|
end
|
147
147
|
elsif path.split('.')[-1] == "csv"
|
148
148
|
log "Reading CSV corpus from #{path}"
|
@@ -205,7 +205,7 @@ module Ebooks
|
|
205
205
|
if path.split('.')[-1] == "json"
|
206
206
|
log "Reading json corpus from #{path}"
|
207
207
|
l = JSON.parse(content).map do |tweet|
|
208
|
-
tweet['text']
|
208
|
+
tweet['text'] || tweet['full_text']
|
209
209
|
end
|
210
210
|
lines.concat(l)
|
211
211
|
elsif path.split('.')[-1] == "csv"
|
@@ -246,7 +246,7 @@ module Ebooks
|
|
246
246
|
# @param generator [SuffixGenerator, nil]
|
247
247
|
# @param retry_limit [Integer] how many times to retry on invalid tweet
|
248
248
|
# @return [String]
|
249
|
-
def make_statement(limit=
|
249
|
+
def make_statement(limit=280, generator=nil, retry_limit=10)
|
250
250
|
responding = !generator.nil?
|
251
251
|
generator ||= SuffixGenerator.build(@sentences)
|
252
252
|
|
@@ -316,7 +316,7 @@ module Ebooks
|
|
316
316
|
# @param limit [Integer] characters available for response
|
317
317
|
# @param sentences [Array<Array<Integer>>]
|
318
318
|
# @return [String]
|
319
|
-
def make_response(input, limit=
|
319
|
+
def make_response(input, limit=280, sentences=@mentions)
|
320
320
|
# Prefer mentions
|
321
321
|
relevant, slightly_relevant = find_relevant(sentences, input)
|
322
322
|
|
data/spec/model_spec.rb
CHANGED
@@ -10,13 +10,13 @@ describe Ebooks::Model do
|
|
10
10
|
|
11
11
|
it "generates a tweet" do
|
12
12
|
s = @model.make_statement
|
13
|
-
expect(s.length).to be <=
|
13
|
+
expect(s.length).to be <= 280
|
14
14
|
puts s
|
15
15
|
end
|
16
16
|
|
17
17
|
it "generates an appropriate response" do
|
18
18
|
s = @model.make_response("hi")
|
19
|
-
expect(s.length).to be <=
|
19
|
+
expect(s.length).to be <= 280
|
20
20
|
expect(s.downcase).to include("hi")
|
21
21
|
puts s
|
22
22
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twitter_ebooks_poll
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.2.
|
4
|
+
version: 3.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Magnus Niemann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -295,7 +295,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
295
295
|
version: '0'
|
296
296
|
requirements: []
|
297
297
|
rubyforge_project:
|
298
|
-
rubygems_version: 2.
|
298
|
+
rubygems_version: 2.4.6
|
299
299
|
signing_key:
|
300
300
|
specification_version: 4
|
301
301
|
summary: Markov chains for all your friends~
|
@@ -306,3 +306,4 @@ test_files:
|
|
306
306
|
- spec/memprof.rb
|
307
307
|
- spec/model_spec.rb
|
308
308
|
- spec/spec_helper.rb
|
309
|
+
has_rdoc:
|