Improve CLI sync and output
This commit is contained in:
parent
aa0eaaa40a
commit
22b7208bdd
3 changed files with 29 additions and 2 deletions
|
|
@ -9,13 +9,18 @@ class FicTracker::Cli < Thor
|
|||
|
||||
desc 'sync', 'Update all tracked stories'
|
||||
method_option :render, type: :boolean, aliases: :r, desc: 'Render updated stories'
|
||||
method_option :cron, type: :boolean, desc: 'Limit simultaenous actions, to reduce load when running as a cron job'
|
||||
def sync
|
||||
setup!
|
||||
should_render = options[:render].nil? ? FicTracker::Config.dig(:cli, :render, default: false) : options[:render]
|
||||
prepare_render! if should_render
|
||||
|
||||
puts "Updating#{ should_render ? ' and rendering' : ''} stories."
|
||||
FicTracker::Models::Story.needing_content_refresh.each do |story|
|
||||
to_update = FicTracker::Models::Story.needing_content_refresh
|
||||
to_update = to_update.to_a.sample 10 if options[:cron]
|
||||
to_update.each do |story|
|
||||
next unless story.needs_content_refresh? || story.needs_metadata_refresh?
|
||||
|
||||
puts " Updating #{story} ..."
|
||||
before = story.etag
|
||||
story.ensure_fully_loaded
|
||||
|
|
|
|||
0
lib/fic_tracker/cli/archive.rb
Normal file
0
lib/fic_tracker/cli/archive.rb
Normal file
|
|
@ -35,6 +35,28 @@ class FicTracker::Cli::Story < Thor
|
|||
end
|
||||
end
|
||||
|
||||
desc 'download STORY...', 'Download stories without adding them to the tracker'
|
||||
def download(*stories)
|
||||
setup!
|
||||
|
||||
stories.each do |story|
|
||||
puts "Downloading #{story} ..."
|
||||
bend = FicTracker::Backends.find_backend story
|
||||
if bend.nil?
|
||||
puts " Can't download, no available backends."
|
||||
next
|
||||
end
|
||||
|
||||
bend = FicTracker::Backends.get(bend)
|
||||
slug = story
|
||||
slug = bend.parse_slug(story) if bend.respond_to? :parse_slug
|
||||
|
||||
story = FicTracker::Models::Story.new(backend: bend, slug:)
|
||||
story.ensure_fully_loaded
|
||||
render_story! story
|
||||
end
|
||||
end
|
||||
|
||||
desc 'del STORY...', 'Remove stories from tracker'
|
||||
def del(*stories)
|
||||
setup!
|
||||
|
|
@ -71,7 +93,7 @@ class FicTracker::Cli::Story < Thor
|
|||
setup!
|
||||
info = [['Slug', 'Story', 'Chapters', 'Completed', 'Last Updated'], ['----','-----','--------','---------','------------']]
|
||||
FicTracker::Models::Story.order_by(:name).each do |story|
|
||||
info << [story.slug, story.name, story.chapters.size, story.completed?, (story.updated_at || story.published_at).strftime("%F")]
|
||||
info << ["#{story.backend_name}/#{story.slug}", story.name, story.chapters.size, story.completed?, (story.updated_at || story.published_at).strftime("%F")]
|
||||
end
|
||||
print_table info
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue