ayadn 2.0.9 → 2.0.10

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: c35b732787743af1ffb4606b914bce7e98eb8449
4
- data.tar.gz: 80061c722394c97348aa4495f06d4ab1ac19b5b1
3
+ metadata.gz: bf33bfde8fef88cb0cfb82f45fd388fc05147539
4
+ data.tar.gz: 0a7ec547cdc0dccc4b4de1e852436d4448fc6687
5
5
  SHA512:
6
- metadata.gz: db25cc0903fe97c2adf343790347f122f18d1a45b08e612bcea0ba9032c2927efa4beac0da5d25d1457b47ef28fc64bb7e7bd7add86c762c862912662d56d74c
7
- data.tar.gz: 8cf1393082834771a438592dd83d0d1a257714311e7c755348bf6d9b42e4e0aa7b8da22baa0e05a4502749e9133c44857708001cfee2d33ec6dbf5c5db118a39
6
+ metadata.gz: 5e70d85dc634475b3cb2b3a238b7090a9e5d3a77017af178e76c0a50653cf52ab61fa8cdc7d9362cbce1e47830f9cc21b22b3062767d7bbab40b83ea587f82da
7
+ data.tar.gz: dd7958ee8d7a976ac3ddceb331d00c19adec0833a4f1bd8789f17c95f9de9e041833bfba74decce8bad2e736d23f0eed63d2129e714f60e09aed3e0cd676edef
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 2.0.10 - 2015-02-21 - 'Haneke'
2
+
3
+ - New: cache results in Lists (and replay requests instantly)
4
+
1
5
  ## 2.0.9 - 2015-02-11 - 'Russel'
2
6
 
3
7
  - Fix: bug in add/remove user/mention to the blacklist
data/doc/05-streams.md CHANGED
@@ -283,6 +283,14 @@ You can get your own stars by using *me* instead of *@username*:
283
283
 
284
284
  `ayadn -was me`
285
285
 
286
+ You can cache the results if you want to replay the same request again later and obtain the same results instantly:
287
+
288
+ `ayadn -was --cache me`
289
+
290
+ `ayadn -was --again me`
291
+
292
+ *Note: `--cache` and `--again` don't have shortcuts.*
293
+
286
294
  # CONVO
287
295
 
288
296
  Show the conversation thread around a specific post.
data/doc/08-listings.md CHANGED
@@ -36,6 +36,14 @@ Force compact view (works with all compatible listing views):
36
36
 
37
37
  `ayadn -fwr -k me`
38
38
 
39
+ You can cache the results if you want to replay the same request again later and obtain the same results instantly:
40
+
41
+ `ayadn -fwr --cache me`
42
+
43
+ `ayadn -fwr --again me`
44
+
45
+ *Note: `--cache` and `--again` don't have shortcuts.*
46
+
39
47
  # FOLLOWINGS
40
48
 
41
49
  List the users a user is following.
@@ -80,6 +88,14 @@ Sort it by last post date:
80
88
 
81
89
  *Note: `-t` is ignored outside of 'last posts'. Other options are compatible with 'last posts' except `-r`.*
82
90
 
91
+ You can cache the results if you want to replay the same request again later and obtain the same results instantly:
92
+
93
+ `ayadn -fwg --cache me`
94
+
95
+ `ayadn -fwg --again me`
96
+
97
+ *Note: `--cache` and `--again` don't have shortcuts.*
98
+
83
99
  # CHANNELS
84
100
 
85
101
  List all your active App.net channels.
@@ -126,6 +142,30 @@ List users who reposted a post.
126
142
 
127
143
  `ayadn -wor 22790201`
128
144
 
145
+ You can cache the results if you want to replay the same request again later and obtain the same results instantly:
146
+
147
+ `ayadn -wor --cache 22790201`
148
+
149
+ `ayadn -wor --again 22790201`
150
+
151
+ *Note: `--cache` and `--again` don't have shortcuts.*
152
+
153
+ # WHOSTARRED
154
+
155
+ List users who starred a post.
156
+
157
+ `ayadn whostarred 22790201`
158
+
159
+ `ayadn -wos 22790201`
160
+
161
+ You can cache the results if you want to replay the same request again later and obtain the same results instantly:
162
+
163
+ `ayadn -wos --cache 22790201`
164
+
165
+ `ayadn -wos --again 22790201`
166
+
167
+ *Note: `--cache` and `--again` don't have shortcuts.*
168
+
129
169
  # MUTED
130
170
 
131
171
  List the users you muted.
@@ -156,6 +196,14 @@ Reverse the list order:
156
196
 
157
197
  `ayadn -mtd -u -r`
158
198
 
199
+ You can cache the results if you want to replay the same request again later and obtain the same results instantly:
200
+
201
+ `ayadn -mtd --cache`
202
+
203
+ `ayadn -mtd --again`
204
+
205
+ *Note: `--cache` and `--again` don't have shortcuts.*
206
+
159
207
  # BLOCKED
160
208
 
161
209
  List the users you blocked.
@@ -186,6 +234,14 @@ Reverse the list order:
186
234
 
187
235
  `ayadn -bkd -u -r`
188
236
 
237
+ You can cache the results if you want to replay the same request again later and obtain the same results instantly:
238
+
239
+ `ayadn -bkd --cache`
240
+
241
+ `ayadn -bkd --again`
242
+
243
+ *Note: `--cache` and `--again` don't have shortcuts.*
244
+
189
245
  # SETTINGS
190
246
 
191
247
  List current Ayadn settings.
data/lib/ayadn/api.rb CHANGED
@@ -289,7 +289,27 @@ module Ayadn
289
289
  end
290
290
 
291
291
  def get_parsed_response(url)
292
- JSON.parse(CNX.get_response_from(url))
292
+ working = true
293
+ begin
294
+ resp = JSON.parse(CNX.get_response_from(url))
295
+ return resp
296
+ rescue JSON::ParserError => e
297
+ if working == true
298
+ working = false
299
+ @status.server_error(true)
300
+ begin
301
+ sleep 10
302
+ rescue Interrupt
303
+ @status.canceled
304
+ exit
305
+ end
306
+ puts "\e[H\e[2J"
307
+ retry
308
+ else
309
+ @status.server_error(false)
310
+ Errors.global_error({error: e, caller: caller, data: [resp]})
311
+ end
312
+ end
293
313
  end
294
314
 
295
315
  def get_original_if_repost(resp)
data/lib/ayadn/app.rb CHANGED
@@ -141,6 +141,8 @@ module Ayadn
141
141
  option :raw, aliases: "-x", type: :boolean, desc: Descriptions.options_raw
142
142
  option :extract, aliases: "-e", type: :boolean, desc: Descriptions.options_extract
143
143
  option :compact, aliases: "-k", type: :boolean, desc: "Force the view to be compact if not already"
144
+ option :cache, type: :boolean, desc: "Cache the results"
145
+ option :again, type: :boolean, desc: "Run the last request from cache"
144
146
  def whatstarred(*username)
145
147
  Action.new.whatstarred(username, options)
146
148
  end
@@ -151,6 +153,8 @@ module Ayadn
151
153
  option :raw, aliases: "-x", type: :boolean, desc: Descriptions.options_raw
152
154
  option :force, aliases: "-f", type: :boolean, desc: "Force retrieve the actual post id (ignores index)"
153
155
  option :compact, aliases: "-k", type: :boolean, desc: "Force the view to be compact if not already"
156
+ option :cache, type: :boolean, desc: "Cache the results"
157
+ option :again, type: :boolean, desc: "Run the last request from cache"
154
158
  def whoreposted(post_id)
155
159
  Action.new.whoreposted(post_id, options)
156
160
  end
@@ -161,6 +165,8 @@ module Ayadn
161
165
  option :raw, aliases: "-x", type: :boolean, desc: Descriptions.options_raw
162
166
  option :force, aliases: "-f", type: :boolean, desc: "Force retrieve the actual post id (ignores index)"
163
167
  option :compact, aliases: "-k", type: :boolean, desc: "Force the view to be compact if not already"
168
+ option :cache, type: :boolean, desc: "Cache the results"
169
+ option :again, type: :boolean, desc: "Run the last request from cache"
164
170
  def whostarred(post_id)
165
171
  Action.new.whostarred(post_id, options)
166
172
  end
@@ -190,6 +196,8 @@ module Ayadn
190
196
  option :date, aliases: "-t", type: :boolean, desc: "Sort the list by: date (only with 'lastposts' option)"
191
197
  option :compact, aliases: "-k", type: :boolean, desc: "Force the view to be compact if not already"
192
198
  option :lastpost, aliases: "-l", type: :boolean, desc: "Displays the last post of each user"
199
+ option :cache, type: :boolean, desc: "Cache the results"
200
+ option :again, type: :boolean, desc: "Run the last request from cache"
193
201
  def followings(*username)
194
202
  Action.new.followings(username, options)
195
203
  end
@@ -204,6 +212,8 @@ module Ayadn
204
212
  option :posts_day, aliases: "-d", type: :boolean, desc: "Sort the list by: posts/day"
205
213
  option :posts, aliases: "-p", type: :boolean, desc: "Sort the list by: total posts"
206
214
  option :compact, aliases: "-k", type: :boolean, desc: "Force the view to be compact if not already"
215
+ option :cache, type: :boolean, desc: "Cache the results"
216
+ option :again, type: :boolean, desc: "Run the last request from cache"
207
217
  def followers(*username)
208
218
  Action.new.followers(username, options)
209
219
  end
@@ -218,6 +228,8 @@ module Ayadn
218
228
  option :posts_day, aliases: "-d", type: :boolean, desc: "Sort the list by: posts/day"
219
229
  option :posts, aliases: "-p", type: :boolean, desc: "Sort the list by: total posts"
220
230
  option :compact, aliases: "-k", type: :boolean, desc: "Force the view to be compact if not already"
231
+ option :cache, type: :boolean, desc: "Cache the results"
232
+ option :again, type: :boolean, desc: "Run the last request from cache"
221
233
  def muted
222
234
  Action.new.muted(options)
223
235
  end
@@ -232,6 +244,8 @@ module Ayadn
232
244
  option :posts_day, aliases: "-d", type: :boolean, desc: "Sort the list by: posts/day"
233
245
  option :posts, aliases: "-p", type: :boolean, desc: "Sort the list by: total posts"
234
246
  option :compact, aliases: "-k", type: :boolean, desc: "Force the view to be compact if not already"
247
+ option :cache, type: :boolean, desc: "Cache the results"
248
+ option :again, type: :boolean, desc: "Run the last request from cache"
235
249
  def blocked
236
250
  Action.new.blocked(options)
237
251
  end
data/lib/ayadn/cnx.rb CHANGED
@@ -115,31 +115,13 @@ module Ayadn
115
115
  case response.code
116
116
  when 200
117
117
  response
118
- when 204
119
- thor.say_status :error, message.upcase, :red
120
- Errors.global_error({error: message, caller: caller, data: [res]})
121
- when 400
122
- thor.say_status :error, message.upcase, :red
123
- Errors.global_error({error: message, caller: caller, data: [res]})
124
- when 401
125
- thor.say_status :error, message.upcase, :red
126
- Errors.global_error({error: message, caller: caller, data: [res]})
127
- when 403
128
- thor.say_status :error, message.upcase, :red
129
- Errors.global_error({error: message, caller: caller, data: [res]})
130
- when 405
118
+ when 204, 400, 401, 403, 405, 500, 502, 504
131
119
  thor.say_status :error, message.upcase, :red
132
120
  Errors.global_error({error: message, caller: caller, data: [res]})
133
121
  when 429
134
122
  thor.say_status :error, message.upcase, :red
135
123
  puts "\n\nAyadn made too many requests to the App.net API. You should wait at least ".color(:cyan) + "#{response.headers[:retry_after]} ".color(:red) + "seconds before trying again. Maybe you launched a lot of Ayadn instances at the same time? That's no problem, but in this case you should increase the value of the scroll timer (with `ayadn set scroll timer 5` for example). App.net allows 5000 requests per hour per account maximum.".color(:cyan)
136
124
  Errors.global_error({error: message, caller: caller, data: [res]})
137
- when 500
138
- thor.say_status :error, message.upcase, :red
139
- Errors.global_error({error: message, caller: caller, data: [res]})
140
- when 507
141
- thor.say_status :error, message.upcase, :red
142
- Errors.global_error({error: message, caller: caller, data: [res]})
143
125
  else
144
126
  response
145
127
  end
data/lib/ayadn/fileops.rb CHANGED
@@ -2,6 +2,20 @@
2
2
  module Ayadn
3
3
  class FileOps
4
4
 
5
+ def self.cache_list(list, name)
6
+ File.write(Settings.config[:paths][:lists] + "/.#{name}", list.to_json)
7
+ end
8
+
9
+ def self.cached_list(name)
10
+ file_path = Settings.config[:paths][:lists] + "/.#{name}"
11
+ if File.exist?(file_path)
12
+ data = File.read(file_path)
13
+ JSON.load(data)
14
+ else
15
+ nil
16
+ end
17
+ end
18
+
5
19
  def self.save_links(obj, name)
6
20
  File.write(Settings.config[:paths][:lists] + "/#{name}", obj.to_json)
7
21
  end
data/lib/ayadn/status.rb CHANGED
@@ -527,6 +527,20 @@ module Ayadn
527
527
  @thor.say_status "next", "Ayadn will use these elements to insert album artwork and a link", :cyan
