organo 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 07f88d3bafa6f79b66260174f984f415229f6f449da715b010df238d201c1eab
4
- data.tar.gz: 77efeae28ceefe926c10be6e6789ca5158fc49e1c405ea88c37932a087c40a5b
3
+ metadata.gz: ce74a150b3bd7be118c17318edaf064c0a3a7e49b7a71775f347123279d7bfcb
4
+ data.tar.gz: 05d621c3fe3e5adefb79abd9bfe8f26a8ba4579967f914360ef56e40323f984f
5
5
  SHA512:
6
- metadata.gz: f9cfb0f392479f25a6713525966805c30fd455403e2079f479337050b8722c2f9c5ddd294cbfab4992e20a691b3f09ef3695715feefa6b3fd9efa857f5bcbd87
7
- data.tar.gz: 637433a7ad969aeaab7cace448cea1b1a2b74a60891c384c8ab8ed2f48b0c46ec4506b0c003352c68b168d33a004b13f5da874800883958b824488f2b2291c0a
6
+ metadata.gz: b369b8ba6b07283b6843614b17739fe6601760251d4abaa5f01ffdd54ddbccbe1adb0bdcd26c52a70165c19c33893d530a1580a94f122c7cbb74dfea77d8458b
7
+ data.tar.gz: ec68ad34f619d0e003f2d1910c1706ba643f837a3b09b3295822ebf811a8aecd82dc9b7563755e5e71287eb4a9e7d32fbc2ca9f143c27a24e5ddab78a0f7a113
@@ -9,8 +9,8 @@ module Organo
9
9
  module Add
10
10
 
11
11
  class AnimeEntry < Dry::CLI::Command
12
- desc "Add anime entry to files"
13
- argument :mal_id, type: :integer, required: true, desc: "MyAnimeList ID"
12
+ desc 'Add anime entry to files'
13
+ argument :mal_id, type: :integer, required: true, desc: 'MyAnimeList ID'
14
14
 
15
15
  def call(mal_id:, **)
16
16
  json_obj = Query.get_anime_by_id(mal_id)
@@ -19,7 +19,7 @@ module Organo
19
19
  file_name = (show_type == 'TV' ? "#{json_obj['year']}-#{json_obj['season']}" : show_type.downcase)
20
20
  file_path = "#{Config::DEFAULT_DIR}/#{file_name}.json"
21
21
  show_list = File.exist?(file_path) ? Reader.read_file(file_path) : Array.new
22
- if (show_list.find_index { |s| s.id.to_s == mal_id.to_s }.nil?)
22
+ if show_list.find_index { |s| s.id.to_s == mal_id.to_s }.nil?
23
23
  Writer.to_file(show_list.push(show).sort_by(&:title), file_path)
24
24
  puts "Added anime \"#{show.title}\" (#{mal_id})"
25
25
  else
@@ -23,13 +23,13 @@ module Organo
23
23
  show = shows_list.find { |s| s.id.to_s == anime_mal_id.to_s }
24
24
  next if show.nil?
25
25
 
26
- unless show.sequels.find { |s| s['id'].to_s == sequel_mal_id.to_s }
26
+ if show.sequels.find { |s| s['id'].to_s == sequel_mal_id.to_s }
27
+ puts 'Cannot add an already existing sequel.'
28
+ else
27
29
  sequel = Sequel.new(json_obj['mal_id'], json_obj['title'], json_obj['images']['jpg']['image_url'], season_num, type, type_num)
28
30
  show.sequels.push(sequel)
29
31
  Writer.to_file(shows_list, file_path)
30
32
  puts "Added sequel \"#{sequel.title}\" (#{sequel.id}) to anime."
31
- else
32
- puts 'Cannot add an already existing sequel.'
33
33
  end
34
34
  break
35
35
  end
@@ -8,11 +8,11 @@ module Organo
8
8
  module Get
9
9
 
10
10
  class BrokenLinks < Dry::CLI::Command
11
- desc "Get list of anime IDs that have broken links"
11
+ desc 'Get list of anime IDs that have broken links'
12
12
 
13
13
  def call(*)
14
14
  show_list = Reader.read_all_files
15
- broken_list = Array.new
15
+ broken_list = []
16
16
  show_list.each do |show|
17
17
  response = HTTParty.get(show.image_url)
18
18
  next unless response.code == 404
@@ -6,19 +6,19 @@ module Organo
6
6
  module Anime
7
7
 
8
8
  class Remove < Dry::CLI::Command
