ayadn 1.5.1 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/ayadn/alias.rb CHANGED
@@ -11,7 +11,7 @@ module Ayadn
11
11
  unless args.empty?
12
12
  channel, channel_alias = args[0], args[1]
13
13
  else
14
- Action.quit Status.wrong_arguments
14
+ abort(Status.wrong_arguments)
15
15
  end
16
16
  if channel.is_integer?
17
17
  Databases.create_alias(channel, channel_alias)
@@ -38,7 +38,7 @@ module Ayadn
38
38
  Logs.rec.info "Deleted alias '#{args[0]}'."
39
39
  puts Status.done
40
40
  else
41
- Action.quit Status.wrong_arguments
41
+ abort(Status.wrong_arguments)
42
42
  end
43
43
  rescue => e
44
44
  Errors.global_error({error: e, caller: caller, data: [args]})
@@ -55,7 +55,7 @@ module Ayadn
55
55
  unless database.nil?
56
56
  new_db = File.realpath(database)
57
57
  else
58
- Action.quit Status.wrong_arguments
58
+ abort(Status.wrong_arguments)
59
59
  end
60
60
  if File.exist?(new_db)
61
61
  Databases.import_aliases(new_db)
data/lib/ayadn/api.rb CHANGED
@@ -2,6 +2,10 @@
2
2
  module Ayadn
3
3
  class API
4
4
 
5
+ def initialize
6
+ @workers = Workers.new
7
+ end
8
+
5
9
  def get_unified(options)
6
10
  options = paginate options, 'unified'
7
11
  get_parsed_response(Endpoints.new.unified(options))
@@ -282,7 +286,7 @@ module Ayadn
282
286
  loop do
283
287
  resp = get_parsed_response(get_list_url(username, target, options))
284
288
  abort(Status.user_404(username)) if resp['meta']['code'] == 404
285
- users = Workers.extract_users(resp)
289
+ users = @workers.extract_users(resp)
286
290
  big_hash.merge!(users)
287
291
  break if resp['meta']['min_id'] == nil
288
292
  options = {:count => 200, :before_id => resp['meta']['min_id']}
data/lib/ayadn/app.rb CHANGED
@@ -3,7 +3,7 @@ module Ayadn
3
3
  class App < Thor
4
4
  package_name "Ayadn"
5
5
 
6
- %w{action api descriptions endpoints cnx view workers settings post status extend databases fileops logs pinboard set alias errors blacklist scroll authorize switch mark nicerank debug}.each { |r| require_relative "#{r}" }
6
+ %w{action stream api search descriptions endpoints cnx view workers settings post status extend databases fileops logs pinboard set alias errors blacklist scroll authorize switch mark nicerank debug check nowplaying nowwatching tvshow}.each { |r| require_relative "#{r}" }
7
7
 
8
8
  ##
9
9
  # These methods are intended to be called from the CLI.
@@ -242,7 +242,7 @@ module Ayadn
242
242
  desc "delete POST", "Delete a post (-D)"
243
243
  map "-D" => :delete
244
244
  long_desc Descriptions.delete
245
- def delete(post_id)
245
+ def delete(*post_id)
246
246
  Action.new.delete(post_id)
247
247
  end
248
248
 
@@ -419,7 +419,7 @@ module Ayadn
419
419
  long_desc Descriptions.blacklist
420
420
  subcommand "blacklist", Blacklist
421
421
 
422
- desc "nowplaying", "Post the current iTunes track (-np)"
422
+ desc "nowplaying", "Post the current playing track from iTunes or Last.fm (-np)"
423
423
  map "-np" => :nowplaying
424
424
  long_desc Descriptions.nowplaying
425
425
  option :no_url, aliases: "-n", type: :boolean, desc: "Don't append preview or album art at the end of the post"
@@ -428,6 +428,25 @@ module Ayadn
428
428
  Action.new.nowplaying(options)
429
429
  end
430
430
 
431
+ desc "movie TITLE", "Create a post from a movie title (-NW)"
432
+ map "nowwatching" => :movie
433
+ map "imdb" => :movie
434
+ map "-NW" => :movie
435
+ long_desc Descriptions.nowwatching
436
+ option :alt, aliases: "-a", type: :boolean, desc: "Select an alternative response if the first didn't match"
437
+ def movie(*title)
438
+ Action.new.nowwatching(title, options)
439
+ end
440
+
441
+ desc "tvshow TITLE", "Create a post from a TV show title (-TV)"
442
+ map "-TV" => :tvshow
443
+ long_desc Descriptions.tvshow
444
+ option :alt, aliases: "-a", type: :boolean, desc: "Select an alternative response if the first didn't match"
445
+ option :banner, aliases: "-b", type: :boolean, desc: "Inserts the show banner instead of the show poster"
446
+ def tvshow(*title)
447
+ Action.new.tvshow(title, options)
448
+ end
449
+
431
450
  desc "random", "Show random posts from App.net (-rnd)"
