ayadn 1.6.0 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
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 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}" }
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 annotations}.each { |r| require_relative "#{r}" }
7
7
 
8
8
  ##
9
9
  # These methods are intended to be called from the CLI.
@@ -17,6 +17,7 @@ module Ayadn
17
17
  option :count, aliases: "-c", type: :numeric, desc: Descriptions.options_count
18
18
  option :index, aliases: "-i", type: :boolean, desc: Descriptions.options_index
19
19
  option :raw, aliases: "-x", type: :boolean, desc: Descriptions.options_raw
20
+ option :force, aliases: "-f", type: :boolean, desc: Descriptions.options_force
20
21
  def timeline
21
22
  Action.new.unified(options)
22
23
  end
@@ -29,6 +30,7 @@ module Ayadn
29
30
  option :count, aliases: "-c", type: :numeric, desc: Descriptions.options_count
30
31
  option :index, aliases: "-i", type: :boolean, desc: Descriptions.options_index
31
32
  option :raw, aliases: "-x", type: :boolean, desc: Descriptions.options_raw
33
+ option :force, aliases: "-f", type: :boolean, desc: Descriptions.options_force
32
34
  def checkins
33
35
  Action.new.checkins(options)
34
36
  end
@@ -41,6 +43,7 @@ module Ayadn
41
43
  option :count, aliases: "-c", type: :numeric, desc: Descriptions.options_count
42
44
  option :index, aliases: "-i", type: :boolean, desc: Descriptions.options_index
43
45
  option :raw, aliases: "-x", type: :boolean, desc: Descriptions.options_raw
46
+ option :force, aliases: "-f", type: :boolean, desc: Descriptions.options_force
44
47
  def global
45
48
  Action.new.global(options)
46
49
  end
@@ -53,6 +56,7 @@ module Ayadn
53
56
  option :count, aliases: "-c", type: :numeric, desc: Descriptions.options_count
54
57
  option :index, aliases: "-i", type: :boolean, desc: Descriptions.options_index
55
58
  option :raw, aliases: "-x", type: :boolean, desc: Descriptions.options_raw
59
+ option :force, aliases: "-f", type: :boolean, desc: Descriptions.options_force
56
60
  def trending
57
61
  Action.new.trending(options)
58
62
  end
@@ -65,6 +69,7 @@ module Ayadn
65
69
  option :count, aliases: "-c", type: :numeric, desc: Descriptions.options_count
66
70
  option :index, aliases: "-i", type: :boolean, desc: Descriptions.options_index
67
71
  option :raw, aliases: "-x", type: :boolean, desc: Descriptions.options_raw
72
+ option :force, aliases: "-f", type: :boolean, desc: Descriptions.options_force
68
73
  def photos
69
74
  Action.new.photos(options)
70
75
  end
@@ -77,6 +82,7 @@ module Ayadn
77
82
  option :count, aliases: "-c", type: :numeric, desc: Descriptions.options_count
78
83
  option :index, aliases: "-i", type: :boolean, desc: Descriptions.options_index
79
84
  option :raw, aliases: "-x", type: :boolean, desc: Descriptions.options_raw
85
+ option :force, aliases: "-f", type: :boolean, desc: Descriptions.options_force
80
86
  def conversations
81
87
  Action.new.conversations(options)
82
88
  end
@@ -88,6 +94,7 @@ module Ayadn
88
94
  option :count, aliases: "-c", type: :numeric, desc: Descriptions.options_count
89
95
  option :index, aliases: "-i", type: :boolean, desc: Descriptions.options_index
90
96
  option :raw, aliases: "-x", type: :boolean, desc: Descriptions.options_raw
97
+ option :force, aliases: "-f", type: :boolean, desc: Descriptions.options_force
91
98
  def mentions(*username)
92
99
  Action.new.mentions(username, options)
93
100
  end
@@ -99,6 +106,7 @@ module Ayadn
99
106
  option :count, aliases: "-c", type: :numeric, desc: Descriptions.options_count