9
- desc "Remove anime entry from files"
10
- argument :mal_id, type: :integer, required: true, desc: "MyAnimeList ID"
9
+ desc 'Remove anime entry from files'
10
+ argument :mal_id, type: :integer, required: true, desc: 'MyAnimeList ID'
11
11
 
12
12
  def call(mal_id:, **)
13
13
  Dir["#{Config::DEFAULT_DIR}/*.json"].each do |file_path|
14
14
  shows_list = Reader.read_file(file_path)
15
15
  show_index = shows_list.find_index { |s| s.id.to_s == mal_id.to_s }
16
- if show_index >= 0
17
- show = shows_list.delete_at(show_index)
18
- Writer.to_file(shows_list, file_path)
19
- puts "Removed anime \"#{show.title}\" (#{mal_id})"
20
- break
21
- end
16
+ next unless show_index >= 0
17
+
18
+ show = shows_list.delete_at(show_index)
19
+ Writer.to_file(shows_list, file_path)
20
+ puts "Removed anime \"#{show.title}\" (#{mal_id})"
21
+ break
22
22
  end
23
23
  end
24
24
  end
@@ -6,11 +6,11 @@ module Organo
6
6
  module Anime
7
7
 
8
8
  class Search < Dry::CLI::Command
9
- desc "Search anime by query from files"
10
- argument :query, type: :string, required: true, desc: "Search query"
9
+ desc 'Search anime by query from files'
10
+ argument :query, type: :string, required: true, desc: 'Search query'
11
11
 
12
12
  def call(query:, **)
13
- found_list = Array.new
13
+ found_list = []
14
14
  Dir["#{Config::DEFAULT_DIR}/*.json"].each do |file_path|
15
15
  shows_list = Reader.read_file(file_path)
16
16
  show = shows_list.find { |s| s.title.downcase.include? query }
@@ -6,17 +6,21 @@ module Organo
6
6
  module Anime
7
7
 
8
8
  class Show < Dry::CLI::Command
9
- desc "Show anime entry from files"
10
- argument :mal_id, type: :integer, required: true, desc: "MyAnimeList ID"
9
+ desc 'Show anime entry from files'
10
+ argument :mal_id, type: :integer, required: true, desc: 'MyAnimeList ID'
11
11
 
12
12
  def call(mal_id:, **)
13
+ found = false
13
14
  Dir["#{Config::DEFAULT_DIR}/*.json"].each do |file_path|
14
15
  shows_list = Reader.read_file(file_path)
15
16
  show = shows_list.find { |s| s.id.to_s == mal_id.to_s }
16
17
  next if show.nil?
17
18
 
19
+ found = true
18
20
  puts show.to_json
21
+ break
19
22
  end
23
+ puts 'Entry not found.' unless found
20
24
  end
21
25
  end
22
26
 
@@ -10,22 +10,35 @@ module Organo
10
10
  module Update
11
11
 
12
12
  class Image < Dry::CLI::Command
13
- desc "Update cover image for the specified anime"
14
- argument :mal_id_list, type: :array, required: true, desc: "MyAnimeList ID list"
13
+ desc 'Update cover image for the specified anime'
14
+ argument :mal_id_list, type: :array, required: true, desc: 'MyAnimeList ID list'
15
15
 
16
16
  def call(mal_id_list:, **)
17
+ found = false
17
18
  Dir["#{Config::DEFAULT_DIR}/*.json"].each do |file_path|
18
19
  shows_list = Reader.read_file(file_path)
19
- mal_id_list.each do |mal_id|
20
+ mal_id_list.each_with_index do |mal_id, index|
20
21
  show = shows_list.find { |s| s.id.to_s == mal_id.to_s }
22
+ if show.nil?
23
+ shows_list.each do |s|
24
+ show = s.sequels.find { |ss| ss['id'].to_s == mal_id.to_s }
25
+ end
26
+ end
21
27
  next if show.nil?
22
28
 
23
- show.image_url = Query.get_anime_image(show.id)
29
+ found = true
30
+ if show.is_a?(Hash)
31
+ show['image_url'] = Query.get_anime_image(show['id'])
32
+ # puts show['image_url']
33
+ else
34
+ show.image_url = Query.get_anime_image(show.id)
35
+ # puts show.image_url
36
+ end
24
37
  Writer.to_file(shows_list, file_path)
25
- # puts show.image_url
38
+ sleep(1) if mal_id_list.size > 1 && index < (mal_id.size - 1)
26
39
  end
27
40
  end
28
- puts 'Cover image(s) has been updated.'
41
+ puts found ? 'Cover image(s) has been updated.' : 'Entry not found.'
29
42
  end
30
43
  end
31
44
 
@@ -9,9 +9,9 @@ module Organo
9
9
  module Update
10
10
 
11
11
  class SearchQuery < Dry::CLI::Command
12
- desc "Update search query for the specified anime"
13
- argument :mal_id, type: :integer, required: true, desc: "MyAnimeList ID"
14
- argument :search_query, type: :string, required: true, desc: "String query for Nyaa Torrents search"
12
+ desc 'Update search query for the specified anime'
13
+ argument :mal_id, type: :integer, required: true, desc: 'MyAnimeList ID'
14
+ argument :search_query, type: :string, required: true, desc: 'String query for Nyaa Torrents search'
15
15
 
16
16
  def call(mal_id:, search_query:, **)
17
17
  Dir["#{Config::DEFAULT_DIR}/*.json"].each do |file_path|
@@ -21,7 +21,7 @@ module Organo
21
21
 
22
22
  show.search_query = search_query
23
23
  Writer.to_file(shows_list, file_path)
24
- puts "Search query has been updated."
24
+ puts 'Search query has been updated.'
25
25
  end
26
26
  end
27
27
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Organo
4
- VERSION = '0.3.0'
4
+ VERSION = '0.3.1'
5
5
  end
data/lib/organo.rb CHANGED
@@ -29,32 +29,37 @@ module Organo
29
29
 
30
30
  register 'version', Version, aliases: %w[v -v --version]
31
31
  register 'init', Init
32
- register 'anime' do |prefix|
33
- prefix.register 'add', Anime::Add::AnimeEntry
34
- prefix.register 'add sequel', Anime::Add::SequelEntry
35
- prefix.register 'remove', Anime::Remove
36
- prefix.register 'show', Anime::Show
37
- prefix.register 'search', Anime::Search
38
- prefix.register 'update image', Anime::Update::Image
39
- prefix.register 'update search_query', Anime::Update::SearchQuery
40
- prefix.register 'get broken_links', Anime::Get::BrokenLinks
41
- end
42
- register 'api' do |prefix|
43
- prefix.register 'get anime', API::Get::Anime
44
- prefix.register 'get season', API::Get::Season
45
- prefix.register 'get sequels', API::Get::Sequels
46
- prefix.register 'search anime', API::Search::Anime
47
- end
48
- register 'merge', Merge
49
- register 'statistics', Statistics
50
- register 'remote' do |prefix|
51
- prefix.register 'add', Remote::Add
52
- prefix.register 'remove', Remote::Remove
53
- prefix.register 'download', Remote::Download
54
- prefix.register 'upload', Remote::Upload
55
- end
56
- register 'schedule' do |prefix|
57
- prefix.register 'create', Schedule::Create
32
+
33
+ if Dir.exist?('.organo')
34
+ register 'anime' do |prefix|
35
+ prefix.register 'add', Anime::Add::AnimeEntry
36
+ prefix.register 'add sequel', Anime::Add::SequelEntry
37
+ prefix.register 'remove', Anime::Remove
38
+ prefix.register 'show', Anime::Show
39
+ prefix.register 'search', Anime::Search
40
+ prefix.register 'update image', Anime::Update::Image
41
+ prefix.register 'update search_query', Anime::Update::SearchQuery
42
+ prefix.register 'get broken_links', Anime::Get::BrokenLinks
43
+ end
44
+ register 'api' do |prefix|
45
+ prefix.register 'get anime', API::Get::Anime
46
+ prefix.register 'get season', API::Get::Season
47
+ prefix.register 'get sequels', API::Get::Sequels
48
+ prefix.register 'search anime', API::Search::Anime
49
+ end
50
+ register 'merge', Merge
51
+ register 'statistics', Statistics
52
+ register 'remote' do |prefix|
53
+ prefix.register 'add', Remote::Add
54
+ prefix.register 'remove', Remote::Remove
55
+ prefix.register 'download', Remote::Download
56
+ prefix.register 'upload', Remote::Upload
57
+ end
58
+ register 'schedule' do |prefix|
59
+ prefix.register 'create', Schedule::Create
60
+ end
61
+ else
62
+ puts 'This directory has not been initialized.'
58
63
  end
59
64
  end
60
65
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: organo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Louis-Philippe Fortin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-02-05 00:00:00.000000000 Z
11
+ date: 2023-03-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-cli