augury 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a28ff9832d2d3004984bc13a8da85a2798c1c324
4
- data.tar.gz: 6988fd81ed53f496199b64519571c3b9782f50fc
3
+ metadata.gz: 9658042a5e949c0611f9e7044dac8f8d5f5a4b4b
4
+ data.tar.gz: 0d6b3d19af712ddde14d4690c00e3c721ba5521e
5
5
  SHA512:
6
- metadata.gz: e14065d03249995fd1f8382ee444b4a8c48b62ba01fcfb270dbded58d1e58379bb3779dbc06a24a46d037422fdf6cc49c3613a998c8cebd19492c19cf174c677
7
- data.tar.gz: f821c6685eb1eda754f90c8f209c71c9f09f4e1b6cea032343839ed22ad0fabe06e85a5ee4e1e53deb30710fcd5316b35e34bcf96ed5162ad777439b0c5e7d94
6
+ metadata.gz: 08b35032107de0c6f05119eeadf8b6bc2316ae5904105c84ef5ff6655642b49223ed36932e987abcedad3462dc3926e07e7f67ab83b2de2fb1bf25e49f356a00
7
+ data.tar.gz: c8bbbfefdcc61cf07844543e7a7e14e0bb074655ed867ce271279155398046a81995feaa5242a6b61aed097cea1c46e6518b06b3892c6aacd244d1f53224ac4b
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ *.gem
data/README.md CHANGED
@@ -1,8 +1,31 @@
1
1
  # Augury
2
2
 
3
- Have you ever wanted to turn a twitter account into an updating fortune file?
3
+ Have you ever wanted to turn a twitter account into a fortune file?
4
4
  Well, today is your lucky day!
5
- Augury can take a twitter feed and turn it into a fortune file for you.
5
+
6
+ Here is an example:
7
+
8
+ ```
9
+ $ augury generate SeinfeldToday
10
+ ```
11
+
12
+ This just created the fortune files in the current directory:
13
+
14
+ ```
15
+ $ ls
16
+ SeinfeldToday SeinfeldToday.dat
17
+ ```
18
+
19
+ You can now read the new fortunes!
20
+
21
+ ```
22
+ $ fortune SeinfeldToday
23
+ Elaine has no idea what her BF does for a living and it's now too
24
+ late to ask. E:"Teacher, I think. Or a doctor? Wait Is
25
+ 'computers' a job?"
26
+ ```
27
+
28
+ Thanks for all the laughs fortune :)
6
29
 
7
30
  ## Installation
8
31
 
@@ -14,36 +37,83 @@ gem 'augury'
14
37
 
15
38
  And then execute:
16
39
 
17
- $ bundle
40
+ ```
41
+ $ bundle
42
+ ```
18
43
 
19
44
  Or install it yourself as:
20
45
 
21
- $ gem install augury
46
+ ```
47
+ $ gem install augury
48
+ ```
49
+
50
+ ### Requirements
51
+
52
+ This gem requires that the fortune program is also installed.
53
+ The fortune program ships with a `strfile` program that converts the plain text files to something that fortune can select from.
54
+
55
+ For example,
56
+ if you are using Homebrew on OS X:
57
+
58
+ ```
59
+ $ brew install fortune
60
+ ```
22
61
 
23
62
  ## Configuration
24
63
 
25
- First, you will need to create a new Twitter application by going here:
64
+ ### Augury Config
65
+
66
+ Create the `~/.augry.cfg` file and then set the permissions since your Twitter API info will be in there.
67
+
68
+ ```sh
69
+ $ touch ~/.augury.cfg
70
+ $ chmod 600 ~/.augury.cfg
71
+ ```
72
+
73
+ Set any of these settings in the `augury` section of the config like this:
74
+
75
+ ```ini
76
+ [augury]
77
+ example_option = "An interesting value"
78
+ ```
79
+
80
+ ### Option list
81
+
82
+ These are the available options for the `~/.augury.cfg`
83
+
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
26
86
 
87
+ ### Twitter Setup
88
+
89
+ First, you will need to create a new Twitter application by going here:
27
90
  https://apps.twitter.com
28
91
 
29
92
  This will give you the ability to generate the consumer and access information used below.
30
93
 
31
- In order to use this gem, you need to set up your Twitter credentials.
32
- This can be done by setting up the `~/.augury.conf` file.
33
- Here is an example of its contents:
94
+ Add the following to your `~/.augury.cfg` file.
34
95
 
35
- consumer_key = "YOUR_CONSUMER_KEY"
36
- consumer_secret = "YOUR_CONSUMER_SECRET"
37
- access_token = "YOUR_ACCESS_TOKEN"
38
- access_token_secret = "YOUR_ACCESS_SECRET"
96
+ ```ini
97
+ [twitter]
98
+ consumer_key = "YOUR_CONSUMER_KEY"
99
+ consumer_secret = "YOUR_CONSUMER_SECRET"
100
+ access_token = "YOUR_ACCESS_TOKEN"
101
+ access_token_secret = "YOUR_ACCESS_SECRET"
102
+ ```
39
103
 
