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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: fed2248a1713b0736904de23a430ce8572a80096b176e99a086bddde42527ee2
4
- data.tar.gz: affd693b13fd537194d9f33b92a40b30f65ed17bddfaa657b8c1ab86dec54656
2
+ SHA1:
3
+ metadata.gz: 5de05b2015541094d0ed54f1403dc8feff2d963e
4
+ data.tar.gz: 139ccbf8d45cc76ebafc193ab054402d51645ccf
5
5
  SHA512:
6
- metadata.gz: 6589699b62e8fd94cbbe8cdcfe1e22341a7f77dc4d52ebae3ae9009c2dc72ed9c8c3d9b8b62d0be9979d86a8f6030622fde19aa03db819737741d8203ed04657
7
- data.tar.gz: 9033064da815766e96e5d0e0b0eb88fa5179ddbe3c55fde429e4b0a1ac2890f96de4af402c86df4fa2862ecb20123cb27d8bb5a44e8a62f5522c5fdb87a31708
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(140)
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"
@@ -82,7 +82,8 @@ module Ebooks
82
82
  opts = {
83
83
  count: 200,
84
84
  #include_rts: false,
85
- trim_user: true
85
+ trim_user: true,
86
+ tweet_mode: 'extended'
86
87
  }
87
88
 
88
89
  opts[:since_id] = @tweets[0][:id] unless @tweets.nil?
@@ -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 = 140 - @reply_prefix.length
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 "starting Twitter timeline polling"
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)
@@ -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
- tweet['text']
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=140, generator=nil, retry_limit=10)
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=140, sentences=@mentions)
319
+ def make_response(input, limit=280, sentences=@mentions)
320
320
  # Prefer mentions
321
321
  relevant, slightly_relevant = find_relevant(sentences, input)
322
322
 
@@ -1,3 +1,3 @@
1
1
  module Ebooks
2
- VERSION = "3.2.1"
2
+ VERSION = "3.2.2"
3
3
  end
@@ -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 <= 140
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 <= 140
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.1
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-09-15 00:00:00.000000000 Z
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.7.6
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: