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 +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +22 -0
- data/README.md +99 -17
- data/TODO.md +1 -1
- data/bin/console +2 -0
- data/bin/setup +1 -3
- data/lib/augury/cli.rb +22 -14
- data/lib/augury/fortune.rb +37 -11
- data/lib/augury/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a0c7c48771363a9a5c848e76b7747bf9b5d9fbd3
|
4
|
+
data.tar.gz: 2dd47ecc12e320134c3ce249f64e088a436a1a4e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8afece52e31616184f74750ae3eee61eca34ef30a7582ffac4f9777b3515cbea1e84d94e5610a4a2f1b1bb075cd64d1bb77358a564bded2a9251d83e26aa917e
|
7
|
+
data.tar.gz: c5ad6b4b98c483fca41f513f29e201f0b9a13b1f0bd9b31c3f34e725179d4b52b28ca98bae506169111e5e64ebdadaccbfd8ca75df5cebba73d30646e008dbb7
|
data/.gitignore
CHANGED
data/CHANGELOG.md
ADDED
@@ -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
|
-
|
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
|
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
|
-
|
23
|
+
seinfeldtoday seinfeldtoday.dat
|
17
24
|
```
|
18
25
|
|
19
26
|
You can now read the new fortunes!
|
20
27
|
|
21
28
|
```
|
22
|
-
$ fortune
|
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
|
-
|
85
|
-
|
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
|
123
|
+
Create a fortune for the latest *seinfeldtoday* tweets.
|
107
124
|
|
108
125
|
```
|
109
|
-
$ augury generate
|
126
|
+
$ augury generate seinfeldtoday
|
110
127
|
```
|
111
128
|
|
112
129
|
Now you have some fortunes.
|
113
130
|
|
114
131
|
```
|
115
|
-
$ fortune
|
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
|
-
|
121
|
-
|
122
|
-
|
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
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
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.
|
data/bin/console
CHANGED
data/bin/setup
CHANGED
data/lib/augury/cli.rb
CHANGED
@@ -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,
|
8
|
-
|
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
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
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
|
data/lib/augury/fortune.rb
CHANGED
@@ -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']
|
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
|
32
|
-
|
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
|
36
|
-
tweets.flat_map { |tweet| tweet.
|
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
|
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
|
data/lib/augury/version.rb
CHANGED
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.
|
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-
|
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
|