40
- Make sure only your user has access to the file:
104
+ ## Usage
41
105
 
42
- $ chmod 600 ~/.augury.conf
106
+ Create a fortune for the latest SeinfeldToday tweets.
43
107
 
44
- ## Usage
108
+ ```
109
+ $ augury generate SeinfeldToday
110
+ ```
111
+
112
+ Now you have some fortunes.
45
113
 
46
- TODO: Write usage instructions here
114
+ ```
115
+ $ fortune SeinfeldToday
116
+ ```
47
117
 
48
118
  ## Development
49
119
 
data/TODO.md ADDED
@@ -0,0 +1,11 @@
1
+ # TODO
2
+
3
+ Some ideas for things that could be added:
4
+
5
+ - Add an option to limit the tweets from a certain date forward.
6
+ This would allow for adding the latest tweets via cron.
7
+ - Add options for how many tweets to retrieve
8
+ - Ask user for twitter config on first start, save it out
9
+ - Sign each entry with the name of the twitter account
10
+ - Series of regex that could be applied.
11
+ This would be a way to make SeinfeldToday dialog get put on their own lines.
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["robots@claytron.com"]
11
11
 
12
12
  spec.summary = %q{Turn a twitter feed into a fortune file}
13
- spec.description = %q{This gem turns a twitter feed into a fortune file that you can use with the fortune program}
13
+ spec.description = File.open('README.md').read
14
14
  spec.homepage = "https://github.com/claytron/augury"
15
15
  spec.license = "MIT"
16
16
 
@@ -20,15 +20,26 @@ Gem::Specification.new do |spec|
20
20
  spec.require_paths = ["lib"]
21
21
 
22
22
  # Actual dependencies
23
- spec.add_dependency "twitter"
24
23
  spec.add_dependency "parseconfig"
25
24
  spec.add_dependency "thor"
25
+ spec.add_dependency "twitter"
26
+ ## Handle booleans from simple config
27
+ spec.add_dependency "wannabe_bool"
28
+ ## For the word_wrap function
29
+ spec.add_dependency "facets"
26
30
 
27
31
  # Development dependencies
32
+ ## Setup
28
33
  spec.add_development_dependency "bundler", "~> 1.10"
29
34
  spec.add_development_dependency "rake", "~> 10.0"
35
+ ## Testing
30
36
  spec.add_development_dependency "rspec"
31
- spec.add_development_dependency "pry"
32
37
  spec.add_development_dependency "cucumber"
33
38
  spec.add_development_dependency "aruba"
39
+ ## Debugging
40
+ spec.add_development_dependency "pry"
41
+ spec.add_development_dependency 'pry-stack_explorer'
42
+ spec.add_development_dependency 'pry-byebug'
43
+ spec.add_development_dependency 'pry-doc'
44
+ spec.add_development_dependency 'pry-awesome_print'
34
45
  end
@@ -5,3 +5,4 @@ module Augury
5
5
  end
6
6
 
7
7
  require 'augury/fortune'
8
+ require 'augury/exception'
@@ -3,10 +3,25 @@ require 'augury'
3
3
 
4
4
  module Augury
5
5
  class CLI < Thor
6
- desc 'generate USERNAME', 'Generate a fortune file for the given username'
7
- def generate(username)
8
- augury = Augury::Fortune.new
9
- puts augury.tweet_texts(username)
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
9
+ def generate(username, *path)
10
+ path = File.expand_path(path[0] || username)
11
+ 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
20
+ exit 1
21
+ end
22
+ tweets = augury.tweet_texts
23
+ augury.write_fortune(augury.format_fortune(tweets))
24
+ puts "Fortune written out to #{path}"
10
25
  end
11
26
  end
12
27
  end
@@ -0,0 +1,7 @@
1
+ module Augury
2
+ class TwitterConfigError < StandardError
3
+ def message
4
+ "No twitter credential configuration found in the augury config"
5
+ end
6
+ end
7
+ end
@@ -1,21 +1,55 @@
1
- require 'twitter'
1
+ require 'facets/string/word_wrap'
2
2
  require 'parseconfig'
3
+ require 'twitter'
4
+ require 'wannabe_bool'
3
5
 
4
6
  module Augury
5
7
  class Fortune
