lib/ayadn/stream.rb in ayadn-2.0.9 vs lib/ayadn/stream.rb in ayadn-2.0.10

- old
+ new

@@ -112,27 +112,48 @@ end def whatstarred(username, options) @check.no_username(username) username = @workers.add_arobase(username) - @view.downloading(options) - stream = @api.get_whatstarred(username, options) + @view.downloading(options) unless options["again"] + + if options["again"] + stream = FileOps.cached_list("whatstarred") + Errors.no_data('cached whatstarred') if stream.nil? + else + stream = @api.get_whatstarred(username, options) + end + @check.no_user(stream, username) @check.no_data(stream, 'whatstarred') - options[:extract] ? @view.all_stars_links(stream) : @view.render(stream, options) + + if options["cache"] && options["again"].nil? + FileOps.cache_list(stream, "whatstarred") + end + + if options[:extract] + @view.all_stars_links(stream) + else + @view.render(stream, options) + end puts "\n" if Settings.options[:timeline][:compact] == true end def followings(username, options) @check.no_username(username) username = @workers.add_arobase(username) - @view.downloading(options) + @view.downloading(options) unless options["again"] show_raw_list(username, :followings, options) - list = @api.get_followings(username) + if options["again"] + list = FileOps.cached_list("followings") + Errors.no_data('cached followings') if list.nil? + else + list = @api.get_followings(username) + end @check.auto_save_followings(list) Errors.no_data('followings') if list.empty? - if options["lastpost"] + if options["lastpost"] && options["again"].nil? count = list.size @workers.thor.say_status :downloading, "please wait, it may take a while...", :red puts "\n" idx = 0 list.each do |str_id,obj| @@ -143,40 +164,75 @@ @workers.thor.say_status iter.to_sym, "last post from #{colored_username}", :cyan resp = @api.get_posts(tmp_username, {count: 1}) obj << resp["data"][0] end end + if options["cache"] && options["again"].nil? + FileOps.cache_list(list, "followings") + end @view.list(:followings, list, username, options) Databases.add_to_users_db_from_list(list) end def followers(username, options) @check.no_username(username) username = @workers.add_arobase(username) - @view.downloading(options) + @view.downloading(options) unless options["again"] show_raw_list(username, :followers, options) - list = @api.get_followers(username) + + if options["again"] + list = FileOps.cached_list("followers") + Errors.no_data('cached followers') if list.nil? + else + list = @api.get_followers(username) + end + @check.auto_save_followers(list) + + if options["cache"] && options["again"].nil? + FileOps.cache_list(list, "followers") + end + Errors.no_data('followers') if list.empty? @view.list(:followers, list, username, options) Databases.add_to_users_db_from_list(list) end def muted(options) - @view.downloading(options) + @view.downloading(options) unless options["again"] show_raw_list(nil, :muted, options) - list = @api.get_muted + + if options["again"] + list = FileOps.cached_list("muted") + Errors.no_data('cached muted') if list.nil? + else + list = @api.get_muted + end + @check.auto_save_muted(list) + + if options["cache"] && options["again"].nil? + FileOps.cache_list(list, "muted") + end + Errors.no_data('muted') if list.empty? @view.list(:muted, list, nil, options) Databases.add_to_users_db_from_list(list) end def blocked(options) - @view.downloading(options) + @view.downloading(options) unless options["again"] show_raw_list(nil, :blocked, options) - list = @api.get_blocked + if options["again"] + list = FileOps.cached_list("blocked") + Errors.no_data('cached blocked') if list.nil? + else + list = @api.get_blocked + end + if options["cache"] && options["again"].nil? + FileOps.cache_list(list, "blocked") + end Errors.no_data('blocked') if list.empty? @view.list(:blocked, list, nil, options) Databases.add_to_users_db_from_list(list) end @@ -192,15 +248,37 @@ def whoreposted(post_id, options) @check.bad_post_id(post_id) unless options[:force] post_id = @workers.get_real_post_id(post_id) end - @view.downloading(options) - details = @api.get_details(post_id, options) + @view.downloading(options) unless options["again"] + + if options["again"] + details = FileOps.cached_list("whoreposted_details") + Errors.no_data('cached whoreposted details') if details.nil? + else + details = @api.get_details(post_id, options) + end + @check.no_post(details, post_id) id = @workers.get_original_id(post_id, details) - list = @api.get_whoreposted(id) + + if options["cache"] && options["again"].nil? + FileOps.cache_list(details, "whoreposted_details") + end + + if options["again"] + list = FileOps.cached_list("whoreposted") + Errors.no_data('cached whoreposted') if list.nil? + else + list = @api.get_whoreposted(id) + end + + if options["cache"] && options["again"].nil? + FileOps.cache_list(list, "whoreposted") + end + @view.if_raw(list, options) if list['data'].empty? @status.nobody_reposted exit end @@ -210,15 +288,37 @@ def whostarred(post_id, options) @check.bad_post_id(post_id) unless options[:force] post_id = @workers.get_real_post_id(post_id) end - @view.downloading(options) - details = @api.get_details(post_id, options) + @view.downloading(options) unless options["again"] + + if options["again"] + details = FileOps.cached_list("whostarred_details") + Errors.no_data('cached whostarred details') if details.nil? + else + details = @api.get_details(post_id, options) + end + @check.no_post(details, post_id) id = @workers.get_original_id(post_id, details) - list = @api.get_whostarred(id) + + if options["cache"] && options["again"].nil? + FileOps.cache_list(details, "whostarred_details") + end + + if options["again"] + list = FileOps.cached_list("whostarred") + Errors.no_data('cached whostarred') if list.nil? + else + list = @api.get_whostarred(id) + end + + if options["cache"] && options["again"].nil? + FileOps.cache_list(list, "whostarred") + end + @view.if_raw(list, options) if list['data'].empty? @status.nobody_starred exit end @@ -308,10 +408,22 @@ private def show_raw_list username, what, options if options[:raw] - @view.show_raw(@api.get_raw_list(username, what), options) + + if options["again"] + list = FileOps.cached_list("#{username}_#{what}") + Errors.no_data("#{username}_#{what}") if list.nil? + else + list = @api.get_raw_list(username, what) + end + + if options["cache"] && options["again"].nil? + FileOps.cache_list(list, "#{username}_#{what}") + end + + @view.show_raw(list, options) exit end end def nicerank_true