organo 0.3.5 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/doc/anime.md +30 -8
- data/doc/readme.md +2 -2
- data/lib/organo/commands/anime/anime_add.rb +27 -24
- data/lib/organo/commands/anime/anime_find_broken_links.rb +31 -0
- data/lib/organo/commands/anime/anime_remove.rb +10 -14
- data/lib/organo/commands/anime/anime_set_sequel.rb +49 -0
- data/lib/organo/commands/anime/anime_show.rb +9 -15
- data/lib/organo/commands/anime/anime_update_image.rb +16 -35
- data/lib/organo/commands/anime/anime_update_query.rb +16 -21
- data/lib/organo/commands/api/api_get_anime.rb +3 -6
- data/lib/organo/commands/api/api_get_season.rb +3 -4
- data/lib/organo/commands/api/api_get_sequels.rb +1 -3
- data/lib/organo/commands/init.rb +30 -8
- data/lib/organo/commands/remote/remote_add.rb +6 -10
- data/lib/organo/commands/remote/remote_download.rb +5 -6
- data/lib/organo/commands/remote/remote_remove.rb +0 -2
- data/lib/organo/commands/remote/remote_upload.rb +1 -2
- data/lib/organo/commands/statistics.rb +6 -21
- data/lib/organo/query.rb +0 -1
- data/lib/organo/tools/string_utils.rb +28 -0
- data/lib/organo/tools/writer.rb +0 -5
- data/lib/organo/version.rb +1 -1
- data/lib/organo.rb +34 -43
- metadata +36 -17
- data/lib/organo/commands/anime/anime_add_sequel.rb +0 -52
- data/lib/organo/commands/anime/anime_get_broken_links.rb +0 -32
- data/lib/organo/commands/anime/anime_search.rb +0 -25
- data/lib/organo/commands/api/api_search_anime.rb +0 -29
- data/lib/organo/commands/merge.rb +0 -24
- data/lib/organo/model/search_show.rb +0 -58
- data/lib/organo/model/sequel.rb +0 -39
- data/lib/organo/model/show.rb +0 -36
- data/lib/organo/show_list.rb +0 -32
- data/lib/organo/tools/check.rb +0 -12
- data/lib/organo/tools/local_search.rb +0 -49
- data/lib/organo/tools/reader.rb +0 -38
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'net/ftp'
|
4
|
-
require_relative '../../tools/check'
|
5
4
|
|
6
5
|
module Organo
|
7
6
|
module CLI
|
@@ -13,7 +12,6 @@ module Organo
|
|
13
12
|
argument :env, type: :string, required: true, desc: 'Environment'
|
14
13
|
|
15
14
|
def call(env:, **)
|
16
|
-
Check.init?
|
17
15
|
config = File.exist?(Config::DEFAULT_FILE) ? JSON.parse(File.read(Config::DEFAULT_FILE)) : nil
|
18
16
|
section = config.find { |option| option['section'] == 'remotes' }
|
19
17
|
if section.nil?
|
@@ -25,6 +23,7 @@ module Organo
|
|
25
23
|
else
|
26
24
|
local_files = Dir['./*.{data,config}.json']
|
27
25
|
local_files.push('./schedule.json')
|
26
|
+
local_files.push('./dkb_edited.db')
|
28
27
|
Net::FTP.open(credentials['url']) do |ftp|
|
29
28
|
ftp.login(credentials['username'], credentials['password'])
|
30
29
|
ftp.chdir(credentials['directory'])
|
@@ -1,34 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
require_relative '../tools/check'
|
3
|
+
require 'sequel'
|
5
4
|
|
6
5
|
module Organo
|
7
6
|
module CLI
|
8
7
|
module Commands
|
9
8
|
|
10
9
|
class Statistics < Dry::CLI::Command
|
11
|
-
desc '
|
10
|
+
desc 'Get statistics from data'
|
12
11
|
|
13
12
|
def call(*)
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
Dir["#{Config::DEFAULT_DIR}/*.json"].each do |file_path|
|
19
|
-
shows = Reader.read_file(file_path)
|
20
|
-
file_size = File.size(file_path)
|
21
|
-
puts "#{File.basename(file_path)}: #{shows.count} (#{file_size.to_f / 1000} KB)"
|
22
|
-
shows_num += shows.count
|
23
|
-
shows.each do |show|
|
24
|
-
sequels_num += show.sequels.size
|
25
|
-
end
|
26
|
-
total_size += file_size
|
27
|
-
end
|
28
|
-
puts '------------------------------'
|
29
|
-
puts "Shows count: #{shows_num}"
|
30
|
-
puts "Sequels count: #{sequels_num}"
|
31
|
-
puts "Total file size: #{total_size.to_f / 1000} KB"
|
13
|
+
db = Sequel.sqlite('dkb_edited.db')
|
14
|
+
puts "Total show count: #{db.from(:shows).count}"
|
15
|
+
puts "Non-sequel show count #{db.from(:shows).where(is_sequel: false).count}"
|
16
|
+
puts "Sequel show count: #{db.from(:sequels).count}"
|
32
17
|
end
|
33
18
|
end
|
34
19
|
|
data/lib/organo/query.rb
CHANGED
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Organo
|
4
|
+
class StringUtils
|
5
|
+
def self.create_slug(title)
|
6
|
+
# strip the string
|
7
|
+
ret = title.strip
|
8
|
+
|
9
|
+
# blow away apostrophes
|
10
|
+
ret.gsub!(/['`]/, '')
|
11
|
+
|
12
|
+
# @ --> at, and & --> and
|
13
|
+
ret.gsub!(/\s*@\s*/, ' at ')
|
14
|
+
ret.gsub!(/\s*&\s*/, ' and ')
|
15
|
+
|
16
|
+
# replace all non alphanumeric with dash
|
17
|
+
ret.gsub!(/\s*[^A-Za-z0-9]\s*/, '-')
|
18
|
+
|
19
|
+
# convert double underscores to single
|
20
|
+
ret.gsub!(/-+/, '-')
|
21
|
+
|
22
|
+
# strip off leading/trailing dash
|
23
|
+
ret.gsub!(/\A-+|-+\z/, '')
|
24
|
+
|
25
|
+
ret.downcase
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/organo/tools/writer.rb
CHANGED
@@ -4,11 +4,6 @@ require 'json'
|
|
4
4
|
|
5
5
|
module Organo
|
6
6
|
class Writer
|
7
|
-
def self.to_data_file(obj, file_name)
|
8
|
-
file_path = "./#{file_name}.data.json"
|
9
|
-
File.write(file_path, JSON.pretty_generate(obj))
|
10
|
-
end
|
11
|
-
|
12
7
|
def self.to_file(obj, file_path)
|
13
8
|
File.write(file_path, JSON.pretty_generate(obj))
|
14
9
|
end
|
data/lib/organo/version.rb
CHANGED
data/lib/organo.rb
CHANGED
@@ -1,63 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'dry/cli'
|
2
4
|
|
5
|
+
require_relative 'organo/commands/version'
|
3
6
|
require_relative 'organo/commands/init'
|
7
|
+
require_relative 'organo/commands/statistics'
|
8
|
+
require_relative 'organo/commands/anime/anime_show'
|
4
9
|
require_relative 'organo/commands/anime/anime_add'
|
5
|
-
require_relative 'organo/commands/anime/anime_add_sequel'
|
6
|
-
require_relative 'organo/commands/anime/anime_get_broken_links'
|
7
10
|
require_relative 'organo/commands/anime/anime_remove'
|
8
|
-
require_relative 'organo/commands/anime/
|
9
|
-
require_relative 'organo/commands/anime/
|
11
|
+
require_relative 'organo/commands/anime/anime_set_sequel'
|
12
|
+
require_relative 'organo/commands/anime/anime_find_broken_links'
|
10
13
|
require_relative 'organo/commands/anime/anime_update_image'
|
11
14
|
require_relative 'organo/commands/anime/anime_update_query'
|
12
|
-
require_relative 'organo/commands/api/api_get_anime'
|
13
|
-
require_relative 'organo/commands/api/api_get_sequels'
|
14
|
-
require_relative 'organo/commands/api/api_get_season'
|
15
|
-
require_relative 'organo/commands/api/api_search_anime'
|
16
|
-
require_relative 'organo/commands/api/api_get_schedule'
|
17
15
|
require_relative 'organo/commands/remote/remote_add'
|
18
16
|
require_relative 'organo/commands/remote/remote_remove'
|
19
17
|
require_relative 'organo/commands/remote/remote_download'
|
20
18
|
require_relative 'organo/commands/remote/remote_upload'
|
21
|
-
require_relative 'organo/commands/
|
22
|
-
require_relative 'organo/commands/
|
23
|
-
require_relative 'organo/commands/
|
24
|
-
require_relative 'organo/commands/
|
19
|
+
require_relative 'organo/commands/api/api_get_anime'
|
20
|
+
require_relative 'organo/commands/api/api_get_season'
|
21
|
+
require_relative 'organo/commands/api/api_get_sequels'
|
22
|
+
require_relative 'organo/commands/api/api_search_anime'
|
25
23
|
|
26
24
|
module Organo
|
27
25
|
module CLI
|
28
26
|
module Commands
|
29
27
|
extend Dry::CLI::Registry
|
28
|
+
# Misc commands
|
29
|
+
register 'version', Organo::CLI::Commands::Version, aliases: %w[v -v --version]
|
30
|
+
register 'init', Organo::CLI::Commands::Init
|
31
|
+
register 'stats', Organo::CLI::Commands::Statistics
|
32
|
+
|
33
|
+
# Anime commands
|
34
|
+
register 'anime show', Organo::CLI::Commands::Anime::ShowEntry
|
35
|
+
register 'anime add', Organo::CLI::Commands::Anime::AddEntry
|
36
|
+
register 'anime remove', Organo::CLI::Commands::Anime::RemoveEntry
|
37
|
+
register 'anime set_sequel', Organo::CLI::Commands::Anime::SequelEntry
|
38
|
+
register 'anime find_broken_links', Organo::CLI::Commands::Anime::FindBrokenLinks
|
39
|
+
register 'anime update image', Organo::CLI::Commands::Anime::UpdateImage
|
40
|
+
register 'anime update search_query', Organo::CLI::Commands::Anime::UpdateSearchQuery
|
41
|
+
|
42
|
+
# Remote commands
|
43
|
+
register 'remote add', Organo::CLI::Commands::Remote::AddEntry
|
44
|
+
register 'remote remove', Organo::CLI::Commands::Remote::Remove
|
45
|
+
register 'remote download', Organo::CLI::Commands::Remote::Download
|
46
|
+
register 'remote download', Organo::CLI::Commands::Remote::Upload
|
30
47
|
|
31
|
-
|
32
|
-
register '
|
33
|
-
register '
|
34
|
-
|
35
|
-
prefix.register 'add sequel', Anime::Add::SequelEntry
|
36
|
-
prefix.register 'remove', Anime::Remove
|
37
|
-
prefix.register 'show', Anime::Show
|
38
|
-
prefix.register 'search', Anime::Search
|
39
|
-
prefix.register 'update image', Anime::Update::Image
|
40
|
-
prefix.register 'update search_query', Anime::Update::SearchQuery
|
41
|
-
prefix.register 'get broken_links', Anime::Get::BrokenLinks
|
42
|
-
end
|
43
|
-
register 'api' do |prefix|
|
44
|
-
prefix.register 'get anime', API::Get::Anime
|
45
|
-
prefix.register 'get season', API::Get::Season
|
46
|
-
prefix.register 'get sequels', API::Get::Sequels
|
47
|
-
prefix.register 'search anime', API::Search::Anime
|
48
|
-
prefix.register 'get schedule', API::Get::Schedule
|
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
|
48
|
+
# API commands
|
49
|
+
register 'api get anime', Organo::CLI::Commands::API::Get::Anime
|
50
|
+
register 'api get season', Organo::CLI::Commands::API::Get::Season
|
51
|
+
register 'api get sequels', Organo::CLI::Commands::API::Get::Sequels
|
61
52
|
end
|
62
53
|
end
|
63
54
|
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.
|
4
|
+
version: 0.4.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-
|
11
|
+
date: 2023-11-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-cli
|
@@ -52,6 +52,34 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '2.1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: sequel
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '5.74'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '5.74'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: sqlite3
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.6'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.6'
|
55
83
|
- !ruby/object:Gem::Dependency
|
56
84
|
name: rubocop
|
57
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,8 +94,8 @@ dependencies:
|
|
66
94
|
- - "~>"
|
67
95
|
- !ruby/object:Gem::Version
|
68
96
|
version: '1.44'
|
69
|
-
description:
|
70
|
-
used
|
97
|
+
description: Gets JSON data from different APIs to build a local database that can
|
98
|
+
be used in other applications
|
71
99
|
email:
|
72
100
|
- timemaster.lpf@gmail.com
|
73
101
|
executables:
|
@@ -87,10 +115,9 @@ files:
|
|
87
115
|
- lib/organo.rb
|
88
116
|
- lib/organo/animeschedule_api.rb
|
89
117
|
- lib/organo/commands/anime/anime_add.rb
|
90
|
-
- lib/organo/commands/anime/
|
91
|
-
- lib/organo/commands/anime/anime_get_broken_links.rb
|
118
|
+
- lib/organo/commands/anime/anime_find_broken_links.rb
|
92
119
|
- lib/organo/commands/anime/anime_remove.rb
|
93
|
-
- lib/organo/commands/anime/
|
120
|
+
- lib/organo/commands/anime/anime_set_sequel.rb
|
94
121
|
- lib/organo/commands/anime/anime_show.rb
|
95
122
|
- lib/organo/commands/anime/anime_update_image.rb
|
96
123
|
- lib/organo/commands/anime/anime_update_query.rb
|
@@ -98,9 +125,7 @@ files:
|
|
98
125
|
- lib/organo/commands/api/api_get_schedule.rb
|
99
126
|
- lib/organo/commands/api/api_get_season.rb
|
100
127
|
- lib/organo/commands/api/api_get_sequels.rb
|
101
|
-
- lib/organo/commands/api/api_search_anime.rb
|
102
128
|
- lib/organo/commands/init.rb
|
103
|
-
- lib/organo/commands/merge.rb
|
104
129
|
- lib/organo/commands/remote/remote_add.rb
|
105
130
|
- lib/organo/commands/remote/remote_download.rb
|
106
131
|
- lib/organo/commands/remote/remote_remove.rb
|
@@ -110,15 +135,9 @@ files:
|
|
110
135
|
- lib/organo/commands/version.rb
|
111
136
|
- lib/organo/config.rb
|
112
137
|
- lib/organo/jikan_api.rb
|
113
|
-
- lib/organo/model/search_show.rb
|
114
|
-
- lib/organo/model/sequel.rb
|
115
|
-
- lib/organo/model/show.rb
|
116
138
|
- lib/organo/query.rb
|
117
139
|
- lib/organo/request.rb
|
118
|
-
- lib/organo/
|
119
|
-
- lib/organo/tools/check.rb
|
120
|
-
- lib/organo/tools/local_search.rb
|
121
|
-
- lib/organo/tools/reader.rb
|
140
|
+
- lib/organo/tools/string_utils.rb
|
122
141
|
- lib/organo/tools/writer.rb
|
123
142
|
- lib/organo/version.rb
|
124
143
|
homepage: https://gitlab.com/dkb-weeblets/organo
|
@@ -146,5 +165,5 @@ requirements: []
|
|
146
165
|
rubygems_version: 3.2.33
|
147
166
|
signing_key:
|
148
167
|
specification_version: 4
|
149
|
-
summary: Tool to build dataset from
|
168
|
+
summary: Tool to build dataset from Anime database APIs
|
150
169
|
test_files: []
|
@@ -1,52 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative '../../config'
|
4
|
-
require_relative '../../tools/writer'
|
5
|
-
require_relative '../../tools/reader'
|
6
|
-
require_relative '../../tools/local_search'
|
7
|
-
require_relative '../../tools/check'
|
8
|
-
|
9
|
-
module Organo
|
10
|
-
module CLI
|
11
|
-
module Commands
|
12
|
-
module Anime
|
13
|
-
module Add
|
14
|
-
|
15
|
-
class SequelEntry < Dry::CLI::Command
|
16
|
-
desc 'Add anime sequel entry to anime in file'
|
17
|
-
argument :anime_mal_id, type: :integer, required: true, desc: 'Anime MyAnimeList ID'
|
18
|
-
argument :sequel_mal_id, type: :integer, required: true, desc: 'Sequel MyAnimeList ID'
|
19
|
-
argument :season_num, type: :integer, required: false, default: 0, desc: 'Season number'
|
20
|
-
argument :type, type: :string, required: false, default: '', values: %w[part movie special], desc: 'Type of sequel (part, movie, special)'
|
21
|
-
argument :type_num, type: :integer, required: false, default: 0, desc: 'The sequel type number'
|
22
|
-
|
23
|
-
def call(anime_mal_id:, sequel_mal_id:, season_num:, type:, type_num:, **)
|
24
|
-
Check.init?
|
25
|
-
if LocalSearch.find_anime_by_id(sequel_mal_id).nil?
|
26
|
-
json_obj = Query.get_anime_by_id(sequel_mal_id)
|
27
|
-
sequel = Sequel.new(
|
28
|
-
json_obj['mal_id'],
|
29
|
-
json_obj['title'],
|
30
|
-
json_obj['images']['jpg']['image_url'],
|
31
|
-
season_num,
|
32
|
-
type,
|
33
|
-
type_num
|
34
|
-
)
|
35
|
-
file_path = LocalSearch.find_file_by_anime_id(anime_mal_id)
|
36
|
-
show_list = Reader.read_file(file_path).each do |show|
|
37
|
-
show.sequels.push(sequel) if show.id == anime_mal_id.to_i
|
38
|
-
end
|
39
|
-
show_info = show_list.find { |show| show.id == anime_mal_id.to_i }
|
40
|
-
Writer.to_file(show_list, file_path)
|
41
|
-
puts "Added sequel \"#{sequel.title}\" (#{sequel.id}) to anime \"#{show_info.title}\" (#{anime_mal_id}) in #{file_path}."
|
42
|
-
else
|
43
|
-
puts 'This sequel already exists.'
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
require 'httparty'
|
2
|
-
require_relative '../../tools/reader'
|
3
|
-
require_relative '../../tools/check'
|
4
|
-
|
5
|
-
module Organo
|
6
|
-
module CLI
|
7
|
-
module Commands
|
8
|
-
module Anime
|
9
|
-
module Get
|
10
|
-
|
11
|
-
class BrokenLinks < Dry::CLI::Command
|
12
|
-
desc 'Get list of anime IDs that have broken links'
|
13
|
-
|
14
|
-
def call(*)
|
15
|
-
Check.init?
|
16
|
-
show_list = Reader.read_all_files
|
17
|
-
broken_list = []
|
18
|
-
show_list.each do |show|
|
19
|
-
response = HTTParty.get(show.image_url)
|
20
|
-
next unless response.code == 404
|
21
|
-
|
22
|
-
broken_list.push(show.id)
|
23
|
-
end
|
24
|
-
puts broken_list.join(' ') unless broken_list.empty?
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative '../../config'
|
4
|
-
require_relative '../../tools/local_search'
|
5
|
-
require_relative '../../tools/check'
|
6
|
-
|
7
|
-
module Organo
|
8
|
-
module CLI
|
9
|
-
module Commands
|
10
|
-
module Anime
|
11
|
-
|
12
|
-
class Search < Dry::CLI::Command
|
13
|
-
desc 'Search anime by query from files'
|
14
|
-
argument :query, type: :string, required: true, desc: 'Search query'
|
15
|
-
|
16
|
-
def call(query:, **)
|
17
|
-
Check.init?
|
18
|
-
puts (LocalSearch.find_anime_by_query(query).map{ |anime| anime.to_json} )
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative '../../query'
|
4
|
-
require_relative '../../show_list'
|
5
|
-
|
6
|
-
module Organo
|
7
|
-
module CLI
|
8
|
-
module Commands
|
9
|
-
module API
|
10
|
-
module Search
|
11
|
-
|
12
|
-
class Anime < Dry::CLI::Command
|
13
|
-
desc 'Get a list anime from query'
|
14
|
-
argument :query, type: :string, required: true, desc: 'Search query'
|
15
|
-
option :type, type: :string, required: false, default: '', values: %w[tv movie ova special ona music], desc: 'Type of anime'
|
16
|
-
option :limit, type: :integer, required: false, default: 5, desc: 'Limit number of results'
|
17
|
-
|
18
|
-
def call(query:, type:, limit:, **)
|
19
|
-
json_obj = Query.search_anime(query, { 'type' => type, 'limit' => limit})
|
20
|
-
show_list = ShowList.create_search_show_list(json_obj)
|
21
|
-
puts show_list.to_json
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative '../tools/reader'
|
4
|
-
require_relative '../tools/writer'
|
5
|
-
require_relative '../tools/check'
|
6
|
-
|
7
|
-
module Organo
|
8
|
-
module CLI
|
9
|
-
module Commands
|
10
|
-
|
11
|
-
class Merge < Dry::CLI::Command
|
12
|
-
desc 'Merge edited seasonal files into one main file'
|
13
|
-
|
14
|
-
def call(*)
|
15
|
-
Check.init?
|
16
|
-
show_list = Reader.read_all_files
|
17
|
-
Writer.to_data_file(show_list, 'shows')
|
18
|
-
puts 'Edited files have been merged.'
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,58 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'json'
|
4
|
-
|
5
|
-
module Organo
|
6
|
-
class SearchShow
|
7
|
-
attr_accessor :id, :title, :image_url, :search_query
|
8
|
-
|
9
|
-
def initialize(id, title, image_url)
|
10
|
-
@id = id
|
11
|
-
@slug = create_slug(title)
|
12
|
-
@title = title.to_s
|
13
|
-
@image_url = image_url
|
14
|
-
@search_query = title
|
15
|
-
end
|
16
|
-
|
17
|
-
def create_slug(title)
|
18
|
-
# strip the string
|
19
|
-
ret = title.strip
|
20
|
-
|
21
|
-
# blow away apostrophes
|
22
|
-
ret.gsub!(/['`]/, '')
|
23
|
-
|
24
|
-
# @ --> at, and & --> and
|
25
|
-
ret.gsub!(/\s*@\s*/, ' at ')
|
26
|
-
ret.gsub!(/\s*&\s*/, ' and ')
|
27
|
-
|
28
|
-
# replace all non alphanumeric with dash
|
29
|
-
ret.gsub!(/\s*[^A-Za-z0-9]\s*/, '-')
|
30
|
-
|
31
|
-
# convert double underscores to single
|
32
|
-
ret.gsub!(/-+/, '-')
|
33
|
-
|
34
|
-
# strip off leading/trailing dash
|
35
|
-
ret.gsub!(/\A-+|-+\z/, '')
|
36
|
-
|
37
|
-
ret.downcase
|
38
|
-
end
|
39
|
-
|
40
|
-
def to_s
|
41
|
-
"title: #{@title}, synopsis: #{@description}, image_url: #{@image_url}"
|
42
|
-
end
|
43
|
-
|
44
|
-
def as_json(_options = {})
|
45
|
-
{
|
46
|
-
id: @id,
|
47
|
-
slug: @slug,
|
48
|
-
title: @title,
|
49
|
-
image_url: @image_url,
|
50
|
-
search_query: @search_query
|
51
|
-
}
|
52
|
-
end
|
53
|
-
|
54
|
-
def to_json(*options)
|
55
|
-
as_json(*options).to_json(*options)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
data/lib/organo/model/sequel.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'json'
|
4
|
-
|
5
|
-
module Organo
|
6
|
-
class Sequel
|
7
|
-
attr_accessor :id, :type, :title, :image_url, :selector
|
8
|
-
|
9
|
-
def initialize(id, title, image_url, season_num = 0, type = "", type_num = 0, selector = -1)
|
10
|
-
@id = id
|
11
|
-
@title = title.to_s
|
12
|
-
@image_url = image_url
|
13
|
-
@season_num = season_num
|
14
|
-
@type = type.to_s
|
15
|
-
@type_num = type_num
|
16
|
-
@selector = selector
|
17
|
-
end
|
18
|
-
|
19
|
-
def to_s
|
20
|
-
"id: #{@id}, title: #{@title}, image_url: #{@image_url}"
|
21
|
-
end
|
22
|
-
|
23
|
-
def as_json(_options = {})
|
24
|
-
{
|
25
|
-
id: @id,
|
26
|
-
title: @title,
|
27
|
-
image_url: @image_url,
|
28
|
-
season_num: @season_num.to_i,
|
29
|
-
type: @type,
|
30
|
-
type_num: @type_num.to_i,
|
31
|
-
selector: @selector.to_i
|
32
|
-
}
|
33
|
-
end
|
34
|
-
|
35
|
-
def to_json(*options)
|
36
|
-
as_json(*options).to_json(*options)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
data/lib/organo/model/show.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'json'
|
4
|
-
|
5
|
-
class Show
|
6
|
-
attr_accessor :id, :slug, :title, :image_url, :search_query, :sequels
|
7
|
-
|
8
|
-
def initialize(id, slug, title, image_url, search_query, links = [], sequels = [])
|
9
|
-
@id = id
|
10
|
-
@slug = slug
|
11
|
-
@title = title.to_s
|
12
|
-
@image_url = image_url
|
13
|
-
@search_query = search_query.empty? ? title : search_query
|
14
|
-
@links = links.nil? ? [] : links
|
15
|
-
@sequels = sequels.nil? ? [] : sequels
|
16
|
-
end
|
17
|
-
|
18
|
-
def to_s
|
19
|
-
"id: #{@id}, title: #{@title}, image_url: #{@image_url}"
|
20
|
-
end
|
21
|
-
|
22
|
-
def as_json(_options = {})
|
23
|
-
{
|
24
|
-
id: @id,
|
25
|
-
slug: @slug,
|
26
|
-
title: @title,
|
27
|
-
image_url: @image_url,
|
28
|
-
sequels: @sequels,
|
29
|
-
search_query: @search_query
|
30
|
-
}
|
31
|
-
end
|
32
|
-
|
33
|
-
def to_json(*options)
|
34
|
-
as_json(*options).to_json(*options)
|
35
|
-
end
|
36
|
-
end
|
data/lib/organo/show_list.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'json'
|
4
|
-
require_relative 'model/search_show'
|
5
|
-
require_relative 'model/sequel'
|
6
|
-
require_relative 'query'
|
7
|
-
|
8
|
-
module Organo
|
9
|
-
class ShowList
|
10
|
-
def self.create_search_show_list(json_obj)
|
11
|
-
show_list = []
|
12
|
-
json_obj.each do |entry|
|
13
|
-
show = SearchShow.new(entry['mal_id'], entry['title'], entry['images']['jpg']['image_url'])
|
14
|
-
show_list.push show
|
15
|
-
end
|
16
|
-
show_list.sort_by(&:title)
|
17
|
-
end
|
18
|
-
|
19
|
-
def self.create_search_sequel_list(json_obj)
|
20
|
-
sequel_list = []
|
21
|
-
json_obj.each do |relations|
|
22
|
-
next unless relations['relation'] == 'Sequel'
|
23
|
-
|
24
|
-
relations['entry'].each do |entry|
|
25
|
-
image_url = Query.get_anime_image(entry['mal_id'])
|
26
|
-
sequel_list.push Sequel.new(entry['mal_id'], entry['name'], image_url)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
sequel_list.sort_by(&:title)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
data/lib/organo/tools/check.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Organo
|
4
|
-
class Check
|
5
|
-
def self.init?
|
6
|
-
unless Dir.exist?('.organo')
|
7
|
-
puts "Directory is not initialized.\nYou can initialize the current directory with the following command:\n$ organo init"
|
8
|
-
exit
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|