6
- def initialize
7
- # TODO: add a check for the file and warn the user
8
- @config = ParseConfig.new(File.expand_path('~/.augury.conf'))
8
+ def initialize(username, path, width=nil, append=nil)
9
+ begin
10
+ @config = ParseConfig.new(File.expand_path('~/.augury.cfg'))
11
+ rescue Errno::EACCES
12
+ @config = ParseConfig.new
13
+ end
14
+
15
+ augury_config = @config.params['augury'] || {}
16
+ @username = username
17
+ @path = path
18
+ @width = width || augury_config['width'] || 72
19
+ @append = append || augury_config['append'].to_b || false
20
+
21
+ twitter_config = @config.params['twitter']
22
+ raise Augury::TwitterConfigError unless twitter_config
9
23
  @twitter = Twitter::REST::Client.new do |config|
10
- config.consumer_key = @config.params['consumer_key']
11
- config.consumer_secret = @config.params['consumer_secret']
12
- config.access_token = @config.params['access_token']
13
- config.access_token_secret = @config.params['access_token_secret']
24
+ config.consumer_key = twitter_config['consumer_key']
25
+ config.consumer_secret = twitter_config['consumer_secret']
26
+ config.access_token = twitter_config['access_token']
27
+ config.access_token_secret = twitter_config['access_token_secret']
14
28
  end
15
29
  end
16
30
 
17
- def tweet_texts(username='SeinfeldToday')
18
- @twitter.user_timeline(username).flat_map { |tweet| tweet.full_text }
31
+ def tweet_texts
32
+ @twitter.user_timeline(@username).flat_map { |tweet| tweet.full_text }
33
+ end
34
+
35
+ def format_fortune(tweets)
36
+ tweets.flat_map { |tweet| tweet.word_wrap(@width) }.join("%\n")
37
+ end
38
+
39
+ def write_fortune(text)
40
+ # Write out the file
41
+ begin
42
+ mode = @append ? 'a' : 'w'
43
+ file = File.open(@path, mode)
44
+ file.write("%\n") if @append
45
+ file.write(text)
46
+ rescue IOError => e
47
+ puts e
48
+ ensure
49
+ file.close unless file.nil?
50
+ end
51
+ # Create the dat file too
52
+ `strfile #{@path} #{@path}.dat`
19
53
  end
20
54
  end
21
55
  end
@@ -1,3 +1,3 @@
1
1
  module Augury
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: augury
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.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-19 00:00:00.000000000 Z
11
+ date: 2015-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: parseconfig
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
13
41
  - !ruby/object:Gem::Dependency
14
42
  name: twitter
15
43
  requirement: !ruby/object:Gem::Requirement
@@ -25,7 +53,7 @@ dependencies:
25
53
  - !ruby/object:Gem::Version
26
54
  version: '0'
27
55
  - !ruby/object:Gem::Dependency
28
- name: parseconfig
56
+ name: wannabe_bool
29
57
  requirement: !ruby/object:Gem::Requirement
30
58
  requirements:
31
59
  - - ">="
@@ -39,7 +67,7 @@ dependencies:
39
67
  - !ruby/object:Gem::Version
40
68
  version: '0'
41
69
  - !ruby/object:Gem::Dependency
42
- name: thor
70
+ name: facets
43
71
  requirement: !ruby/object:Gem::Requirement
44
72
  requirements:
45
73
  - - ">="
@@ -94,6 +122,34 @@ dependencies:
94
122
  - - ">="
95
123
  - !ruby/object:Gem::Version
96
124
  version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: cucumber
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: aruba
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
97
153
  - !ruby/object:Gem::Dependency
98
154
  name: pry
99
155
  requirement: !ruby/object:Gem::Requirement
@@ -109,7 +165,7 @@ dependencies:
109
165
  - !ruby/object:Gem::Version
110
166
  version: '0'
111
167
  - !ruby/object:Gem::Dependency
112
- name: cucumber
168
+ name: pry-stack_explorer
113
169
  requirement: !ruby/object:Gem::Requirement
114
170
  requirements:
115
171
  - - ">="
@@ -123,7 +179,35 @@ dependencies:
123
179
  - !ruby/object:Gem::Version
124
180
  version: '0'
125
181
  - !ruby/object:Gem::Dependency
126
- name: aruba
182
+ name: pry-byebug
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: pry-doc
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
209
+ - !ruby/object:Gem::Dependency
210
+ name: pry-awesome_print
127
211
  requirement: !ruby/object:Gem::Requirement
128
212
  requirements:
129
213
  - - ">="
@@ -136,8 +220,143 @@ dependencies:
136
220
  - - ">="
137
221
  - !ruby/object:Gem::Version
138
222
  version: '0'
139
- description: This gem turns a twitter feed into a fortune file that you can use with
140
- the fortune program
223
+ description: |
224
+ # Augury
225
+
226
+ Have you ever wanted to turn a twitter account into a fortune file?
227
+ Well, today is your lucky day!
228
+
229
+ Here is an example:
230
+
231
+ ```
232
+ $ augury generate SeinfeldToday
233
+ ```
234
+
235
+ This just created the fortune files in the current directory:
236
+
237
+ ```
238
+ $ ls
239
+ SeinfeldToday SeinfeldToday.dat
240
+ ```
241
+
242
+ You can now read the new fortunes!
243
+
244
+ ```
245
+ $ fortune SeinfeldToday
246
+ Elaine has no idea what her BF does for a living and it's now too
247
+ late to ask. E:"Teacher, I think. Or a doctor? Wait Is
248
+ 'computers' a job?"
249
+ ```
250
+
251
+ Thanks for all the laughs fortune :)
252
+
253
+ ## Installation
254
+
255
+ Add this line to your application's Gemfile:
256
+
257
+ ```ruby
258
+ gem 'augury'
259
+ ```
260
+
261
+ And then execute:
262
+
263
+ ```
264
+ $ bundle
265
+ ```
266
+
267
+ Or install it yourself as:
268
+
269
+ ```
270
+ $ gem install augury
271
+ ```
272
+
273
+ ### Requirements
274
+
275
+ This gem requires that the fortune program is also installed.
276
+ The fortune program ships with a `strfile` program that converts the plain text files to something that fortune can select from.
277
+
278
+ For example,
279
+ if you are using Homebrew on OS X:
280
+
281
+ ```
282
+ $ brew install fortune
283
+ ```
284
+
285
+ ## Configuration
286
+
287
+ ### Augury Config
288
+
289
+ Create the `~/.augry.cfg` file and then set the permissions since your Twitter API info will be in there.
290
+
291
+ ```sh
292
+ $ touch ~/.augury.cfg
293
+ $ chmod 600 ~/.augury.cfg
294
+ ```
295
+
296
+ Set any of these settings in the `augury` section of the config like this:
297
+
298
+ ```ini
299
+ [augury]
300
+ example_option = "An interesting value"
301
+ ```
302
+
303
+ ### Option list
304
+
305
+ These are the available options for the `~/.augury.cfg`
306
+
307
+ - `append` Make the script add more entries to the specified file instead of re-writing it. DEFAULT: False
308
+ - `width` Set the default width used if none is given on the command line. DEFAULT: 72
309
+
310
+ ### Twitter Setup
311
+
312
+ First, you will need to create a new Twitter application by going here:
313
+ https://apps.twitter.com
314
+
315
+ This will give you the ability to generate the consumer and access information used below.
316
+
317
+ Add the following to your `~/.augury.cfg` file.
318
+
319
+ ```ini
320
+ [twitter]
321
+ consumer_key = "YOUR_CONSUMER_KEY"
322
+ consumer_secret = "YOUR_CONSUMER_SECRET"
323
+ access_token = "YOUR_ACCESS_TOKEN"
324
+ access_token_secret = "YOUR_ACCESS_SECRET"
325
+ ```
326
+
327
+ ## Usage
328
+
329
+ Create a fortune for the latest SeinfeldToday tweets.
330
+
331
+ ```
332
+ $ augury generate SeinfeldToday
333
+ ```
334
+
335
+ Now you have some fortunes.
336
+
337
+ ```
338
+ $ fortune SeinfeldToday
339
+ ```
340
+
341
+ ## Development
342
+
343
+ After checking out the repo, run `bin/setup` to install dependencies.
344
+ Then, run `rake spec` to run the tests.
345
+ You can also run `bin/console` for an interactive prompt that will allow you to experiment.
346
+
347
+ To install this gem onto your local machine, run `bundle exec rake install`.
348
+ To release a new version, update the version number in `version.rb`,
349
+ and then run `bundle exec rake release`,
350
+ which will create a git tag for the version,
351
+ push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
352
+
353
+ ## Contributing
354
+
355
+ Bug reports and pull requests are welcome on GitHub at https://github.com/claytron/augury.
356
+
357
+ ## License
358
+
359
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
141
360
  email:
142
361
  - robots@claytron.com
143
362
  executables:
@@ -152,12 +371,14 @@ files:
152
371
  - LICENSE.txt
153
372
  - README.md
154
373
  - Rakefile
374
+ - TODO.md
155
375
  - augury.gemspec
156
376
  - bin/console
157
377
  - bin/setup
158
378
  - exe/augury
159
379
  - lib/augury.rb
160
380
  - lib/augury/cli.rb
381
+ - lib/augury/exception.rb
161
382
  - lib/augury/fortune.rb
162
383
  - lib/augury/version.rb
163
384
  homepage: https://github.com/claytron/augury
@@ -185,3 +406,4 @@ signing_key:
185
406
  specification_version: 4
186
407
  summary: Turn a twitter feed into a fortune file
187
408
  test_files: []
409
+ has_rdoc: