ayadn 1.4.2 → 1.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -2
- data/CHANGELOG.md +12 -2
- data/ayadn.gemspec +1 -1
- data/lib/ayadn/action.rb +418 -427
- data/lib/ayadn/alias.rb +5 -5
- data/lib/ayadn/api.rb +3 -2
- data/lib/ayadn/app.rb +2 -1
- data/lib/ayadn/cnx.rb +32 -32
- data/lib/ayadn/databases.rb +2 -6
- data/lib/ayadn/debug.rb +53 -36
- data/lib/ayadn/errors.rb +13 -15
- data/lib/ayadn/logs.rb +2 -2
- data/lib/ayadn/mark.rb +5 -5
- data/lib/ayadn/pinboard.rb +1 -1
- data/lib/ayadn/post.rb +7 -29
- data/lib/ayadn/settings.rb +2 -2
- data/lib/ayadn/status.rb +18 -12
- data/lib/ayadn/version.rb +1 -1
- data/lib/ayadn/view.rb +4 -1
- data/lib/ayadn.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- data/spec/unit/blacklistworkers_spec.rb +8 -8
- data/spec/unit/post_spec.rb +12 -12
- data/spec/unit/set_spec.rb +4 -4
- metadata +3 -3
data/lib/ayadn/action.rb
CHANGED
@@ -10,20 +10,19 @@ module Ayadn
|
|
10
10
|
Settings.init_config
|
11
11
|
Logs.create_logger
|
12
12
|
Databases.open_databases
|
13
|
+
at_exit { Databases.close_all }
|
13
14
|
end
|
14
15
|
|
15
16
|
def unified(options)
|
16
17
|
begin
|
17
18
|
doing(options)
|
18
19
|
stream = @api.get_unified(options)
|
19
|
-
(
|
20
|
+
stop_if_no_new_posts(stream, options, 'unified')
|
20
21
|
Databases.save_max_id(stream)
|
21
22
|
render_view(stream, options)
|
22
23
|
Scroll.new(@api, @view).unified(options) if options[:scroll]
|
23
24
|
rescue => e
|
24
|
-
Errors.global_error(
|
25
|
-
ensure
|
26
|
-
Databases.close_all
|
25
|
+
Errors.global_error({error: e, caller: caller, data: [options]})
|
27
26
|
end
|
28
27
|
end
|
29
28
|
|
@@ -31,34 +30,28 @@ module Ayadn
|
|
31
30
|
begin
|
32
31
|
doing(options)
|
33
32
|
stream = @api.get_checkins(options)
|
34
|
-
(
|
33
|
+
stop_if_no_new_posts(stream, options, 'explore:checkins')
|
35
34
|
Databases.save_max_id(stream)
|
36
35
|
render_view(stream, options)
|
37
36
|
Scroll.new(@api, @view).checkins(options) if options[:scroll]
|
38
37
|
rescue => e
|
39
|
-
Errors.global_error(
|
40
|
-
ensure
|
41
|
-
Databases.close_all
|
38
|
+
Errors.global_error({error: e, caller: caller, data: [options]})
|
42
39
|
end
|
43
40
|
end
|
44
41
|
|
45
42
|
def global(settings)
|
46
43
|
begin
|
47
44
|
options = settings.dup
|
48
|
-
|
49
|
-
options[:filter] = true if Settings.options[:nicerank][:filter] == true
|
50
|
-
end
|
45
|
+
options[:filter] = nicerank_true()
|
51
46
|
doing(options)
|
52
47
|
stream = @api.get_global(options)
|
53
|
-
niceranks = NiceRank.new.get_ranks
|
54
|
-
(
|
48
|
+
niceranks = NiceRank.new.get_ranks(stream)
|
49
|
+
stop_if_no_new_posts(stream, options, 'global')
|
55
50
|
Databases.save_max_id(stream)
|
56
51
|
render_view(stream, options, niceranks)
|
57
52
|
Scroll.new(@api, @view).global(options) if options[:scroll]
|
58
53
|
rescue => e
|
59
|
-
Errors.global_error(
|
60
|
-
ensure
|
61
|
-
Databases.close_all
|
54
|
+
Errors.global_error({error: e, caller: caller, data: [options]})
|
62
55
|
end
|
63
56
|
end
|
64
57
|
|
@@ -66,14 +59,12 @@ module Ayadn
|
|
66
59
|
begin
|
67
60
|
doing(options)
|
68
61
|
stream = @api.get_trending(options)
|
69
|
-
(
|
62
|
+
stop_if_no_new_posts(stream, options, 'explore:trending')
|
70
63
|
Databases.save_max_id(stream)
|
71
64
|
render_view(stream, options)
|
72
65
|
Scroll.new(@api, @view).trending(options) if options[:scroll]
|
73
66
|
rescue => e
|
74
|
-
Errors.global_error(
|
75
|
-
ensure
|
76
|
-
Databases.close_all
|
67
|
+
Errors.global_error({error: e, caller: caller, data: [options]})
|
77
68
|
end
|
78
69
|
end
|
79
70
|
|
@@ -81,14 +72,12 @@ module Ayadn
|
|
81
72
|
begin
|
82
73
|
doing(options)
|
83
74
|
stream = @api.get_photos(options)
|
84
|
-
(
|
75
|
+
stop_if_no_new_posts(stream, options, 'explore:photos')
|
85
76
|
Databases.save_max_id(stream)
|
86
77
|
render_view(stream, options)
|
87
78
|
Scroll.new(@api, @view).photos(options) if options[:scroll]
|
88
79
|
rescue => e
|
89
|
-
Errors.global_error(
|
90
|
-
ensure
|
91
|
-
Databases.close_all
|
80
|
+
Errors.global_error({error: e, caller: caller, data: [options]})
|
92
81
|
end
|
93
82
|
end
|
94
83
|
|
@@ -96,52 +85,46 @@ module Ayadn
|
|
96
85
|
begin
|
97
86
|
doing(options)
|
98
87
|
stream = @api.get_conversations(options)
|
99
|
-
(
|
88
|
+
stop_if_no_new_posts(stream, options, 'explore:replies')
|
100
89
|
Databases.save_max_id(stream)
|
101
90
|
render_view(stream, options)
|
102
91
|
Scroll.new(@api, @view).replies(options) if options[:scroll]
|
103
92
|
rescue => e
|
104
|
-
Errors.global_error(
|
105
|
-
ensure
|
106
|
-
Databases.close_all
|
93
|
+
Errors.global_error({error: e, caller: caller, data: [options]})
|
107
94
|
end
|
108
95
|
end
|
109
96
|
|
110
97
|
def mentions(username, options)
|
111
98
|
begin
|
112
|
-
|
113
|
-
username =
|
99
|
+
stop_if_no_username(username)
|
100
|
+
username = add_arobase(username)
|
114
101
|
doing(options)
|
115
102
|
stream = @api.get_mentions(username, options)
|
116
|
-
|
103
|
+
stop_if_no_user(stream, username)
|
117
104
|
Databases.save_max_id(stream)
|
118
105
|
options = options.dup
|
119
106
|
options[:in_mentions] = true
|
120
|
-
|
107
|
+
stop_if_no_data(stream, 'mentions')
|
121
108
|
render_view(stream, options)
|
122
109
|
Scroll.new(@api, @view).mentions(username, options) if options[:scroll]
|
123
110
|
rescue => e
|
124
|
-
Errors.global_error(
|
125
|
-
ensure
|
126
|
-
Databases.close_all
|
111
|
+
Errors.global_error({error: e, caller: caller, data: [username, options]})
|
127
112
|
end
|
128
113
|
end
|
129
114
|
|
130
115
|
def posts(username, options)
|
131
116
|
begin
|
132
|
-
|
133
|
-
username =
|
117
|
+
stop_if_no_username(username)
|
118
|
+
username = add_arobase(username)
|
134
119
|
doing(options)
|
135
120
|
stream = @api.get_posts(username, options)
|
136
|
-
|
121
|
+
stop_if_no_user(stream, username)
|
137
122
|
Databases.save_max_id(stream)
|
138
|
-
|
123
|
+
stop_if_no_data(stream, 'mentions')
|
139
124
|
render_view(stream, options)
|
140
125
|
Scroll.new(@api, @view).posts(username, options) if options[:scroll]
|
141
126
|
rescue => e
|
142
|
-
Errors.global_error(
|
143
|
-
ensure
|
144
|
-
Databases.close_all
|
127
|
+
Errors.global_error({error: e, caller: caller, data: [username, options]})
|
145
128
|
end
|
146
129
|
end
|
147
130
|
|
@@ -149,114 +132,95 @@ module Ayadn
|
|
149
132
|
begin
|
150
133
|
doing(options)
|
151
134
|
stream = @api.get_interactions
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
else
|
156
|
-
@view.show_raw(stream)
|
157
|
-
end
|
135
|
+
option_show_raw(stream, options)
|
136
|
+
@view.clear_screen
|
137
|
+
@view.show_interactions(stream['data'])
|
158
138
|
rescue => e
|
159
|
-
Errors.global_error(
|
160
|
-
ensure
|
161
|
-
Databases.close_all
|
139
|
+
Errors.global_error({error: e, caller: caller, data: [options]})
|
162
140
|
end
|
163
141
|
end
|
164
142
|
|
165
143
|
def whatstarred(username, options)
|
166
144
|
begin
|
167
|
-
|
168
|
-
username =
|
145
|
+
stop_if_no_username(username)
|
146
|
+
username = add_arobase(username)
|
169
147
|
doing(options)
|
170
148
|
stream = @api.get_whatstarred(username, options)
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
view_all_stars_links(stream)
|
175
|
-
else
|
176
|
-
render_view(stream, options)
|
177
|
-
end
|
149
|
+
stop_if_no_user(stream, username)
|
150
|
+
stop_if_no_data(stream, 'whatstarred')
|
151
|
+
options[:extract] ? view_all_stars_links(stream) : render_view(stream, options)
|
178
152
|
rescue => e
|
179
|
-
Errors.global_error(
|
180
|
-
ensure
|
181
|
-
Databases.close_all
|
153
|
+
Errors.global_error({error: e, caller: caller, data: [username, options]})
|
182
154
|
end
|
183
155
|
end
|
184
156
|
|
185
157
|
def whoreposted(post_id, options)
|
186
158
|
begin
|
187
|
-
|
159
|
+
stop_if_bad_post_id(post_id)
|
188
160
|
doing(options)
|
189
|
-
|
161
|
+
details = @api.get_details(post_id, options)
|
162
|
+
stop_if_404(details, post_id)
|
163
|
+
id = get_original_id(post_id, details)
|
190
164
|
list = @api.get_whoreposted(id)
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
else
|
195
|
-
puts Status.nobody_reposted
|
196
|
-
end
|
165
|
+
option_show_raw(list, options)
|
166
|
+
unless list['data'].empty?
|
167
|
+
get_list(:whoreposted, list['data'], post_id)
|
197
168
|
else
|
198
|
-
|
169
|
+
puts Status.nobody_reposted
|
199
170
|
end
|
200
171
|
rescue => e
|
201
|
-
Errors.global_error(
|
202
|
-
ensure
|
203
|
-
Databases.close_all
|
172
|
+
Errors.global_error({error: e, caller: caller, data: [post_id, options]})
|
204
173
|
end
|
205
174
|
end
|
206
175
|
|
207
176
|
def whostarred(post_id, options)
|
208
177
|
begin
|
209
|
-
|
178
|
+
stop_if_bad_post_id(post_id)
|
210
179
|
doing(options)
|
211
|
-
|
180
|
+
details = @api.get_details(post_id, options)
|
181
|
+
stop_if_404(details, post_id)
|
182
|
+
id = get_original_id(post_id, details)
|
212
183
|
list = @api.get_whostarred(id)
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
else
|
217
|
-
puts Status.nobody_starred
|
218
|
-
end
|
184
|
+
option_show_raw(list, options)
|
185
|
+
unless list['data'].empty?
|
186
|
+
get_list(:whostarred, list['data'], id)
|
219
187
|
else
|
220
|
-
|
188
|
+
puts Status.nobody_starred
|
221
189
|
end
|
222
190
|
rescue => e
|
223
|
-
Errors.global_error(
|
224
|
-
ensure
|
225
|
-
Databases.close_all
|
191
|
+
Errors.global_error({error: e, caller: caller, data: [post_id, id, options]})
|
226
192
|
end
|
227
193
|
end
|
228
194
|
|
229
195
|
def convo(post_id, options)
|
230
196
|
begin
|
231
|
-
|
197
|
+
stop_if_bad_post_id(post_id)
|
232
198
|
doing(options)
|
233
|
-
|
199
|
+
details = @api.get_details(post_id, options)
|
200
|
+
stop_if_404(details, post_id)
|
201
|
+
id = get_original_id(post_id, details)
|
234
202
|
stream = get_convo id, options
|
235
203
|
Databases.pagination["replies:#{id}"] = stream['meta']['max_id']
|
236
204
|
render_view(stream, options)
|
237
205
|
Scroll.new(@api, @view).convo(id, options) if options[:scroll]
|
238
206
|
rescue => e
|
239
|
-
Errors.global_error(
|
240
|
-
ensure
|
241
|
-
Databases.close_all
|
207
|
+
Errors.global_error({error: e, caller: caller, data: [post_id, id, options]})
|
242
208
|
end
|
243
209
|
end
|
244
210
|
|
245
211
|
def get_convo id, options
|
246
212
|
stream = @api.get_convo(id, options)
|
247
|
-
|
213
|
+
stop_if_no_post(stream, id)
|
248
214
|
stream
|
249
215
|
end
|
250
216
|
|
251
217
|
def delete(post_id)
|
252
218
|
begin
|
253
|
-
|
219
|
+
stop_if_bad_post_id(post_id)
|
254
220
|
print Status.deleting_post(post_id)
|
255
221
|
check_has_been_deleted(post_id, @api.delete_post(post_id))
|
256
222
|
rescue => e
|
257
|
-
Errors.global_error(
|
258
|
-
ensure
|
259
|
-
Databases.close_all
|
223
|
+
Errors.global_error({error: e, caller: caller, data: [post_id]})
|
260
224
|
end
|
261
225
|
end
|
262
226
|
|
@@ -270,108 +234,92 @@ module Ayadn
|
|
270
234
|
resp = @api.delete_message(channel_id, message_id)
|
271
235
|
check_message_has_been_deleted(message_id, resp)
|
272
236
|
rescue => e
|
273
|
-
Errors.global_error(
|
274
|
-
ensure
|
275
|
-
Databases.close_all
|
237
|
+
Errors.global_error({error: e, caller: caller, data: [message_id]})
|
276
238
|
end
|
277
239
|
end
|
278
240
|
|
279
241
|
def unfollow(username)
|
280
242
|
begin
|
281
|
-
|
282
|
-
username =
|
243
|
+
stop_if_no_username(username)
|
244
|
+
username = add_arobase(username)
|
283
245
|
puts Status.unfollowing(username)
|
284
246
|
check_has_been_unfollowed(username, @api.unfollow(username))
|
285
247
|
rescue => e
|
286
|
-
Errors.global_error(
|
287
|
-
ensure
|
288
|
-
Databases.close_all
|
248
|
+
Errors.global_error({error: e, caller: caller, data: [username]})
|
289
249
|
end
|
290
250
|
end
|
291
251
|
|
292
252
|
def follow(username)
|
293
253
|
begin
|
294
|
-
|
295
|
-
username =
|
254
|
+
stop_if_no_username(username)
|
255
|
+
username = add_arobase(username)
|
296
256
|
puts Status.following(username)
|
297
257
|
check_has_been_followed(username, @api.follow(username))
|
298
258
|
rescue => e
|
299
|
-
Errors.global_error(
|
300
|
-
ensure
|
301
|
-
Databases.close_all
|
259
|
+
Errors.global_error({error: e, caller: caller, data: [username]})
|
302
260
|
end
|
303
261
|
end
|
304
262
|
|
305
263
|
def unmute(username)
|
306
264
|
begin
|
307
|
-
|
308
|
-
username =
|
265
|
+
stop_if_no_username(username)
|
266
|
+
username = add_arobase(username)
|
309
267
|
puts Status.unmuting(username)
|
310
268
|
check_has_been_unmuted(username, @api.unmute(username))
|
311
269
|
rescue => e
|
312
|
-
Errors.global_error(
|
313
|
-
ensure
|
314
|
-
Databases.close_all
|
270
|
+
Errors.global_error({error: e, caller: caller, data: [username]})
|
315
271
|
end
|
316
272
|
end
|
317
273
|
|
318
274
|
def mute(username)
|
319
275
|
begin
|
320
|
-
|
321
|
-
username =
|
276
|
+
stop_if_no_username(username)
|
277
|
+
username = add_arobase(username)
|
322
278
|
puts Status.muting(username)
|
323
279
|
check_has_been_muted(username, @api.mute(username))
|
324
280
|
rescue => e
|
325
|
-
Errors.global_error(
|
326
|
-
ensure
|
327
|
-
Databases.close_all
|
281
|
+
Errors.global_error({error: e, caller: caller, data: [username]})
|
328
282
|
end
|
329
283
|
end
|
330
284
|
|
331
285
|
def unblock(username)
|
332
286
|
begin
|
333
|
-
|
334
|
-
username =
|
287
|
+
stop_if_no_username(username)
|
288
|
+
username = add_arobase(username)
|
335
289
|
puts Status.unblocking(username)
|
336
290
|
check_has_been_unblocked(username, @api.unblock(username))
|
337
291
|
rescue => e
|
338
|
-
Errors.global_error(
|
339
|
-
ensure
|
340
|
-
Databases.close_all
|
292
|
+
Errors.global_error({error: e, caller: caller, data: [username]})
|
341
293
|
end
|
342
294
|
end
|
343
295
|
|
344
296
|
def block(username)
|
345
297
|
begin
|
346
|
-
|
347
|
-
username =
|
298
|
+
stop_if_no_username(username)
|
299
|
+
username = add_arobase(username)
|
348
300
|
puts Status.blocking(username)
|
349
301
|
check_has_been_blocked(username, @api.block(username))
|
350
302
|
rescue => e
|
351
|
-
Errors.global_error(
|
352
|
-
ensure
|
353
|
-
Databases.close_all
|
303
|
+
Errors.global_error({error: e, caller: caller, data: [username]})
|
354
304
|
end
|
355
305
|
end
|
356
306
|
|
357
307
|
def repost(post_id)
|
358
308
|
begin
|
359
|
-
|
309
|
+
stop_if_bad_post_id(post_id)
|
360
310
|
puts Status.reposting(post_id)
|
361
311
|
resp = @api.get_details(post_id)
|
362
312
|
check_if_already_reposted(resp)
|
363
313
|
id = get_original_id(post_id, resp)
|
364
314
|
check_has_been_reposted(id, @api.repost(id))
|
365
315
|
rescue => e
|
366
|
-
Errors.global_error(
|
367
|
-
ensure
|
368
|
-
Databases.close_all
|
316
|
+
Errors.global_error({error: e, caller: caller, data: [post_id, id]})
|
369
317
|
end
|
370
318
|
end
|
371
319
|
|
372
320
|
def unrepost(post_id)
|
373
321
|
begin
|
374
|
-
|
322
|
+
stop_if_bad_post_id(post_id)
|
375
323
|
puts Status.unreposting(post_id)
|
376
324
|
if @api.get_details(post_id)['data']['you_reposted']
|
377
325
|
check_has_been_unreposted(post_id, @api.unrepost(post_id))
|
@@ -379,15 +327,13 @@ module Ayadn
|
|
379
327
|
puts Status.not_your_repost
|
380
328
|
end
|
381
329
|
rescue => e
|
382
|
-
Errors.global_error(
|
383
|
-
ensure
|
384
|
-
Databases.close_all
|
330
|
+
Errors.global_error({error: e, caller: caller, data: [post_id]})
|
385
331
|
end
|
386
332
|
end
|
387
333
|
|
388
334
|
def unstar(post_id)
|
389
335
|
begin
|
390
|
-
|
336
|
+
stop_if_bad_post_id(post_id)
|
391
337
|
puts Status.unstarring(post_id)
|
392
338
|
resp = @api.get_details(post_id)
|
393
339
|
id = get_original_id(post_id, resp)
|
@@ -398,24 +344,20 @@ module Ayadn
|
|
398
344
|
puts Status.not_your_starred
|
399
345
|
end
|
400
346
|
rescue => e
|
401
|
-
Errors.global_error(
|
402
|
-
ensure
|
403
|
-
Databases.close_all
|
347
|
+
Errors.global_error({error: e, caller: caller, data: [post_id]})
|
404
348
|
end
|
405
349
|
end
|
406
350
|
|
407
351
|
def star(post_id)
|
408
352
|
begin
|
409
|
-
|
353
|
+
stop_if_bad_post_id(post_id)
|
410
354
|
puts Status.starring(post_id)
|
411
355
|
resp = @api.get_details(post_id)
|
412
356
|
check_if_already_starred(resp)
|
413
357
|
id = get_original_id(post_id, resp)
|
414
358
|
check_has_been_starred(id, @api.star(id))
|
415
359
|
rescue => e
|
416
|
-
Errors.global_error(
|
417
|
-
ensure
|
418
|
-
Databases.close_all
|
360
|
+
Errors.global_error({error: e, caller: caller, data: [post_id]})
|
419
361
|
end
|
420
362
|
end
|
421
363
|
|
@@ -423,16 +365,14 @@ module Ayadn
|
|
423
365
|
begin
|
424
366
|
doing(options)
|
425
367
|
stream = @api.get_hashtag(hashtag)
|
426
|
-
|
368
|
+
stop_if_no_data(stream, 'hashtag')
|
427
369
|
if options[:extract]
|
428
370
|
view_all_hashtag_links(stream, hashtag)
|
429
371
|
else
|
430
372
|
render_view(stream, options)
|
431
373
|
end
|
432
374
|
rescue => e
|
433
|
-
Errors.global_error(
|
434
|
-
ensure
|
435
|
-
Databases.close_all
|
375
|
+
Errors.global_error({error: e, caller: caller, data: [hashtag, options]})
|
436
376
|
end
|
437
377
|
end
|
438
378
|
|
@@ -456,7 +396,7 @@ module Ayadn
|
|
456
396
|
splitted = splitter_all words
|
457
397
|
@api.get_search splitted.join(','), options
|
458
398
|
end
|
459
|
-
|
399
|
+
stop_if_no_data(stream, 'search')
|
460
400
|
if options[:users]
|
461
401
|
stream['data'].sort_by! {|obj| obj['counts']['followers']}
|
462
402
|
stream['data'].each do |obj|
|
@@ -473,208 +413,152 @@ module Ayadn
|
|
473
413
|
end
|
474
414
|
end
|
475
415
|
rescue => e
|
476
|
-
Errors.global_error(
|
477
|
-
ensure
|
478
|
-
Databases.close_all
|
416
|
+
Errors.global_error({error: e, caller: caller, data: [words, options]})
|
479
417
|
end
|
480
418
|
end
|
481
419
|
|
482
420
|
def followings(username, options)
|
483
421
|
begin
|
484
|
-
|
485
|
-
username =
|
422
|
+
stop_if_no_username(username)
|
423
|
+
username = add_arobase(username)
|
486
424
|
doing(options)
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
else
|
494
|
-
@view.show_raw(@api.get_raw_list(username, :followings))
|
495
|
-
end
|
425
|
+
option_show_raw(@api.get_raw_list(username, :followings), options)
|
426
|
+
list = @api.get_followings(username)
|
427
|
+
auto_save_followings(list)
|
428
|
+
no_data('followings') if list.empty?
|
429
|
+
get_list(:followings, list, username)
|
430
|
+
Databases.add_to_users_db_from_list(list)
|
496
431
|
rescue => e
|
497
|
-
Errors.global_error(
|
498
|
-
ensure
|
499
|
-
Databases.close_all
|
432
|
+
Errors.global_error({error: e, caller: caller, data: [username, options]})
|
500
433
|
end
|
501
434
|
end
|
502
435
|
|
503
436
|
def followers(username, options)
|
504
437
|
begin
|
505
|
-
|
506
|
-
username =
|
438
|
+
stop_if_no_username(username)
|
439
|
+
username = add_arobase(username)
|
507
440
|
doing(options)
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
else
|
515
|
-
@view.show_raw(@api.get_raw_list(username, :followers))
|
516
|
-
end
|
441
|
+
option_show_raw(@api.get_raw_list(username, :followers), options)
|
442
|
+
list = @api.get_followers(username)
|
443
|
+
auto_save_followers(list)
|
444
|
+
no_data('followers') if list.empty?
|
445
|
+
get_list(:followers, list, username)
|
446
|
+
Databases.add_to_users_db_from_list(list)
|
517
447
|
rescue => e
|
518
|
-
Errors.global_error(
|
519
|
-
ensure
|
520
|
-
Databases.close_all
|
448
|
+
Errors.global_error({error: e, caller: caller, data: [username, options]})
|
521
449
|
end
|
522
450
|
end
|
523
451
|
|
524
452
|
def muted(options)
|
525
453
|
begin
|
526
454
|
doing(options)
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
else
|
534
|
-
@view.show_raw(@api.get_raw_list(nil, :muted))
|
535
|
-
end
|
455
|
+
option_show_raw(@api.get_raw_list(nil, :muted), options)
|
456
|
+
list = @api.get_muted
|
457
|
+
auto_save_muted(list)
|
458
|
+
no_data('muted') if list.empty?
|
459
|
+
get_list(:muted, list, nil)
|
460
|
+
Databases.add_to_users_db_from_list(list)
|
536
461
|
rescue => e
|
537
|
-
Errors.global_error(
|
538
|
-
ensure
|
539
|
-
Databases.close_all
|
462
|
+
Errors.global_error({error: e, caller: caller, data: [options]})
|
540
463
|
end
|
541
464
|
end
|
542
465
|
|
543
466
|
def blocked(options)
|
544
467
|
begin
|
545
468
|
doing(options)
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
else
|
552
|
-
@view.show_raw(@api.get_raw_list(nil, :blocked))
|
553
|
-
end
|
469
|
+
option_show_raw(@api.get_raw_list(nil, :blocked), options)
|
470
|
+
list = @api.get_blocked
|
471
|
+
no_data('blocked') if list.empty?
|
472
|
+
get_list(:blocked, list, nil)
|
473
|
+
Databases.add_to_users_db_from_list(list)
|
554
474
|
rescue => e
|
555
|
-
Errors.global_error(
|
556
|
-
ensure
|
557
|
-
Databases.close_all
|
475
|
+
Errors.global_error({error: e, caller: caller, data: [options]})
|
558
476
|
end
|
559
477
|
end
|
560
478
|
|
561
479
|
def view_settings(options)
|
562
480
|
begin
|
563
|
-
|
564
|
-
puts Settings.options.to_json
|
565
|
-
else
|
566
|
-
@view.clear_screen
|
567
|
-
@view.show_settings
|
568
|
-
end
|
481
|
+
options[:raw] ? (puts Settings.options.to_json) : @view.show_settings
|
569
482
|
rescue => e
|
570
|
-
Errors.global_error(
|
571
|
-
ensure
|
572
|
-
Databases.close_all
|
483
|
+
Errors.global_error({error: e, caller: caller, data: [options]})
|
573
484
|
end
|
574
485
|
end
|
575
486
|
|
576
487
|
def userinfo(username, options)
|
577
488
|
begin
|
578
|
-
|
579
|
-
username =
|
489
|
+
stop_if_no_username(username)
|
490
|
+
username = add_arobase(username)
|
580
491
|
doing(options)
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
get_infos(stream['data'], token['data'])
|
587
|
-
else
|
588
|
-
get_infos(stream['data'], nil)
|
589
|
-
end
|
590
|
-
else
|
591
|
-
@view.show_raw(@api.get_user(username))
|
592
|
-
end
|
492
|
+
option_show_raw(@api.get_user(username), options)
|
493
|
+
stream = @api.get_user(username)
|
494
|
+
stop_if_no_user(stream, username)
|
495
|
+
same_username?(stream) ? token = @api.get_token_info['data'] : token = nil
|
496
|
+
get_infos(stream['data'], token)
|
593
497
|
rescue => e
|
594
|
-
Errors.global_error(
|
595
|
-
ensure
|
596
|
-
Databases.close_all
|
498
|
+
Errors.global_error({error: e, caller: caller, data: [username, options]})
|
597
499
|
end
|
598
500
|
end
|
599
501
|
|
600
502
|
def postinfo(post_id, options)
|
601
503
|
begin
|
602
|
-
|
504
|
+
stop_if_bad_post_id(post_id)
|
603
505
|
doing(options)
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
puts "
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
puts "AUTHOR:\n".inverse
|
623
|
-
if response['data']['username'] == Settings.config[:identity][:username]
|
624
|
-
@view.show_userinfos(stream, token['data'])
|
625
|
-
else
|
626
|
-
@view.show_userinfos(stream, nil)
|
627
|
-
end
|
506
|
+
option_show_raw(@api.get_details(post_id, options), options)
|
507
|
+
@view.clear_screen
|
508
|
+
response = @api.get_details(post_id, options)
|
509
|
+
stop_if_no_post(response, post_id)
|
510
|
+
resp = response['data']
|
511
|
+
response = @api.get_user("@#{resp['user']['username']}")
|
512
|
+
stop_if_no_user(response, response['data']['username'])
|
513
|
+
stream = response['data']
|
514
|
+
puts "POST:\n".inverse
|
515
|
+
@view.show_simple_post([resp], options)
|
516
|
+
if resp['repost_of']
|
517
|
+
puts "REPOST OF:\n".inverse
|
518
|
+
Errors.repost(post_id, resp['repost_of']['id'])
|
519
|
+
@view.show_simple_post([resp['repost_of']], options)
|
520
|
+
end
|
521
|
+
puts "AUTHOR:\n".inverse
|
522
|
+
if response['data']['username'] == Settings.config[:identity][:username]
|
523
|
+
@view.show_userinfos(stream, @api.get_token_info['data'])
|
628
524
|
else
|
629
|
-
@view.
|
525
|
+
@view.show_userinfos(stream, nil)
|
630
526
|
end
|
631
527
|
rescue => e
|
632
|
-
Errors.global_error(
|
633
|
-
ensure
|
634
|
-
Databases.close_all
|
528
|
+
Errors.global_error({error: e, caller: caller, data: [post_id, options]})
|
635
529
|
end
|
636
530
|
end
|
637
531
|
|
638
532
|
def files(options)
|
639
533
|
begin
|
640
534
|
doing(options)
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
else
|
646
|
-
@view.show_raw(@api.get_files_list(options))
|
647
|
-
end
|
535
|
+
option_show_raw(@api.get_files_list(options), options)
|
536
|
+
list = @api.get_files_list(options)
|
537
|
+
@view.clear_screen
|
538
|
+
list.empty? ? no_data('files') : @view.show_files_list(list)
|
648
539
|
rescue => e
|
649
|
-
Errors.global_error(
|
650
|
-
ensure
|
651
|
-
Databases.close_all
|
540
|
+
Errors.global_error({error: e, caller: caller, data: [options]})
|
652
541
|
end
|
653
542
|
end
|
654
543
|
|
655
544
|
def download(file_id)
|
656
545
|
begin
|
657
|
-
|
658
|
-
file = resp['data']
|
546
|
+
file = @api.get_file(file_id)['data']
|
659
547
|
FileOps.download_url(file['name'], file['url'])
|
660
548
|
puts Status.downloaded(file['name'])
|
661
549
|
rescue => e
|
662
|
-
Errors.global_error(
|
663
|
-
ensure
|
664
|
-
Databases.close_all
|
550
|
+
Errors.global_error({error: e, caller: caller, data: [file_id, file['url']]})
|
665
551
|
end
|
666
552
|
end
|
667
553
|
|
668
554
|
def channels
|
669
555
|
begin
|
670
|
-
doing
|
556
|
+
doing()
|
671
557
|
resp = @api.get_channels
|
672
558
|
@view.clear_screen
|
673
559
|
@view.show_channels(resp)
|
674
560
|
rescue => e
|
675
|
-
Errors.global_error(
|
676
|
-
ensure
|
677
|
-
Databases.close_all
|
561
|
+
Errors.global_error({error: e, caller: caller, data: [resp['meta']]})
|
678
562
|
end
|
679
563
|
end
|
680
564
|
|
@@ -683,19 +567,14 @@ module Ayadn
|
|
683
567
|
channel_id = get_channel_id_from_alias(channel_id)
|
684
568
|
doing(options)
|
685
569
|
resp = @api.get_messages(channel_id, options)
|
686
|
-
(
|
570
|
+
stop_if_no_new_posts(resp, options, "channel:#{channel_id}")
|
687
571
|
Databases.save_max_id(resp)
|
688
|
-
|
689
|
-
|
690
|
-
exit
|
691
|
-
end
|
692
|
-
no_data('messages') if resp['data'].empty?
|
572
|
+
option_show_raw(resp, options)
|
573
|
+
stop_if_no_data(resp, 'messages')
|
693
574
|
render_view(resp, options)
|
694
575
|
Scroll.new(@api, @view).messages(channel_id, options) if options[:scroll]
|
695
576
|
rescue => e
|
696
|
-
Errors.global_error(
|
697
|
-
ensure
|
698
|
-
Databases.close_all
|
577
|
+
Errors.global_error({error: e, caller: caller, data: [channel_id, options]})
|
699
578
|
end
|
700
579
|
end
|
701
580
|
|
@@ -703,14 +582,13 @@ module Ayadn
|
|
703
582
|
require 'pinboard'
|
704
583
|
require 'base64'
|
705
584
|
begin
|
706
|
-
|
707
|
-
doing
|
708
|
-
resp = get_data_from_response(@api.get_details(post_id
|
585
|
+
stop_if_bad_post_id(post_id)
|
586
|
+
doing()
|
587
|
+
resp = get_data_from_response(@api.get_details(post_id))
|
709
588
|
@view.clear_screen
|
710
589
|
links = Workers.new.extract_links(resp)
|
711
590
|
resp['text'].nil? ? text = "" : text = resp['text']
|
712
591
|
usertags << "ADN"
|
713
|
-
post_url = resp['canonical_url']
|
714
592
|
handle = "@" + resp['user']['username']
|
715
593
|
post_text = "From: #{handle} -- Text: #{text} -- Links: #{links.join(" ")}"
|
716
594
|
pinner = Ayadn::PinBoard.new
|
@@ -721,14 +599,12 @@ module Ayadn
|
|
721
599
|
end
|
722
600
|
credentials = pinner.load_credentials
|
723
601
|
maker = Struct.new(:username, :password, :url, :tags, :text, :description)
|
724
|
-
bookmark = maker.new(credentials[0], credentials[1],
|
602
|
+
bookmark = maker.new(credentials[0], credentials[1], resp['canonical_url'], usertags.join(","), post_text, links[0])
|
725
603
|
puts Status.saving_pin
|
726
604
|
pinner.pin(bookmark)
|
727
605
|
puts Status.done
|
728
606
|
rescue => e
|
729
|
-
Errors.global_error(
|
730
|
-
ensure
|
731
|
-
Databases.close_all
|
607
|
+
Errors.global_error({error: e, caller: caller, data: [post_id, usertags]})
|
732
608
|
end
|
733
609
|
end
|
734
610
|
|
@@ -736,20 +612,9 @@ module Ayadn
|
|
736
612
|
begin
|
737
613
|
@view.clear_screen
|
738
614
|
puts Status.auto
|
739
|
-
|
740
|
-
# platform = Settings.config[:platform]
|
741
|
-
# case platform
|
742
|
-
# when /mswin|mingw|cygwin/
|
743
|
-
# poster.auto_classic
|
744
|
-
# else
|
745
|
-
require "readline"
|
746
|
-
poster.auto_readline
|
747
|
-
# end
|
615
|
+
Post.new.auto_readline
|
748
616
|
rescue => e
|
749
|
-
|
750
|
-
Errors.global_error("action/auto post", [options], e)
|
751
|
-
ensure
|
752
|
-
Databases.close_all
|
617
|
+
Errors.global_error({error: e, caller: caller, data: [options]})
|
753
618
|
end
|
754
619
|
end
|
755
620
|
|
@@ -758,8 +623,16 @@ module Ayadn
|
|
758
623
|
writer = Post.new
|
759
624
|
@view.clear_screen
|
760
625
|
if options['embed']
|
761
|
-
|
762
|
-
|
626
|
+
if options['embed'].length > 1 # if args are inversed on the cl
|
627
|
+
opts = options['embed'].dup
|
628
|
+
embed = [opts.shift]
|
629
|
+
text = opts.join(" ")
|
630
|
+
else
|
631
|
+
embed = options['embed']
|
632
|
+
text = args.join(" ")
|
633
|
+
end
|
634
|
+
puts Status.uploading(embed)
|
635
|
+
resp = writer.send_embedded(text, FileOps.make_paths(embed))
|
763
636
|
else
|
764
637
|
puts Status.posting
|
765
638
|
resp = writer.post(args)
|
@@ -769,9 +642,7 @@ module Ayadn
|
|
769
642
|
puts Status.yourpost
|
770
643
|
@view.show_posted(resp)
|
771
644
|
rescue => e
|
772
|
-
Errors.global_error(
|
773
|
-
ensure
|
774
|
-
Databases.close_all
|
645
|
+
Errors.global_error({error: e, caller: caller, data: [args, options]})
|
775
646
|
end
|
776
647
|
end
|
777
648
|
|
@@ -798,18 +669,15 @@ module Ayadn
|
|
798
669
|
puts Status.yourpost
|
799
670
|
@view.show_posted(resp)
|
800
671
|
rescue => e
|
801
|
-
Errors.global_error(
|
802
|
-
ensure
|
803
|
-
Databases.close_all
|
672
|
+
Errors.global_error({error: e, caller: caller, data: [text, options]})
|
804
673
|
end
|
805
674
|
end
|
806
675
|
|
807
676
|
def pmess(username, options = {})
|
808
677
|
begin
|
809
678
|
files = FileOps.make_paths(options['embed']) if options['embed']
|
810
|
-
|
811
|
-
|
812
|
-
username = [temp]
|
679
|
+
stop_if_no_username(username)
|
680
|
+
username = [add_arobase(username)]
|
813
681
|
messenger = Post.new
|
814
682
|
puts Status.message_from(username)
|
815
683
|
puts Status.message
|
@@ -829,7 +697,7 @@ module Ayadn
|
|
829
697
|
puts Status.yourmessage
|
830
698
|
@view.show_posted(resp)
|
831
699
|
rescue => e
|
832
|
-
Errors.global_error(
|
700
|
+
Errors.global_error({error: e, caller: caller, data: [username, options]})
|
833
701
|
ensure
|
834
702
|
Databases.close_all
|
835
703
|
end
|
@@ -851,7 +719,7 @@ module Ayadn
|
|
851
719
|
puts Status.yourpost
|
852
720
|
@view.show_posted(resp)
|
853
721
|
rescue => e
|
854
|
-
Errors.global_error(
|
722
|
+
Errors.global_error({error: e, caller: caller, data: [channel_id]})
|
855
723
|
ensure
|
856
724
|
Databases.close_all
|
857
725
|
end
|
@@ -863,12 +731,12 @@ module Ayadn
|
|
863
731
|
post_id = get_real_post_id(post_id)
|
864
732
|
puts Status.replying_to(post_id)
|
865
733
|
replied_to = @api.get_details(post_id)
|
866
|
-
|
734
|
+
stop_if_no_post(replied_to, post_id)
|
867
735
|
post_id = get_original_id(post_id, replied_to)
|
868
736
|
if replied_to['data']['repost_of']
|
869
737
|
if post_id == replied_to['data']['repost_of']['id']
|
870
738
|
replied_to = @api.get_details(post_id)
|
871
|
-
|
739
|
+
stop_if_no_post(replied_to, post_id)
|
872
740
|
end
|
873
741
|
end
|
874
742
|
poster = Post.new
|
@@ -888,56 +756,14 @@ module Ayadn
|
|
888
756
|
FileOps.save_post(resp) if Settings.options[:backup][:auto_save_sent_posts]
|
889
757
|
@view.clear_screen
|
890
758
|
puts Status.done
|
891
|
-
render_view(@api.get_convo(post_id
|
759
|
+
render_view(@api.get_convo(post_id))
|
892
760
|
rescue => e
|
893
|
-
Errors.global_error(
|
894
|
-
ensure
|
895
|
-
Databases.close_all
|
761
|
+
Errors.global_error({error: e, caller: caller, data: [post_id, options]})
|
896
762
|
end
|
897
763
|
end
|
898
764
|
|
899
765
|
def nowplaying(options = {})
|
900
|
-
|
901
|
-
Databases.close_all
|
902
|
-
abort(Status.error_only_osx) unless Settings.config[:platform] =~ /darwin/
|
903
|
-
itunes = get_track_infos()
|
904
|
-
itunes.each {|el| abort(Status.empty_fields) if el.length == 0}
|
905
|
-
@view.clear_screen
|
906
|
-
unless options['no_url']
|
907
|
-
store = itunes_request(itunes)
|
908
|
-
end
|
909
|
-
text_to_post = "#nowplaying\n \nTitle: ‘#{itunes.track}’\nArtist: #{itunes.artist}\nfrom ‘#{itunes.album}’"
|
910
|
-
puts Status.writing
|
911
|
-
show_nowplaying("\n#{text_to_post}", options, store)
|
912
|
-
text_to_post += "\n \n[> Listen](#{store['preview']})" unless options['no_url']
|
913
|
-
unless STDIN.getch == ("y" || "Y")
|
914
|
-
puts "\nCanceled.\n\n".color(:red)
|
915
|
-
exit
|
916
|
-
end
|
917
|
-
puts "\n"
|
918
|
-
puts Status.yourpost
|
919
|
-
if options['no_url'].nil?
|
920
|
-
visible, track, artwork = true, store['track'], store['artwork']
|
921
|
-
else
|
922
|
-
visible, track, artwork = false, false, false
|
923
|
-
end
|
924
|
-
dic = {
|
925
|
-
'text' => text_to_post,
|
926
|
-
'title' => track,
|
927
|
-
'artwork' => artwork,
|
928
|
-
'width' => 1200,
|
929
|
-
'height' => 1200,
|
930
|
-
'visible' => visible
|
931
|
-
}
|
932
|
-
@view.show_posted(Post.new.send_nowplaying(dic))
|
933
|
-
rescue => e
|
934
|
-
puts Status.wtf
|
935
|
-
if options['no_url']
|
936
|
-
Errors.global_error("action/nowplaying", itunes, e)
|
937
|
-
else
|
938
|
-
Errors.global_error("action/nowplaying", [itunes, store, options], e)
|
939
|
-
end
|
940
|
-
end
|
766
|
+
options['lastfm'] ? np_lastfm(options) : np_itunes(options)
|
941
767
|
end
|
942
768
|
|
943
769
|
def random_posts(options)
|
@@ -967,27 +793,146 @@ module Ayadn
|
|
967
793
|
end
|
968
794
|
end
|
969
795
|
rescue => e
|
970
|
-
Errors.global_error(
|
971
|
-
ensure
|
972
|
-
Databases.close_all
|
796
|
+
Errors.global_error({error: e, caller: caller, data: [@max_id, @random_post_id, @resp, options]})
|
973
797
|
end
|
974
798
|
end
|
975
799
|
|
976
800
|
private
|
977
801
|
|
978
|
-
def
|
802
|
+
def np_lastfm options
|
803
|
+
require 'rss'
|
804
|
+
begin
|
805
|
+
if Settings.options[:nowplaying]
|
806
|
+
if Settings.options[:nowplaying][:lastfm]
|
807
|
+
user = Settings.options[:nowplaying][:lastfm]
|
808
|
+
else
|
809
|
+
user = create_lastfm_user()
|
810
|
+
end
|
811
|
+
else
|
812
|
+
Settings.options[:nowplaying] = {}
|
813
|
+
user = create_lastfm_user()
|
814
|
+
end
|
815
|
+
puts Status.fetching_from('Last.fm')
|
816
|
+
artist, track = get_lastfm_track_infos(user)
|
817
|
+
puts Status.itunes_store
|
818
|
+
store = lastfm_istore_request(artist, track) unless options['no_url']
|
819
|
+
text_to_post = "#nowplaying\n \nTitle: ‘#{track}’\nArtist: #{artist}"
|
820
|
+
post_nowplaying(text_to_post, store, options)
|
821
|
+
rescue => e
|
822
|
+
puts Status.wtf
|
823
|
+
Errors.global_error({error: e, caller: caller, data: [lfm, store, options]})
|
824
|
+
end
|
825
|
+
end
|
826
|
+
|
827
|
+
def get_lastfm_track_infos user
|
828
|
+
begin
|
829
|
+
url = "http://ws.audioscrobbler.com/2.0/user/#{user}/recenttracks.rss"
|
830
|
+
feed = RSS::Parser.parse(CNX.download(url))
|
831
|
+
lfm = feed.items[0].title.split(' – ')
|
832
|
+
return lfm[0], lfm[1]
|
833
|
+
rescue Interrupt
|
834
|
+
abort(Status.canceled)
|
835
|
+
end
|
836
|
+
end
|
837
|
+
|
838
|
+
def np_itunes options
|
839
|
+
begin
|
840
|
+
abort(Status.error_only_osx) unless Settings.config[:platform] =~ /darwin/
|
841
|
+
puts Status.fetching_from('iTunes')
|
842
|
+
itunes = get_itunes_track_infos()
|
843
|
+
itunes.each {|el| abort(Status.empty_fields) if el.length == 0}
|
844
|
+
puts Status.itunes_store
|
845
|
+
store = itunes_istore_request(itunes) unless options['no_url']
|
846
|
+
text_to_post = "#nowplaying\n \nTitle: ‘#{itunes.track}’\nArtist: #{itunes.artist}\nfrom ‘#{itunes.album}’"
|
847
|
+
post_nowplaying(text_to_post, store, options)
|
848
|
+
rescue => e
|
849
|
+
puts Status.wtf
|
850
|
+
Errors.global_error({error: e, caller: caller, data: [itunes, store, options]})
|
851
|
+
end
|
852
|
+
end
|
853
|
+
|
854
|
+
def post_nowplaying text_to_post, store, options
|
855
|
+
begin
|
856
|
+
@view.clear_screen
|
857
|
+
puts Status.writing
|
858
|
+
show_nowplaying("\n#{text_to_post}", options, store)
|
859
|
+
unless options['no_url'] || store['code'] != 200
|
860
|
+
#text_to_post += "\n \n[> Listen](#{store['preview']})"
|
861
|
+
text_to_post += "\n \n[iTunes Store](#{store['link']})"
|
862
|
+
end
|
863
|
+
abort(Status.canceled) unless STDIN.getch == ("y" || "Y")
|
864
|
+
puts "\n#{Status.yourpost}"
|
865
|
+
unless options['no_url'] || store['code'] != 200
|
866
|
+
visible, track, artwork, artwork_thumb = true, store['track'], store['artwork'], store['artwork_thumb']
|
867
|
+
else
|
868
|
+
visible, track, artwork, artwork_thumb = false
|
869
|
+
end
|
870
|
+
dic = {
|
871
|
+
'text' => text_to_post,
|
872
|
+
'title' => track,
|
873
|
+
'artwork' => artwork,
|
874
|
+
'artwork_thumb' => artwork_thumb,
|
875
|
+
'width' => 1200,
|
876
|
+
'height' => 1200,
|
877
|
+
'width_thumb' => 200,
|
878
|
+
'height_thumb' => 200,
|
879
|
+
'visible' => visible
|
880
|
+
}
|
881
|
+
@view.show_posted(Post.new.send_nowplaying(dic))
|
882
|
+
rescue => e
|
883
|
+
puts Status.wtf
|
884
|
+
Errors.global_error({error: e, caller: caller, data: [dic, store, options]})
|
885
|
+
end
|
886
|
+
end
|
887
|
+
|
888
|
+
def ask_lastfm_user
|
889
|
+
puts "\nPlease enter your Last.fm username:\n".color(:cyan)
|
890
|
+
begin
|
891
|
+
STDIN.gets.chomp!
|
892
|
+
rescue Interrupt
|
893
|
+
abort(Status.canceled)
|
894
|
+
end
|
895
|
+
end
|
896
|
+
|
897
|
+
def create_lastfm_user
|
898
|
+
Settings.options[:nowplaying][:lastfm] = ask_lastfm_user()
|
899
|
+
Settings.save_config
|
900
|
+
return Settings.options[:nowplaying][:lastfm]
|
901
|
+
end
|
902
|
+
|
903
|
+
def itunes_istore_request itunes
|
979
904
|
infos = itunes_reg([itunes.artist, itunes.track, itunes.album])
|
980
905
|
itunes_url = "https://itunes.apple.com/search?term=#{infos[0]}&term=#{infos[1]}&term=#{infos[2]}&media=music&entity=musicTrack"
|
981
|
-
|
982
|
-
|
983
|
-
|
984
|
-
|
985
|
-
|
986
|
-
|
987
|
-
|
988
|
-
|
989
|
-
|
990
|
-
|
906
|
+
get_itunes_store(itunes_url)
|
907
|
+
end
|
908
|
+
|
909
|
+
def lastfm_istore_request artist, track
|
910
|
+
infos = itunes_reg([artist, track])
|
911
|
+
itunes_url = "https://itunes.apple.com/search?term=#{infos[0]}&term=#{infos[1]}&media=music&entity=musicTrack"
|
912
|
+
get_itunes_store(itunes_url)
|
913
|
+
end
|
914
|
+
|
915
|
+
def get_itunes_store url
|
916
|
+
results = JSON.load(CNX.download(url))['results']
|
917
|
+
unless results.empty? || results.nil?
|
918
|
+
candidate = results[0]
|
919
|
+
return {
|
920
|
+
'code' => 200,
|
921
|
+
'artist' => candidate['artistName'],
|
922
|
+
'track' => candidate['trackName'],
|
923
|
+
'preview' => candidate['previewUrl'],
|
924
|
+
'link' => candidate['collectionViewUrl'],
|
925
|
+
'artwork' => candidate['artworkUrl100'].gsub('100x100', '1200x1200'),
|
926
|
+
'artwork_thumb' => candidate['artworkUrl100'].gsub('100x100', '600x600'),
|
927
|
+
'request' => url,
|
928
|
+
'results' => results
|
929
|
+
}
|
930
|
+
else
|
931
|
+
return {
|
932
|
+
'code' => 404,
|
933
|
+
'request' => url
|
934
|
+
}
|
935
|
+
end
|
991
936
|
end
|
992
937
|
|
993
938
|
def itunes_reg arr_of_itunes
|
@@ -997,6 +942,73 @@ module Ayadn
|
|
997
942
|
end
|
998
943
|
end
|
999
944
|
|
945
|
+
def get_itunes_track_infos
|
946
|
+
track = `osascript -e 'tell application "iTunes"' -e 'set trackName to name of current track' -e 'return trackName' -e 'end tell'`
|
947
|
+
if track.empty?
|
948
|
+
puts Status.no_itunes
|
949
|
+
Errors.warn "Nowplaying canceled: unable to get info from iTunes."
|
950
|
+
exit
|
951
|
+
end
|
952
|
+
album = `osascript -e 'tell application "iTunes"' -e 'set trackAlbum to album of current track' -e 'return trackAlbum' -e 'end tell'`
|
953
|
+
artist = `osascript -e 'tell application "iTunes"' -e 'set trackArtist to artist of current track' -e 'return trackArtist' -e 'end tell'`
|
954
|
+
maker = Struct.new(:artist, :album, :track)
|
955
|
+
maker.new(artist.chomp!, album.chomp!, track.chomp!)
|
956
|
+
end
|
957
|
+
|
958
|
+
def show_nowplaying(text, options, store)
|
959
|
+
puts "\nYour post:\n".color(:cyan)
|
960
|
+
if options['no_url'] || store['code'] != 200
|
961
|
+
puts text + "\n\n\n"
|
962
|
+
else
|
963
|
+
puts text + "\n\n\nThe iTunes Store thinks this track is: ".color(:green) + "'#{store['track']}'".color(:magenta) + " by ".color(:green) + "'#{store['artist']}'".color(:magenta) + ".\n\nAyadn will use these elements to insert album artwork and a link to the track.\n\n".color(:green)
|
964
|
+
end
|
965
|
+
puts "Do you confirm? (y/N) ".color(:yellow)
|
966
|
+
end
|
967
|
+
|
968
|
+
def nicerank_true
|
969
|
+
if Settings.options[:nicerank]
|
970
|
+
if Settings.options[:nicerank][:filter] == true
|
971
|
+
return true
|
972
|
+
end
|
973
|
+
end
|
974
|
+
end
|
975
|
+
|
976
|
+
def option_show_raw stream, options
|
977
|
+
if options[:raw]
|
978
|
+
@view.show_raw(stream)
|
979
|
+
exit
|
980
|
+
end
|
981
|
+
end
|
982
|
+
|
983
|
+
def stop_if_bad_post_id post_id
|
984
|
+
missing_post_id() unless post_id.is_integer?
|
985
|
+
end
|
986
|
+
|
987
|
+
def stop_if_no_data stream, target
|
988
|
+
if stream['data'].empty?
|
989
|
+
Errors.warn "In action/#{target}: no data"
|
990
|
+
abort(Status.empty_list)
|
991
|
+
end
|
992
|
+
end
|
993
|
+
|
994
|
+
def stop_if_404 stream, post_id
|
995
|
+
if stream['meta']['code'] == 404
|
996
|
+
abort(Status.post_404(post_id))
|
997
|
+
end
|
998
|
+
end
|
999
|
+
|
1000
|
+
def add_arobase username
|
1001
|
+
Workers.add_arobase_if_missing(username)
|
1002
|
+
end
|
1003
|
+
|
1004
|
+
def stop_if_no_new_posts stream, options, title
|
1005
|
+
if options[:new]
|
1006
|
+
unless Databases.has_new?(stream, title)
|
1007
|
+
no_new_posts()
|
1008
|
+
end
|
1009
|
+
end
|
1010
|
+
end
|
1011
|
+
|
1000
1012
|
def splitter_all words
|
1001
1013
|
[words].collect {|w| w.split(' ')}
|
1002
1014
|
end
|
@@ -1144,31 +1156,31 @@ module Ayadn
|
|
1144
1156
|
abort(Status.empty_list)
|
1145
1157
|
end
|
1146
1158
|
|
1147
|
-
def
|
1148
|
-
stream['meta']['code'] == 404
|
1149
|
-
|
1150
|
-
|
1151
|
-
|
1152
|
-
|
1153
|
-
Errors.info("User #{username} doesn't exist")
|
1154
|
-
exit
|
1159
|
+
def stop_if_no_user stream, username
|
1160
|
+
if stream['meta']['code'] == 404
|
1161
|
+
puts Status.user_404(username)
|
1162
|
+
Errors.info("User #{username} doesn't exist")
|
1163
|
+
exit
|
1164
|
+
end
|
1155
1165
|
end
|
1156
1166
|
|
1157
|
-
def
|
1158
|
-
|
1159
|
-
|
1160
|
-
|
1167
|
+
def stop_if_no_post stream, post_id
|
1168
|
+
if stream['meta']['code'] == 404
|
1169
|
+
puts Status.post_404(post_id)
|
1170
|
+
Errors.info("Impossible to find #{post_id}")
|
1171
|
+
exit
|
1172
|
+
end
|
1161
1173
|
end
|
1162
1174
|
|
1163
1175
|
def length_of_index
|
1164
1176
|
Databases.get_index_length
|
1165
1177
|
end
|
1166
1178
|
|
1167
|
-
def get_post_from_index
|
1168
|
-
Databases.get_post_from_index
|
1179
|
+
def get_post_from_index id
|
1180
|
+
Databases.get_post_from_index id
|
1169
1181
|
end
|
1170
1182
|
|
1171
|
-
def get_real_post_id
|
1183
|
+
def get_real_post_id post_id
|
1172
1184
|
id = post_id.to_i
|
1173
1185
|
if id > 0 && id <= length_of_index
|
1174
1186
|
resp = get_post_from_index(id)
|
@@ -1177,11 +1189,11 @@ module Ayadn
|
|
1177
1189
|
post_id
|
1178
1190
|
end
|
1179
1191
|
|
1180
|
-
def render_view(
|
1192
|
+
def render_view(stream, options = {}, niceranks = {})
|
1181
1193
|
unless options[:raw]
|
1182
|
-
get_view(
|
1194
|
+
get_view(stream['data'], options, niceranks)
|
1183
1195
|
else
|
1184
|
-
@view.show_raw(
|
1196
|
+
@view.show_raw(stream)
|
1185
1197
|
end
|
1186
1198
|
end
|
1187
1199
|
|
@@ -1256,9 +1268,11 @@ module Ayadn
|
|
1256
1268
|
exit
|
1257
1269
|
end
|
1258
1270
|
|
1259
|
-
def
|
1260
|
-
|
1261
|
-
|
1271
|
+
def stop_if_no_username username
|
1272
|
+
if username.empty?
|
1273
|
+
puts Status.error_missing_username
|
1274
|
+
exit
|
1275
|
+
end
|
1262
1276
|
end
|
1263
1277
|
|
1264
1278
|
def missing_post_id
|
@@ -1285,29 +1299,6 @@ module Ayadn
|
|
1285
1299
|
stream['data']['username'] == Settings.config[:identity][:username]
|
1286
1300
|
end
|
1287
1301
|
|
1288
|
-
def get_track_infos
|
1289
|
-
track = `osascript -e 'tell application "iTunes"' -e 'set trackName to name of current track' -e 'return trackName' -e 'end tell'`
|
1290
|
-
if track.empty?
|
1291
|
-
puts Status.no_itunes
|
1292
|
-
Errors.warn "Nowplaying canceled: unable to get info from iTunes."
|
1293
|
-
exit
|
1294
|
-
end
|
1295
|
-
album = `osascript -e 'tell application "iTunes"' -e 'set trackAlbum to album of current track' -e 'return trackAlbum' -e 'end tell'`
|
1296
|
-
artist = `osascript -e 'tell application "iTunes"' -e 'set trackArtist to artist of current track' -e 'return trackArtist' -e 'end tell'`
|
1297
|
-
maker = Struct.new(:artist, :album, :track)
|
1298
|
-
maker.new(artist.chomp!, album.chomp!, track.chomp!)
|
1299
|
-
end
|
1300
|
-
|
1301
|
-
def show_nowplaying(text, options, store)
|
1302
|
-
puts "\nYour post:\n".color(:cyan)
|
1303
|
-
if options['no_url']
|
1304
|
-
puts text + "\n\n\n"
|
1305
|
-
else
|
1306
|
-
puts text + "\n\nAlbum artwork + 30 sec preview for track '#{store['track']}' by '#{store['artist']}' will be inserted in the post.\n\n\n".color(:green)
|
1307
|
-
end
|
1308
|
-
puts "Do you confirm? (y/N) ".color(:yellow)
|
1309
|
-
end
|
1310
|
-
|
1311
1302
|
def countdown(wait)
|
1312
1303
|
wait.downto(1) do |i|
|
1313
1304
|
print "\r#{sprintf("%02d", i)} sec... QUIT WITH [CTRL+C]".color(:cyan)
|