100
107
  option :index, aliases: "-i", type: :boolean, desc: Descriptions.options_index
101
108
  option :raw, aliases: "-x", type: :boolean, desc: Descriptions.options_raw
109
+ option :force, aliases: "-f", type: :boolean, desc: Descriptions.options_force
102
110
  def userposts(*username)
103
111
  Action.new.posts(username, options)
104
112
  end
@@ -144,6 +152,7 @@ module Ayadn
144
152
  option :scroll, aliases: "-s", type: :boolean, desc: "Scroll the stream"
145
153
  option :index, aliases: "-i", type: :boolean, desc: Descriptions.options_index
146
154
  option :raw, aliases: "-x", type: :boolean, desc: Descriptions.options_raw
155
+ option :force, aliases: "-f", type: :boolean, desc: Descriptions.options_force
147
156
  long_desc Descriptions.convo
148
157
  def convo(post_id)
149
158
  Action.new.convo(post_id, options)
@@ -186,6 +195,7 @@ module Ayadn
186
195
  long_desc Descriptions.hashtag
187
196
  option :raw, aliases: "-x", type: :boolean, desc: Descriptions.options_raw
188
197
  option :extract, aliases: "-e", type: :boolean, desc: Descriptions.options_extract
198
+ option :force, aliases: "-f", type: :boolean, desc: Descriptions.options_force
189
199
  def hashtag(hashtag)
190
200
  Action.new.hashtag(hashtag, options)
191
201
  end
@@ -197,6 +207,7 @@ module Ayadn
197
207
  option :index, aliases: "-i", type: :boolean, desc: Descriptions.options_index
198
208
  option :raw, aliases: "-x", type: :boolean, desc: Descriptions.options_raw
199
209
  option :extract, aliases: "-e", type: :boolean, desc: Descriptions.options_extract
210
+ option :force, aliases: "-f", type: :boolean, desc: Descriptions.options_force
200
211
  option :messages, type: :boolean, desc: 'Search for WORD(S) in messages, including PMs.'
201
212
  option :users, type: :boolean, desc: 'Search for App.net users by searching WORD(S) in their bio/description.'
202
213
  option :channels, type: :boolean, desc: 'Search for App.net channels by searching WORD(S) in their description.'
@@ -225,6 +236,7 @@ module Ayadn
225
236
  map "-pi" => :postinfo
226
237
  long_desc Descriptions.postinfo
227
238
  option :raw, aliases: "-x", type: :boolean, desc: Descriptions.options_raw
239
+ option :force, aliases: "-f", type: :boolean, desc: Descriptions.options_force
228
240
  def postinfo(post_id)
229
241
  Action.new.postinfo(post_id, options)
230
242
  end
@@ -350,7 +362,10 @@ module Ayadn
350
362
  desc "post Your text", "Simple post to App.net (-P)"
351
363
  map "-P" => :post
352
364
  long_desc Descriptions.post
353
- option :embed, aliases: "-e", type: :array, desc: "Embed one or several pictures in the new post"
365
+ option :embed, aliases: "-E", type: :array, desc: "Embed one or several pictures in the new post"
366
+ option :youtube, aliases: "-Y", type: :array, desc: "Embed a Youtube video in the new post"
367
+ option :vimeo, aliases: "-V", type: :array, desc: "Embed a Vimeo video in the new post"
368
+ option :poster, aliases: "-M", type: :array, desc: "Embed a movie poster, from title, in the new post"
354
369
  def post(*args)
355
370
  Action.new.post(args, options)
356
371
  end
@@ -359,14 +374,20 @@ module Ayadn
359
374
  map "compose" => :write
360
375
  map "-W" => :write
361
376
  long_desc Descriptions.write
362
- option :embed, aliases: "-e", type: :array, desc: "Embed one or several pictures in the new post"
377
+ option :embed, aliases: "-E", type: :array, desc: "Embed one or several pictures in the new post"
378
+ option :youtube, aliases: "-Y", type: :array, desc: "Embed a Youtube video in the new post"
379
+ option :vimeo, aliases: "-V", type: :array, desc: "Embed a Vimeo video in the new post"
380
+ option :poster, aliases: "-M", type: :array, desc: "Embed a movie poster, from title, in the new post"
363
381
  def write
364
382
  Action.new.write(options)
365
383
  end
366
384
 
367
385
  desc "pm @USERNAME", "Send a private message to @username"
368
386
  long_desc Descriptions.pmess
369
- option :embed, aliases: "-e", type: :array, desc: "Embed one or several pictures in the new post"
387
+ option :embed, aliases: "-E", type: :array, desc: "Embed one or several pictures in the new post"
388
+ option :youtube, aliases: "-Y", type: :array, desc: "Embed a Youtube video in the new post"
389
+ option :vimeo, aliases: "-V", type: :array, desc: "Embed a Vimeo video in the new post"
390
+ option :poster, aliases: "-M", type: :array, desc: "Embed a movie poster, from title, in the new post"
370
391
  def pm(*username)
371
392
  Action.new.pmess(username, options)
372
393
  end
@@ -381,7 +402,10 @@ module Ayadn
381
402
  desc "reply POST", "Reply to post n°POST (-R)"
382
403
  map "-R" => :reply
383
404
  long_desc Descriptions.reply
384
- option :embed, aliases: "-e", type: :array, desc: "Embed one or several pictures in the new post"
405
+ option :embed, aliases: "-E", type: :array, desc: "Embed one or several pictures in the new post"
406
+ option :youtube, aliases: "-Y", type: :array, desc: "Embed a Youtube video in the new post"
407
+ option :vimeo, aliases: "-V", type: :array, desc: "Embed a Vimeo video in the new post"
408
+ option :poster, aliases: "-M", type: :array, desc: "Embed a movie poster, from title, in the new post"
385
409
  def reply(id)
386
410
  ayadn = Action.new
387
411
  ayadn.reply(id, options)
@@ -77,8 +77,14 @@ module Ayadn
77
77
  @blacklist.clear
78
78
  dummy.each {|v,k| @blacklist[v] = k}
79
79
  end
80
- def self.save_max_id(stream)
81
- @pagination[stream['meta']['marker']['name']] = stream['meta']['max_id']
80
+
81
+ def self.save_max_id(stream, name = 'unknown')
82
+ if stream['meta']['marker'].nil?
83
+ key = name
84
+ else
85
+ key = stream['meta']['marker']['name']
86
+ end
87
+ @pagination[key] = stream['meta']['max_id']
82
88
  end
83
89
 
84
90
  def self.create_alias(channel_id, channel_alias)
data/lib/ayadn/debug.rb CHANGED
@@ -22,12 +22,12 @@ module Ayadn
22
22
 
23
23
  def self.db dbs
24
24
  if Settings.options[:timeline][:show_debug] == true
25
- puts "/////\nSETTINGS\n"
26
- jj JSON.parse((Settings.config).to_json)
27
- jj JSON.parse((Settings.options).to_json)
28
- Logs.rec.debug "SETTINGS/CONFIG: #{Settings.config}"
29
- Logs.rec.debug "SETTINGS/OPTIONS: #{Settings.options}"
30
- puts "/////\n\n"
25
+ # puts "/////\nSETTINGS\n"
26
+ # jj JSON.parse((Settings.config).to_json)
27
+ # jj JSON.parse((Settings.options).to_json)
28
+ # Logs.rec.debug "SETTINGS/CONFIG: #{Settings.config}"
29
+ # Logs.rec.debug "SETTINGS/OPTIONS: #{Settings.options}"
30
+ # puts "/////\n\n"
31
31
 
32
32
  #puts ">>>>>\nDATABASES\n"
33
33
  dbs.each do |db|
@@ -16,6 +16,9 @@ module Ayadn
16
16
  def self.options_extract
17
17
  "Extract links from each object"
18
18
  end
19
+ def self.options_force
20
+ "Force retrieve posts if the user is muted/blocked"
21
+ end
19
22
  def self.unified
20
23
  <<-USAGE
21
24
  Show your App.net timeline, aka the Unified Stream.
@@ -732,9 +735,25 @@ module Ayadn
732
735
 
733
736
  ayadn -P Watching a movie with friends
734
737
 
738
+ Embed a picture:
739
+
740
+ ayadn -P "lol cat" -E ~/Pics/lolcat.jpg
741
+
735
742
  You don't have to put quotes around your text, but it's better to do it.
736
743
 
737
744
  The 'write' method is recommended over this one: it's more secure and offers multi-line support.
745
+
746
+ Embed an online video:
747
+
748
+ ayadn -P wave function -Y https://www.youtube.com/watch?v=Ei8CFin00PY
749
+
750
+ ayadn -P wargarbl -V http://vimeo.com/123234345
751
+
752
+ Embed a movie poster:
753
+
754
+ ayadn -P "I'll be back" -M terminator
755
+
756
+ (This is different from the 'movie' command, check the docs.)
738
757
  \n\n
739
758
  USAGE
740
759
  end
@@ -748,7 +767,23 @@ module Ayadn
748
767
 
749
768
  ayadn -W
750
769
 
770
+ Embed a picture:
771
+
772
+ ayadn -W -E ~/Pics/lolcat.jpg
773
+
751
774
  It enters the writing mode where you will type your post.
775
+
776
+ Embed an online video:
777
+
778
+ ayadn -P wave function -Y https://www.youtube.com/watch?v=Ei8CFin00PY
779
+
780
+ ayadn -P wargarbl -V http://vimeo.com/123234345
781
+
782
+ Embed a movie poster:
783
+
784
+ ayadn -P "I'll be back" -M terminator
785
+
786
+ (This is different from the 'movie' command, check the docs.)
752
787
  \n\n
753
788
  USAGE
754
789
  end
@@ -760,6 +795,10 @@ module Ayadn
760
795
 
761
796
  ayadn pm @ericd
762
797
 
798
+ Embed a picture:
799
+
800
+ ayadn pm -E ~/Pics/lolcat.jpg
801
+
763
802
  It enters the writing mode where you will type your message.
764
803
  \n\n
765
804
  USAGE
@@ -796,9 +835,23 @@ module Ayadn
796
835
 
797
836
  If you reply to a repost, Ayadn will automatically replace it by the original post.
798
837
 
799
- If you just viewed a stream with the -i (--index) option, you can also reply to a post by its index.
838
+ If you just viewed a stream with the -i (--index) option, you can also reply to a post by its index (ex: ayadn -R 3).
839
+
840
+ Embed a picture in a reply:
841
+
842
+ ayadn -R 23365251 -E ~/Pics/lolcat.jpg
843
+
844
+ Embed an online video:
845
+
846
+ ayadn -P wave function -Y https://www.youtube.com/watch?v=Ei8CFin00PY
847
+
848
+ ayadn -P wargarbl -V http://vimeo.com/123234345
849
+
850
+ Embed a movie poster:
851
+
852
+ ayadn -P "I'll be back" -M terminator
800
853
 
801
- Example: ayadn -R 3
854
+ (This is different from the 'movie' command, check the docs.)
802
855
  \n\n
803
856
  USAGE
804
857
  end
@@ -56,7 +56,11 @@ module Ayadn
56
56
  else
57
57
  API.build_query({count: Settings.options[:counts][:global]})
58
58
  end
59
- "#{@posts_url}stream/global?access_token=#{Settings.user_token}#{@options_list}"
59
+ if Settings.options[:force]
60
+ "#{@posts_url}stream/global?#{@options_list}"
61
+ else
62
+ "#{@posts_url}stream/global?access_token=#{Settings.user_token}#{@options_list}"
63
+ end
60
64
  end
61
65
 
62
66
  def trending(options)
@@ -101,7 +105,11 @@ module Ayadn
101
105
  else
102
106
  API.build_query({count: Settings.options[:counts][:posts]})
103
107
  end
104
- "#{@users_url}#{username}/posts/?access_token=#{Settings.user_token}#{@options_list}"
108
+ if Settings.options[:force]
109
+ "#{@users_url}#{username}/posts/?#{@options_list}"
110
+ else
111
+ "#{@users_url}#{username}/posts/?access_token=#{Settings.user_token}#{@options_list}"
112
+ end
105
113
  end
106
114
 
107
115
  def whatstarred(username, options)
@@ -248,7 +256,7 @@ module Ayadn
248
256
  "#{@channels_url}?access_token=#{Settings.user_token}#{API.build_query(options)}"
249
257
  end
250
258
 
251
- def messages(channel_id, options)
259
+ def messages(channel_id, options = {})
252
260
  "#{@channels_url}#{channel_id}/messages?access_token=#{Settings.user_token}#{API.build_query(options)}&include_machine=1"
253
261
  end
254
262
 
data/lib/ayadn/logs.rb CHANGED
@@ -17,22 +17,5 @@ module Ayadn
17
17
  end
18
18
  end
19
19
 
20
- # unused (experiment)
21
- # def self.send_log(from, args, content)
22
- # begin
23
- # log = {
24
- # "platform" => "#{Settings.config[:platform]}",
25
- # "date" => Time.now,
26
- # "version" => "#{Settings.config[:version]}",
27
- # "source" => from,
28
- # "args" => args,
29
- # "content" => content
30
- # }
31
- # Post.new.send_log(log)
32
- # rescue
33
- # @rec.warn("Unable to send log.")
34
- # end
35
- # end
36
-
37
20
  end
38
21
  end
data/lib/ayadn/mark.rb CHANGED
@@ -9,12 +9,13 @@ module Ayadn
9
9
  begin
10
10
  init
11
11
  unless args.empty?
12
- post_id, convo_title = args[0], args[1]
12
+ double = args.dup
13
+ post_id, convo_title = double.shift, double.join(' ')
13
14
  else
14
15
  abort Status.wrong_arguments
15
16
  end
16
17
  abort Status.error_missing_post_id unless post_id.is_integer?
17
- convo_title = post_id if convo_title.nil?
18
+ convo_title = post_id if convo_title == ''
18
19
  api, workers, view = API.new, Workers.new, View.new
19
20
  users, bucket = [], []
20
21
  view.clear_screen
@@ -52,6 +53,8 @@ module Ayadn
52
53
  puts Status.done
53
54
  rescue => e
54
55
  Errors.global_error({error: e, caller: caller, data: [args]})
56
+ ensure
57
+ Databases.close_all
55
58
  end
56
59
  end
57
60
 
@@ -60,36 +60,37 @@ module Ayadn
60
60
  @view.clear_screen
61
61
  puts Status.writing
62
62
  show_nowplaying("\n#{text_to_post}", options, store)
63
- unless options['no_url'] || store.nil?
63
+ unless options[:no_url] || store.nil?
64
64
  text_to_post += "\n \n[iTunes Store](#{store['link']})"
65
65
  end
66
66
  abort(Status.canceled) unless STDIN.getch == ("y" || "Y")
67
67
  puts "\n#{Status.yourpost}"
68
- unless store.nil? || options['no_url']
68
+ unless store.nil? || options[:no_url]
69
69
  visible, track, artwork, artwork_thumb, link, artist = true, store['track'], store['artwork'], store['artwork_thumb'], store['link'], store['artist']
70
70
  else
71
71
  visible, track, artwork, artwork_thumb, link, artist = false
72
72
  end