528
528
  end
529
529
 
530
+ def server_error(bool)
531
+ if bool == true
532
+ say do
533
+ @thor.say_status :error, "Ayadn couldn't get the JSON reponse", :red
534
+ @thor.say_status :next, "trying again in 10 seconds", :yellow
535
+ end
536
+ else
537
+ say do
538
+ @thor.say_status :error, "Ayadn couldn't get the JSON reponse", :red
539
+ @thor.say_status :status, "Current command canceled after one retry", :yellow
540
+ end
541
+ end
542
+ end
543
+
530
544
  ##---
531
545
 
532
546
  def info(status, message, color = nil)
data/lib/ayadn/stream.rb CHANGED
@@ -114,23 +114,44 @@ module Ayadn
114
114
  def whatstarred(username, options)
115
115
  @check.no_username(username)
116
116
  username = @workers.add_arobase(username)
117
- @view.downloading(options)
118
- stream = @api.get_whatstarred(username, options)
117
+ @view.downloading(options) unless options["again"]
118
+
119
+ if options["again"]
120
+ stream = FileOps.cached_list("whatstarred")
121
+ Errors.no_data('cached whatstarred') if stream.nil?
122
+ else
123
+ stream = @api.get_whatstarred(username, options)
124
+ end
125
+
119
126
  @check.no_user(stream, username)
120
127
  @check.no_data(stream, 'whatstarred')
121
- options[:extract] ? @view.all_stars_links(stream) : @view.render(stream, options)
128
+
129
+ if options["cache"] && options["again"].nil?
130
+ FileOps.cache_list(stream, "whatstarred")
131
+ end
132
+
133
+ if options[:extract]
134
+ @view.all_stars_links(stream)
135
+ else
136
+ @view.render(stream, options)
137
+ end
122
138
  puts "\n" if Settings.options[:timeline][:compact] == true
123
139
  end
124
140
 
125
141
  def followings(username, options)
126
142
  @check.no_username(username)
127
143
  username = @workers.add_arobase(username)
128
- @view.downloading(options)
144
+ @view.downloading(options) unless options["again"]
129
145
  show_raw_list(username, :followings, options)
130
- list = @api.get_followings(username)
146
+ if options["again"]
147
+ list = FileOps.cached_list("followings")
148
+ Errors.no_data('cached followings') if list.nil?
149
+ else
150
+ list = @api.get_followings(username)
151
+ end
131
152
  @check.auto_save_followings(list)
132
153
  Errors.no_data('followings') if list.empty?
133
- if options["lastpost"]
154
+ if options["lastpost"] && options["again"].nil?
134
155
  count = list.size
135
156
  @workers.thor.say_status :downloading, "please wait, it may take a while...", :red
136
157
  puts "\n"
@@ -145,6 +166,9 @@ module Ayadn
145
166
  obj << resp["data"][0]
146
167
  end
147
168
  end
169
+ if options["cache"] && options["again"].nil?
170
+ FileOps.cache_list(list, "followings")
171
+ end
148
172
  @view.list(:followings, list, username, options)
149
173
  Databases.add_to_users_db_from_list(list)
150
174
  end
@@ -152,29 +176,61 @@ module Ayadn
152
176
  def followers(username, options)
153
177
  @check.no_username(username)
154
178
  username = @workers.add_arobase(username)
155
- @view.downloading(options)
179
+ @view.downloading(options) unless options["again"]
156
180
  show_raw_list(username, :followers, options)
157
- list = @api.get_followers(username)
181
+
182
+ if options["again"]
183
+ list = FileOps.cached_list("followers")
184
+ Errors.no_data('cached followers') if list.nil?
185
+ else
186
+ list = @api.get_followers(username)
187
+ end
188
+
158
189
  @check.auto_save_followers(list)
190
+
191
+ if options["cache"] && options["again"].nil?
192
+ FileOps.cache_list(list, "followers")
193
+ end
194
+
159
195
  Errors.no_data('followers') if list.empty?
160
196
  @view.list(:followers, list, username, options)
161
197
  Databases.add_to_users_db_from_list(list)
162
198
  end
163
199
 
164
200
  def muted(options)
165
- @view.downloading(options)
201
+ @view.downloading(options) unless options["again"]
166
202
  show_raw_list(nil, :muted, options)
167
- list = @api.get_muted
203
+
204
+ if options["again"]
205
+ list = FileOps.cached_list("muted")
206
+ Errors.no_data('cached muted') if list.nil?
207
+ else
208
+ list = @api.get_muted
209
+ end
210
+
168
211
  @check.auto_save_muted(list)