432
451
  map "-rnd" => :random
433
452
  option :wait, aliases: "-w", type: :numeric, desc: "In seconds, time to wait before next page"
@@ -5,7 +5,7 @@ module Ayadn
5
5
  map "create" => :add
6
6
  long_desc Descriptions.blacklist_add
7
7
  def add(*args)
8
- Action.quit(Status.type_and_target_missing) if args.length < 2
8
+ abort(Status.type_and_target_missing) if args.length < 2
9
9
  BlacklistWorkers.new.add(args)
10
10
  puts Status.done
11
11
  end
@@ -14,7 +14,7 @@ module Ayadn
14
14
  map "delete" => :remove
15
15
  long_desc Descriptions.blacklist_remove
16
16
  def remove(*args)
17
- Action.quit(Status.type_and_target_missing) if args.length < 2
17
+ abort(Status.type_and_target_missing) if args.length < 2
18
18
  BlacklistWorkers.new.remove(args)
19
19
  puts Status.done
20
20
  end
@@ -54,6 +54,7 @@ module Ayadn
54
54
  Settings.init_config
55
55
  Logs.create_logger
56
56
  Databases.open_databases
57
+ @workers = Workers.new
57
58
  end
58
59
  def import(database)
59
60
  begin
@@ -95,11 +96,11 @@ module Ayadn
95
96
  type = args.shift
96
97
  case type
97
98
  when 'user', 'username', 'account'
98
- target = Workers.add_arobases_to_usernames args
99
+ target = @workers.add_arobases_to_usernames args
99
100
  Databases.add_user_to_blacklist(target)
100
101
  Logs.rec.info "Added '#{target}' to blacklist of users."
101
102
  when 'mention', 'mentions'
102
- target = Workers.add_arobases_to_usernames args
103
+ target = @workers.add_arobases_to_usernames args
103
104
  Databases.add_mention_to_blacklist(target)
104
105
  Logs.rec.info "Added '#{target}' to blacklist of mentions."
105
106
  when 'client', 'source'
@@ -120,12 +121,12 @@ module Ayadn
120
121
  type = args.shift
121
122
  case type
122
123
  when 'user', 'username', 'account'
123
- temp = Workers.add_arobases_to_usernames args
124
+ temp = @workers.add_arobases_to_usernames args
124
125
  target = temp.map {|u| "-#{u}"}
125
126
  Databases.remove_from_blacklist(target)
126
127
  Logs.rec.info "Removed '#{target}' from blacklist of users."
127
128
  when 'mention', 'mentions'
128
- target = Workers.add_arobases_to_usernames args
129
+ target = @workers.add_arobases_to_usernames args
129
130
  Databases.remove_from_blacklist(target)
130
131
  Logs.rec.info "Removed '#{target}' from blacklist of mentions."
131
132
  when 'client', 'source', 'hashtag', 'tag'