73
- if options['lastfm']
73
+ if options[:lastfm]
74
74
  source = 'Last.fm'
75
75
  else
76
76
  source = 'iTunes'
77
77
  end
78
78
  dic = {
79
- 'text' => text_to_post,
80
- 'title' => track,
81
- 'artist' => artist,
82
- 'artwork' => artwork,
83
- 'artwork_thumb' => artwork_thumb,
84
- 'width' => 1200,
85
- 'height' => 1200,
86
- 'width_thumb' => 200,
87
- 'height_thumb' => 200,
88
- 'link' => link,
89
- 'source' => source,
90
- 'visible' => visible
79
+ options: options,
80
+ text: text_to_post,
81
+ title: track,
82
+ artist: artist,
83
+ artwork: artwork,
84
+ artwork_thumb: artwork_thumb,
85
+ width: 1200,
86
+ height: 1200,
87
+ width_thumb: 200,
88
+ height_thumb: 200,
89
+ link: link,
90
+ source: source,
91
+ visible: visible
91
92
  }
92
- @view.show_posted(Post.new.send_nowplaying(dic))
93
+ @view.show_posted(Post.new.post(dic))
93
94
  rescue => e
94
95
  puts Status.wtf
95
96
  Errors.global_error({error: e, caller: caller, data: [dic, store, options]})
@@ -5,29 +5,54 @@ module Ayadn
5
5
 
6
6
  require 'spotlite'
7
7
 
8
- def initialize view
8
+ def initialize view = nil
9
9
  @view = view
10
10
  @spotlite = Spotlite::Movie
11
11
  end
12
12
 
13
+ # -----
14
+
15
+ def get_response args, options
16
+ find_by_title(args, options)
17
+ end
18
+
19
+ def create_filename response
20
+ reg = /[~:-;,?!\'&`^=+<>*%()\/"“”’°£$€.…]/
21
+ "#{response.title.downcase.strip.gsub(reg, '_').split(' ').join('_')}.jpg"
22
+ end
23
+
24
+ # This is only for the `-M` option in the CLI
25
+ def get_poster args, options
26
+ options = options.dup
27
+ response = get_response(args, options)
28
+ filename = create_filename(response)
29
+ FileOps.download_url(filename, response.poster_url)
30
+ options[:embed] ||= []
31
+ options[:embed] << "#{Settings.config[:paths][:downloads]}/#{filename}"
32
+ return options
33
+ end
34
+
35
+ # -----
36
+
13
37
  def post args, options
38
+ options = options.dup
14
39
  puts "\nContacting IMDb.com...".color(:cyan)
15
40
  response = find_by_title(args, options)
16
41
  text = format_post(response)
17
42
  show_post(text)
18
- reg = /[~:-;,?!\'&`^=+<>*%()\/"“”’°£$€.…]/
19
- filename = "#{response.title.downcase.strip.gsub(reg, '_').split(' ').join('_')}.jpg"
43
+ filename = create_filename(response)
20
44
  FileOps.download_url(filename, response.poster_url)
21
45
  @view.clear_screen
22
46
  puts "\nPosting and uploading the movie poster...\n".color(:green)
23
- file = ["#{Settings.config[:paths][:downloads]}/#{filename}"]
47
+ options[:embed] = ["#{Settings.config[:paths][:downloads]}/#{filename}"]
48
+ options[:movie] = true
24
49
  dic = {
25
- 'text' => text,
26
- 'data' => FileOps.upload_files(file),
27
- 'title' => response.title,
28
- 'source' => 'IMDb'
50
+ options: options,
51
+ text: text,
52
+ title: response.title,
53
+ source: 'IMDb'
29
54
  }
30
- resp = Post.new.send_movie(dic)
55
+ resp = Post.new.post(dic)
31
56
  FileOps.save_post(resp) if Settings.options[:backup][:auto_save_sent_posts]
32
57
  @view.clear_screen
33
58
  puts Status.yourpost