212
+
213
+ if options["cache"] && options["again"].nil?
214
+ FileOps.cache_list(list, "muted")
215
+ end
216
+
169
217
  Errors.no_data('muted') if list.empty?
170
218
  @view.list(:muted, list, nil, options)
171
219
  Databases.add_to_users_db_from_list(list)
172
220
  end
173
221
 
174
222
  def blocked(options)
175
- @view.downloading(options)
223
+ @view.downloading(options) unless options["again"]
176
224
  show_raw_list(nil, :blocked, options)
177
- list = @api.get_blocked
225
+ if options["again"]
226
+ list = FileOps.cached_list("blocked")
227
+ Errors.no_data('cached blocked') if list.nil?
228
+ else
229
+ list = @api.get_blocked
230
+ end
231
+ if options["cache"] && options["again"].nil?
232
+ FileOps.cache_list(list, "blocked")
233
+ end
178
234
  Errors.no_data('blocked') if list.empty?
179
235
  @view.list(:blocked, list, nil, options)
180
236
  Databases.add_to_users_db_from_list(list)
@@ -194,11 +250,33 @@ module Ayadn
194
250
  unless options[:force]
195
251
  post_id = @workers.get_real_post_id(post_id)
196
252
  end
197
- @view.downloading(options)
198
- details = @api.get_details(post_id, options)
253
+ @view.downloading(options) unless options["again"]
254
+
255
+ if options["again"]
256
+ details = FileOps.cached_list("whoreposted_details")
257
+ Errors.no_data('cached whoreposted details') if details.nil?
258
+ else
259
+ details = @api.get_details(post_id, options)
260
+ end
261
+
199
262
  @check.no_post(details, post_id)
200
263
  id = @workers.get_original_id(post_id, details)
201
- list = @api.get_whoreposted(id)
264
+
265
+ if options["cache"] && options["again"].nil?
266
+ FileOps.cache_list(details, "whoreposted_details")
267
+ end
268
+
269
+ if options["again"]
270
+ list = FileOps.cached_list("whoreposted")
271
+ Errors.no_data('cached whoreposted') if list.nil?
272
+ else
273
+ list = @api.get_whoreposted(id)
274
+ end
275
+
276
+ if options["cache"] && options["again"].nil?
277
+ FileOps.cache_list(list, "whoreposted")
278
+ end
279
+
202
280
  @view.if_raw(list, options)
203
281
  if list['data'].empty?
204
282
  @status.nobody_reposted
@@ -212,11 +290,33 @@ module Ayadn
212
290
  unless options[:force]
213
291
  post_id = @workers.get_real_post_id(post_id)
214
292
  end
215
- @view.downloading(options)
216
- details = @api.get_details(post_id, options)
293
+ @view.downloading(options) unless options["again"]
294
+
295
+ if options["again"]
296
+ details = FileOps.cached_list("whostarred_details")
297
+ Errors.no_data('cached whostarred details') if details.nil?
298
+ else
299
+ details = @api.get_details(post_id, options)
300
+ end
301
+
217
302
  @check.no_post(details, post_id)
218
303
  id = @workers.get_original_id(post_id, details)
219
- list = @api.get_whostarred(id)
304
+
305
+ if options["cache"] && options["again"].nil?
306
+ FileOps.cache_list(details, "whostarred_details")
307
+ end
308
+
309
+ if options["again"]
310
+ list = FileOps.cached_list("whostarred")
311
+ Errors.no_data('cached whostarred') if list.nil?
312
+ else
313
+ list = @api.get_whostarred(id)
314
+ end
315
+
316
+ if options["cache"] && options["again"].nil?
317
+ FileOps.cache_list(list, "whostarred")
318
+ end
319
+
220
320
  @view.if_raw(list, options)
221
321
  if list['data'].empty?
222
322
  @status.nobody_starred
@@ -310,7 +410,19 @@ module Ayadn
310
410
 
311
411
  def show_raw_list username, what, options
312
412
  if options[:raw]
313
- @view.show_raw(@api.get_raw_list(username, what), options)
413
+
414
+ if options["again"]
415
+ list = FileOps.cached_list("#{username}_#{what}")
416
+ Errors.no_data("#{username}_#{what}") if list.nil?
417
+ else
418
+ list = @api.get_raw_list(username, what)
419
+ end
420
+
421
+ if options["cache"] && options["again"].nil?
422
+ FileOps.cache_list(list, "#{username}_#{what}")
423
+ end
424
+
425
+ @view.show_raw(list, options)
314
426
  exit
315
427
  end
316
428
  end