@@ -0,0 +1,187 @@
1
+ # encoding: utf-8
2
+ module Ayadn
3
+
4
+ class Check
5
+
6
+ def self.same_username(stream)
7
+ stream['data']['username'] == Settings.config[:identity][:username]
8
+ end
9
+
10
+ def self.auto_save_muted(list)
11
+ FileOps.save_muted_list(list) if Settings.options[:backup][:auto_save_lists]
12
+ end
13
+
14
+ def self.auto_save_followers(list)
15
+ FileOps.save_followers_list(list) if Settings.options[:backup][:auto_save_lists]
16
+ end
17
+
18
+ def self.auto_save_followings(list)
19
+ FileOps.save_followings_list(list) if Settings.options[:backup][:auto_save_lists]
20
+ end
21
+
22
+ def self.no_username username
23
+ abort(Status.error_missing_username) if username.empty?
24
+ end
25
+
26
+ def self.no_data stream, target
27
+ if stream['data'].empty?
28
+ Errors.warn "In action/#{target}: no data"
29
+ abort(Status.empty_list)
30
+ end
31
+ end
32
+
33
+ def self.no_new_posts stream, options, title
34
+ if options[:new]
35
+ unless Databases.has_new?(stream, title)
36
+ abort(Status.no_new_posts)
37
+ end
38
+ end
39
+ end
40
+
41
+ def self.no_post stream, post_id
42
+ if stream['meta']['code'] == 404
43
+ puts Status.post_404(post_id)
44
+ Errors.info("Impossible to find #{post_id}")
45
+ exit
46
+ end
47
+ end
48
+
49
+ def self.bad_post_id post_id
50
+ abort(Status.error_missing_post_id) unless post_id.is_integer?
51
+ end
52
+
53
+ def self.no_user stream, username
54
+ if stream['meta']['code'] == 404
55
+ puts Status.user_404(username)
56
+ Errors.info("User #{username} doesn't exist")
57
+ exit
58
+ end
59
+ end
60
+
61
+ def self.has_been_unfollowed(username, resp)
62
+ if resp['meta']['code'] == 200
63
+ puts Status.unfollowed(username)
64
+ Logs.rec.info "Unfollowed #{username}."
65
+ else
66
+ Errors.whine(Status.not_unfollowed(username), resp)
67
+ end
68
+ end
69
+
70
+ def self.has_been_unmuted(username, resp)
71
+ if resp['meta']['code'] == 200
72
+ puts Status.unmuted(username)
73
+ Logs.rec.info "Unmuted #{username}."
74
+ else
75
+ Errors.whine(Status.not_unmuted(username), resp)
76
+ end
77
+ end
78
+
79
+ def self.already_starred(resp)
80
+ if resp['data']['you_starred']
81
+ puts "\nYou already starred this post.\n".color(:red)
82
+ exit
83
+ end
84
+ end
85
+
86
+ def self.already_reposted(resp)
87
+ if resp['data']['you_reposted']
88
+ puts "\nYou already reposted this post.\n".color(:red)
89
+ exit
90
+ end
91
+ end
92
+
93
+ def self.has_been_starred(post_id, resp)
94
+ if resp['meta']['code'] == 200
95
+ puts Status.starred(post_id)
96
+ Logs.rec.info "Starred #{post_id}."
97
+ else
98
+ Errors.whine(Status.not_starred(post_id), resp)
99
+ end
100
+ end
101
+
102
+ def self.has_been_reposted(post_id, resp)
103
+ if resp['meta']['code'] == 200
104
+ puts Status.reposted(post_id)
105
+ Logs.rec.info "Reposted #{post_id}."
106
+ else
107
+ Errors.whine(Status.not_reposted(post_id), resp)
108
+ end
109
+ end
110
+
111
+ def self.has_been_blocked(username, resp)
112
+ if resp['meta']['code'] == 200
113
+ puts Status.blocked(username)
114
+ Logs.rec.info "Blocked #{username}."
115
+ else
116
+ Errors.whine(Status.not_blocked(username), resp)
117
+ end
118
+ end
119
+
120
+ def self.has_been_muted(username, resp)
121
+ if resp['meta']['code'] == 200
122
+ puts Status.muted(username)
123
+ Logs.rec.info "Muted #{username}."
124
+ else
125
+ Errors.whine(Status.not_muted(username), resp)
126
+ end
127
+ end
128
+
129
+ def self.has_been_followed(username, resp)
130
+ if resp['meta']['code'] == 200
131
+ puts Status.followed(username)
132
+ Logs.rec.info "Followed #{username}."
133
+ else
134
+ Errors.whine(Status.not_followed(username), resp)
135
+ end
136
+ end
137
+
138
+ def self.has_been_deleted(post_id, resp)
139
+ if resp['meta']['code'] == 200
140
+ puts Status.deleted(post_id)
141
+ Logs.rec.info "Deleted post #{post_id}."
142
+ else
143
+ Errors.whine(Status.not_deleted(post_id), resp)
144
+ end
145
+ end
146
+
147
+ def self.message_has_been_deleted(message_id, resp)
148
+ if resp['meta']['code'] == 200
149
+ puts Status.deleted_m(message_id)
150
+ Logs.rec.info "Deleted message #{message_id}."
151
+ else
152
+ Errors.whine(Status.not_deleted(message_id), resp)
153
+ end
154
+ end
155
+
156
+ def self.has_been_unblocked(username, resp)
157
+ if resp['meta']['code'] == 200
158
+ puts Status.unblocked(username)
159
+ Logs.rec.info "Unblocked #{username}."
160
+ else
161
+ Errors.whine(Status.not_unblocked(username), resp)
162
+ end
163
+ end
164
+
165
+ def self.has_been_unstarred(post_id, resp)
166
+ if resp['meta']['code'] == 200
167
+ puts Status.unstarred(post_id)
168
+ Logs.rec.info "Unstarred #{post_id}."
169
+ else
170
+ Errors.whine(Status.not_unstarred(post_id), resp)
171
+ end
172
+ end
173
+
174
+ def self.has_been_unreposted(post_id, resp)
175
+ if resp['meta']['code'] == 200
176
+ puts Status.unreposted(post_id)
177
+ Logs.rec.info "Unreposted #{post_id}."
178
+ else
179
+ Errors.whine(Status.not_unreposted(post_id), resp)
180
+ end
181
+ end
182
+
183
+
184
+
185
+ end
186
+
187
+ end
@@ -1128,6 +1128,92 @@ module Ayadn
1128
1128
  \n\n
