augury 0.2.1 → 0.3.0

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
2
  SHA1:
3
- metadata.gz: a745ff0e70cbdadbaf9dd4415b1edb16ec0bb87d
4
- data.tar.gz: 34a82cf9069b55127f301c6a54c623fea08866d0
3
+ metadata.gz: a0c7c48771363a9a5c848e76b7747bf9b5d9fbd3
4
+ data.tar.gz: 2dd47ecc12e320134c3ce249f64e088a436a1a4e
5
5
  SHA512:
6
- metadata.gz: 6470c46d253a9315362d40d7035b516b7db8e69c936c2042b76a172fe145658d5e43f5f08185510715d92cafc65995cd91b9cc2f95ae60df549338de39c2d809
7
- data.tar.gz: 6f4e38961aa97d87c085c2b7c9b5f007536eb5b5f6a21026420842c2afb39afc5a70ab3546ae3033a9ea37a96c08c4ea74afdb8c1106f64a519697e158d15101
6
+ metadata.gz: 8afece52e31616184f74750ae3eee61eca34ef30a7582ffac4f9777b3515cbea1e84d94e5610a4a2f1b1bb075cd64d1bb77358a564bded2a9251d83e26aa917e
7
+ data.tar.gz: c5ad6b4b98c483fca41f513f29e201f0b9a13b1f0bd9b31c3f34e725179d4b52b28ca98bae506169111e5e64ebdadaccbfd8ca75df5cebba73d30646e008dbb7
data/.gitignore CHANGED
@@ -8,3 +8,4 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  *.gem
11
+ /bin/*
@@ -0,0 +1,22 @@
1
+ # Changes
2
+
3
+ ## 0.3.0 (2015-08-20)
4
+
5
+ - Add `count` option and allow for a user to get all tweets
6
+ - Improve error handling
7
+ - Handle spaces in `path` argument
8
+ - Properly get defaults from the config if not passed on the command line
9
+ - Updated docs and interactive help
10
+
11
+ ## 0.2.1 (2015-08-19)
12
+
13
+ - Fix docs on rubygems site
14
+
15
+ ## 0.2.0 (2015-08-19)
16
+
17
+ - Initial working code and documentation
18
+
19
+ ## 0.1.0 (2015-08-19)
20
+
21
+ - Initial code skeleton
22
+ - Test push to rubygems
data/README.md CHANGED
@@ -3,23 +3,30 @@
3
3
  Have you ever wanted to turn a twitter account into a fortune file?
4
4
  Well, today is your lucky day!
5
5
 
6
- Here is an example:
6
+ <blockquote>
7
+ Augury is the practice from ancient Roman religion of<br>
8
+ interpreting omens from the observed flight of birds.<br><br>
9
+ As per [Wikipedia](https://en.wikipedia.org/wiki/Augury)
10
+ </blockquote>
11
+
12
+ There are a lot of really funny twitter accounts out there.
13
+ Let's just pick one and get started.
7
14
 
8
15
  ```
9
- $ augury generate SeinfeldToday
16
+ $ augury generate seinfeldtoday
10
17
  ```
11
18
 
12
19
  This just created the fortune files in the current directory:
13
20
 
14
21
  ```
15
22
  $ ls
16
- SeinfeldToday SeinfeldToday.dat
23
+ seinfeldtoday seinfeldtoday.dat
17
24
  ```
18
25
 
19
26
  You can now read the new fortunes!
20
27
 
21
28
  ```
22
- $ fortune SeinfeldToday
29
+ $ fortune seinfeldtoday
23
30
  Elaine has no idea what her BF does for a living and it's now too
24
31
  late to ask. E:"Teacher, I think. Or a doctor? Wait Is
25
32
  'computers' a job?"
@@ -27,6 +34,13 @@ late to ask. E:"Teacher, I think. Or a doctor? Wait Is
27
34
 
28
35
  Thanks for all the laughs fortune :)
29
36
 
37
+ Here are some accounts that work well with Augury:
38
+
39
+ - [Modern Seinfeld](https://twitter.com/seinfeldtoday)
40
+ - [Very Short Story](https://twitter.com/veryshortstory)
41
+ - [Bored Elon Musk](https://twitter.com/boredelonmusk)
42
+ - Your own feed, so you can get nostalgic.
43
+
30
44
  ## Installation
31
45
 
32
46
  Add this line to your application's Gemfile:
@@ -81,8 +95,11 @@ example_option = "An interesting value"
81
95
 
82
96
  These are the available options for the `~/.augury.cfg`
83
97
 
84
- - `append` Make the script add more entries to the specified file instead of re-writing it. DEFAULT: False
85
- - `width` Set the default width used if none is given on the command line. DEFAULT: 72
98
+ Option | Description | Default
99
+ ------ | :---------- | -------
100
+ `append` | Make the script add more entries to the specified file instead of re-writing it | `false`
101
+ `width` | Set the default width used if none is given on the command line. | `72`
102
+ `count` | The number of tweets to get. Set to 0 to get all. | `200`
86
103
 
87
104
  ### Twitter Setup
88
105
 
@@ -103,29 +120,81 @@ access_token_secret = "YOUR_ACCESS_SECRET"
103
120
 
104
121
  ## Usage
105
122
 
106
- Create a fortune for the latest SeinfeldToday tweets.
123
+ Create a fortune for the latest *seinfeldtoday* tweets.
107
124
 
108
125
  ```
109
- $ augury generate SeinfeldToday
126
+ $ augury generate seinfeldtoday
110
127
  ```
111
128
 
112
129
  Now you have some fortunes.
113
130
 
114
131
  ```
115
- $ fortune SeinfeldToday
132
+ $ fortune seinfeldtoday
133
+ ```
134
+
135
+ Specify a width and a different path to use:
136
+
137
+ ```
138
+ $ augury generate -w 120 seinfeldtoday /usr/local/share/games/fortune/Modern\ Seinfeld
139
+ ```
140
+
141
+ If this is where your fortune program looks for fortunes,
142
+ you can now use the new fortune.
143
+
144
+ ```
145
+ $ fortune "Modern Seinfeld"
146
+ ```
147
+
148
+ ### See the interactive help
149
+
150
+ Run the help to get more details about what the program can do
151
+
152
+ ```
153
+ $ bin/augury help
154
+ $ bin/augury help generate
116
155
  ```
117
156
 
118
157
  ## Development
119
158
 
120
- After checking out the repo, run `bin/setup` to install dependencies.
121
- Then, run `rake spec` to run the tests.
122
- You can also run `bin/console` for an interactive prompt that will allow you to experiment.
159
+ If you want to contribute to this library,
160
+ do the following.
161
+
162
+ Create a fork, then get the code
163
+
164
+ ```
165
+ $ git clone git@github.com:YOUR_USERNAME/augury.git
166
+ $ cd augury
167
+ ```
168
+
169
+ Run the setup script to get everything installed:
123
170
 
124
- To install this gem onto your local machine, run `bundle exec rake install`.
125
- To release a new version, update the version number in `version.rb`,
126
- and then run `bundle exec rake release`,
127
- which will create a git tag for the version,
128
- push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
171
+ **NOTE**: This requires having bundler available.
172
+ That is beyond the scope of this README.
173
+
174
+ ```
175
+ $ bin/setup
176
+ ```
177
+
178
+ Once that is finished, there is a console available.
179
+ This gives you access to all the code via Pry.
180
+
181
+ ```
182
+ $ bin/console
183
+ ```
184
+
185
+ The `augury` command will be available in bin:
186
+
187
+ ```
188
+ $ bin/augury help
189
+ ```
190
+
191
+ ### Run the tests
192
+
193
+ You can run the tests with the rake task:
194
+
195
+ ```
196
+ $ rake spec
197
+ ```
129
198
 
130
199
  ## Contributing
131
200
 
@@ -134,3 +203,16 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/claytr
134
203
  ## License
135
204
 
136
205
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
206
+
207
+ ## Thanks for all the fish
208
+
209
+ Thanks to [TinderBox](http://gettinderbox.com) for giving us time to make cool things happen!
210
+
211
+ This was an excellent learning experience for the author,
212
+ who is new at programming in Ruby.
213
+
214
+ The [Developing a RubyGem using Bundler][gemdocs] documentation was fun to read and informative.
215
+ It helped get the skeleton of the code set up and extra goodies in the development profile.
216
+ Highly recommended read!
217
+
218
+ [gemdocs]: https://github.com/radar/guides/blob/master/gem-development.md#developing-a-rubygem-using-bundler
data/TODO.md CHANGED
@@ -4,8 +4,8 @@ Some ideas for things that could be added:
4
4
 
5
5
  - Add an option to limit the tweets from a certain date forward.
6
6
  This would allow for adding the latest tweets via cron.
7
- - Add options for how many tweets to retrieve
8
7
  - Ask user for twitter config on first start, save it out
9
8
  - Sign each entry with the name of the twitter account
10
9
  - Series of regex that could be applied.
11
10
  This would be a way to make SeinfeldToday dialog get put on their own lines.
11
+ - Different word wrapping options. To a width, or by sentence, or whatever.
@@ -2,6 +2,8 @@
2
2
 
3
3
  require "bundler/setup"
4
4
  require "augury"
5
+ # Load up the cli here as well
6
+ require "augury/cli"
5
7
 
6
8
  # You can add fixtures and/or initialization code here to make experimenting
7
9
  # with your gem easier. You can also use a different console, if you like.
data/bin/setup CHANGED
@@ -2,6 +2,4 @@
2
2
  set -euo pipefail
3
3
  IFS=$'\n\t'
4
4
 
5
- bundle install
6
-
7
- # Do any other automated setup that you need to do here
5
+ bundle install --binstubs
@@ -4,24 +4,32 @@ require 'augury'
4
4
  module Augury
5
5
  class CLI < Thor
6
6
  desc 'generate USERNAME [PATH]', 'Generate a fortune file for the given username'
7
- option :width, :type => :numeric, :aliases => :w
8
- option :append, :type => :boolean, :aliases => :a
7
+ option :width,
8
+ :type => :numeric, :aliases => '-w',
9
+ :desc => 'The maximum number of columns that will be written on a line. DEFAULT: 72'
10
+ option :append,
11
+ :type => :boolean, :aliases => '-a',
12
+ :desc => 'If set, the target path will be appended to instead of overwritten'
13
+ option :count,
14
+ :type => :numeric, :aliases => '-c',
15
+ :desc => 'The number of tweets to get. Set to 0 to get all. DEFAULT: 200'
9
16
  def generate(username, *path)
10
- path = File.expand_path(path[0] || username)
11
17
  begin
12
- augury = Augury::Fortune.new(
13
- username,
14
- path,
15
- options['width'],
16
- options['append']
17
- )
18
- rescue Augury::TwitterConfigError => e
19
- puts e.message
18
+ path = File.expand_path(path[0] || username)
19
+ augury = Augury::Fortune.new(
20
+ username,
21
+ path,
22
+ options['width'],
23
+ options['append'],
24
+ options['count'],
25
+ )
26
+ augury.write_fortune
27
+ self.say "Fortune written out to #{path}"
28
+ rescue => e
29
+ self.say "There was an error running the command. Details below:"
30
+ self.say e.message
20
31
  exit 1
21
32
  end
22
- tweets = augury.tweet_texts
23
- augury.write_fortune(augury.format_fortune(tweets))
24
- puts "Fortune written out to #{path}"
25
33
  end
26
34
  end
27
35
  end
@@ -5,7 +5,7 @@ require 'wannabe_bool'
5
5
 
6
6
  module Augury
7
7
  class Fortune
8
- def initialize(username, path, width=nil, append=nil)
8
+ def initialize(username, path, width=nil, append=nil, count=nil)
9
9
  begin
10
10
  @config = ParseConfig.new(File.expand_path('~/.augury.cfg'))
11
11
  rescue Errno::EACCES
@@ -15,8 +15,9 @@ module Augury
15
15
  augury_config = @config.params['augury'] || {}
16
16
  @username = username
17
17
  @path = path
18
- @width = width || augury_config['width'] || 72
19
- @append = append || augury_config['append'].to_b || false
18
+ @width = (width || augury_config['width'] || 72).to_i
19
+ @append = (append || augury_config['append'] || false).to_b
20
+ @count = (count || augury_config['count'] || 200).to_i
20
21
 
21
22
  twitter_config = @config.params['twitter']
22
23
  raise Augury::TwitterConfigError unless twitter_config
@@ -28,28 +29,53 @@ module Augury
28
29
  end
29
30
  end
30
31
 
31
- def tweet_texts
32
- @twitter.user_timeline(@username).flat_map { |tweet| tweet.full_text }
32
+ def collect_with_max_id(collection=[], max_id=nil, &block)
33
+ response = yield(max_id)
34
+ collection += response
35
+ if response.empty?
36
+ collection.flatten
37
+ elsif ! @count.zero? && collection.length >= @count
38
+ collection.flatten
39
+ else
40
+ collect_with_max_id(collection, response.last.id - 1, &block)
41
+ end
42
+ end
43
+
44
+ def tweets
45
+ begin
46
+ collect_with_max_id do |max_id|
47
+ options = {
48
+ count: @count.zero? ? 200 : @count,
49
+ include_rts: true,
50
+ }
51
+ options[:max_id] = max_id unless max_id.nil?
52
+ @twitter.user_timeline(@username, options)
53
+ end
54
+ rescue Twitter::Error::TooManyRequests => e
55
+ reset_length = e.rate_limit.reset_in + 1
56
+ puts "Twitter rate limit exceeded. Waiting #{reset_length} minute(s)"
57
+ sleep reset_length
58
+ end
33
59
  end
34
60
 
35
- def format_fortune(tweets)
36
- tweets.flat_map { |tweet| tweet.word_wrap(@width) }.join("%\n")
61
+ def format_fortune
62
+ tweet_texts = self.tweets.flat_map { |tweet| tweet.full_text }
63
+ tweet_texts.flat_map { |tweet| tweet.word_wrap(@width) }.join("%\n")
37
64
  end
38
65
 
39
- def write_fortune(text)
66
+ def write_fortune
67
+ text = self.format_fortune
40
68
  # Write out the file
41
69
  begin
42
70
  mode = @append ? 'a' : 'w'
43
71
  file = File.open(@path, mode)
44
72
  file.write("%\n") if @append
45
73
  file.write(text)
46
- rescue IOError => e
47
- puts e
48
74
  ensure
49
75
  file.close unless file.nil?
50
76
  end
51
77
  # Create the dat file too
52
- `strfile #{@path} #{@path}.dat`
78
+ `strfile '#{@path}' '#{@path}.dat'`
53
79
  end
54
80
  end
55
81
  end
@@ -1,3 +1,3 @@
1
1
  module Augury
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: augury
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Clayton Parker
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-08-20 00:00:00.000000000 Z
11
+ date: 2015-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parseconfig
@@ -232,6 +232,7 @@ files:
232
232
  - ".gitignore"
233
233
  - ".rspec"
234
234
  - ".travis.yml"
235
+ - CHANGELOG.md
235
236
  - Gemfile
236
237
  - LICENSE.txt
237
238
  - README.md