1129
1129
  USAGE
1130
1130
  end
1131
+ def self.nowwatching
1132
+ <<-USAGE
1133
+ Create a post from (part of) a movie title. Includes movie poster and IMDb url.
1134
+
1135
+ Usage:
1136
+
1137
+ ayadn movie ghost in the shell
1138
+
1139
+ ayadn movie existenz
1140
+
1141
+ ayadn -NW beetlejuice
1142
+
1143
+ (shortcut is 'NW' because of 'nowwatching')
1144
+
1145
+ If the movie is not the one you're looking for, you can specify the 'alt' option to force find an alternative.
1146
+
1147
+ This is useful for remakes:
1148
+
1149
+ ayadn -NW solaris
1150
+
1151
+ (gives the 2002 version)
1152
+
1153
+ ayadn -NW solaris --alt
1154
+
1155
+ (gives the 1972 version)
1156
+
1157
+ Aliases:
1158
+
1159
+ ayadn nowwatching godfather II
1160
+
1161
+ ayadn imdb -a conan
1162
+
1163
+ Hashtag:
1164
+
1165
+ You can modify the hashtag with 'set':
1166
+
1167
+ ayadn set movie hashtag movietime
1168
+
1169
+ ayadn set movie hashtag adnmovieclub
1170
+
1171
+ (default is 'nowwatching')
1172
+ \n\n
1173
+ USAGE
1174
+ end
1175
+ def self.tvshow
1176
+ <<-USAGE
1177
+ Create a post from (part of) a TV show title. Includes show poster and IMDb url.
1178
+
1179
+ Usage:
1180
+
1181
+ ayadn tvshow magnum
1182
+
1183
+ ayadn tvshow game of thrones
1184
+
1185
+ ayadn -TV 24
1186
+
1187
+ If the show is not the one you're looking for, you can specify the 'alt' option to force find an alternative.
1188
+
1189
+ ayadn -TV whose line
1190
+
1191
+ (gives the US version)
1192
+
1193
+ ayadn -TV whose line --alt
1194
+
1195
+ (gives the UK version)
1196
+
1197
+ Hashtag:
1198
+
1199
+ You can modify the hashtag with 'set':
1200
+
1201
+ ayadn set tvshow hashtag showtime
1202
+
1203
+ ayadn set tvshow hashtag tvshow
1204
+
1205
+ (default is 'nowwatching')
1206
+
1207
+ Banner:
1208
+
1209
+ Use the `--banner` (-b) options to insert a banner instead of a poster:
1210
+
1211
+ ayadn -TV magnum --banner
1212
+
1213
+ ayadn -TV -b magnum
1214
+ \n\n
1215
+ USAGE
1216
+ end
1131
1217
  def self.random_posts
1132
1218
  <<-USAGE
1133
1219
  Show random posts from App.net.
data/lib/ayadn/errors.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
  module Ayadn
3
3
  class Errors
4
+
4
5
  def self.global_error(args)
5
6
  Logs.rec.error "--BEGIN--"
6
7
  Logs.rec.error "CAUSE: #{args[:error]}"
@@ -18,20 +19,36 @@ module Ayadn
18
19
  Debug.err(args[:error], stack)
19
20
  exit
20
21
  end
22
+
21
23
  def self.error(status)
22
24
  Logs.rec.error status
23
25
  end
26
+
24
27
  def self.warn(warning)
25
28
  Logs.rec.warn warning
26
29
  end
30
+
27
31
  def self.info(msg)
28
32
  Logs.rec.info msg
29
33
  end
34
+
30
35
  def self.repost(repost, original)
31
36
  Logs.rec.info "Post #{repost} is a repost. Using original: #{original}."
32
37
  end
38
+
33
39
  def self.nr msg
34
40
  Logs.nr.warn msg
35
41
  end
42
+
43
+ def self.whine(status, resp)
44
+ puts status
45
+ self.error("#{status} => #{resp['meta']}")
46
+ end
47
+
48
+ def self.no_data(where)
49
+ self.warn "In action/#{where}: no data"
50
+ abort(Status.empty_list)
51
+ end
52
+
36
53
  end
37
54
  end