organo 0.3.4 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- 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 -22
- data/lib/organo/commands/anime/anime_find_broken_links.rb +31 -0
- data/lib/organo/commands/anime/anime_remove.rb +12 -12
- data/lib/organo/commands/anime/anime_set_sequel.rb +49 -0
- data/lib/organo/commands/anime/anime_show.rb +11 -13
- data/lib/organo/commands/anime/anime_update_image.rb +18 -33
- data/lib/organo/commands/anime/anime_update_query.rb +18 -19
- data/lib/organo/commands/api/api_get_anime.rb +5 -6
- data/lib/organo/commands/api/api_get_season.rb +6 -7
- data/lib/organo/commands/api/api_get_sequels.rb +5 -5
- data/lib/organo/commands/init.rb +32 -8
- data/lib/organo/commands/remote/remote_add.rb +14 -14
- data/lib/organo/commands/remote/remote_download.rb +10 -7
- data/lib/organo/commands/remote/remote_remove.rb +6 -4
- data/lib/organo/commands/remote/remote_upload.rb +6 -3
- data/lib/organo/commands/statistics.rb +8 -12
- data/lib/organo/commands/version.rb +3 -1
- data/lib/organo/query.rb +0 -1
- data/lib/organo/tools/string_utils.rb +28 -0
- data/lib/organo/{writer.rb → tools/writer.rb} +0 -5
- data/lib/organo/version.rb +1 -1
- data/lib/organo.rb +33 -47
- metadata +37 -17
- data/lib/organo/commands/anime/anime_add_sequel.rb +0 -50
- data/lib/organo/commands/anime/anime_get_broken_links.rb +0 -30
- data/lib/organo/commands/anime/anime_search.rb +0 -23
- data/lib/organo/commands/api/api_search_anime.rb +0 -27
- data/lib/organo/commands/merge.rb +0 -20
- data/lib/organo/reader.rb +0 -38
- data/lib/organo/search_show.rb +0 -58
- data/lib/organo/sequel.rb +0 -39
- data/lib/organo/show.rb +0 -36
- data/lib/organo/show_list.rb +0 -32
- data/lib/organo/tools/local_search.rb +0 -49
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative '../../config'
|
2
4
|
|
3
5
|
module Organo
|
@@ -6,17 +8,17 @@ module Organo
|
|
6
8
|
module Remote
|
7
9
|
|
8
10
|
class Remove < Dry::CLI::Command
|
9
|
-
desc
|
10
|
-
argument :env, type: :string, required: true, desc:
|
11
|
+
desc 'Remove remote FTP server from config file'
|
12
|
+
argument :env, type: :string, required: true, desc: 'Remote environment name'
|
11
13
|
|
12
14
|
def call(env:, **)
|
13
15
|
config = File.exist?(Config::DEFAULT_FILE) ? JSON.parse(File.read(Config::DEFAULT_FILE)) : nil
|
14
16
|
unless config.nil?
|
15
17
|
section = config.find { |option| option['section'] == 'remotes' }
|
16
|
-
|
18
|
+
if !section.nil?
|
17
19
|
index = section['entries'].find_index { |entry| entry['env'] == env }
|
18
20
|
if index.nil?
|
19
|
-
puts
|
21
|
+
puts 'Specified environment does not exist'
|
20
22
|
elsif !section['entries'].delete_at(index).nil?
|
21
23
|
puts "Removed \"#{env}\" entry"
|
22
24
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'net/ftp'
|
2
4
|
|
3
5
|
module Organo
|
@@ -6,14 +8,14 @@ module Organo
|
|
6
8
|
module Remote
|
7
9
|
|
8
10
|
class Upload < Dry::CLI::Command
|
9
|
-
desc
|
10
|
-
argument :env, type: :string, required: true, desc:
|
11
|
+
desc 'Upload data to the website FTP'
|
12
|
+
argument :env, type: :string, required: true, desc: 'Environment'
|
11
13
|
|
12
14
|
def call(env:, **)
|
13
15
|
config = File.exist?(Config::DEFAULT_FILE) ? JSON.parse(File.read(Config::DEFAULT_FILE)) : nil
|
14
16
|
section = config.find { |option| option['section'] == 'remotes' }
|
15
17
|
if section.nil?
|
16
|
-
puts
|
18
|
+
puts 'No remote is configured in the configuration file'
|
17
19
|
else
|
18
20
|
credentials = section['entries'].find { |entry| entry['env'] == env }
|
19
21
|
if credentials.nil?
|
@@ -21,6 +23,7 @@ module Organo
|
|
21
23
|
else
|
22
24
|
local_files = Dir['./*.{data,config}.json']
|
23
25
|
local_files.push('./schedule.json')
|
26
|
+
local_files.push('./dkb_edited.db')
|
24
27
|
Net::FTP.open(credentials['url']) do |ftp|
|
25
28
|
ftp.login(credentials['username'], credentials['password'])
|
26
29
|
ftp.chdir(credentials['directory'])
|
@@ -1,23 +1,19 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'sequel'
|
2
4
|
|
3
5
|
module Organo
|
4
6
|
module CLI
|
5
7
|
module Commands
|
6
8
|
|
7
9
|
class Statistics < Dry::CLI::Command
|
8
|
-
desc
|
10
|
+
desc 'Get statistics from data'
|
9
11
|
|
10
12
|
def call(*)
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
file_size = File.size(file_path)
|
16
|
-
puts "#{File.basename(file_path)}: #{shows.count} (#{file_size} b)"
|
17
|
-
i += shows.count
|
18
|
-
total_size += file_size
|
19
|
-
end
|
20
|
-
puts "Total count: #{i} (#{total_size} o)"
|
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}"
|
21
17
|
end
|
22
18
|
end
|
23
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
|
@@ -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,68 +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
|
30
41
|
|
31
|
-
|
32
|
-
register '
|
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
|
33
47
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
prefix.register 'remove', Anime::Remove
|
39
|
-
prefix.register 'show', Anime::Show
|
40
|
-
prefix.register 'search', Anime::Search
|
41
|
-
prefix.register 'update image', Anime::Update::Image
|
42
|
-
prefix.register 'update search_query', Anime::Update::SearchQuery
|
43
|
-
prefix.register 'get broken_links', Anime::Get::BrokenLinks
|
44
|
-
end
|
45
|
-
register 'api' do |prefix|
|
46
|
-
prefix.register 'get anime', API::Get::Anime
|
47
|
-
prefix.register 'get season', API::Get::Season
|
48
|
-
prefix.register 'get sequels', API::Get::Sequels
|
49
|
-
prefix.register 'search anime', API::Search::Anime
|
50
|
-
prefix.register 'get schedule', API::Get::Schedule
|
51
|
-
end
|
52
|
-
register 'merge', Merge
|
53
|
-
register 'statistics', Statistics
|
54
|
-
register 'remote' do |prefix|
|
55
|
-
prefix.register 'add', Remote::Add
|
56
|
-
prefix.register 'remove', Remote::Remove
|
57
|
-
prefix.register 'download', Remote::Download
|
58
|
-
prefix.register 'upload', Remote::Upload
|
59
|
-
end
|
60
|
-
register 'schedule' do |prefix|
|
61
|
-
prefix.register 'create', Schedule::Create
|
62
|
-
end
|
63
|
-
else
|
64
|
-
puts 'This directory has not been initialized.'
|
65
|
-
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
|
66
52
|
end
|
67
53
|
end
|
68
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
|
@@ -111,15 +136,10 @@ files:
|
|
111
136
|
- lib/organo/config.rb
|
112
137
|
- lib/organo/jikan_api.rb
|
113
138
|
- lib/organo/query.rb
|
114
|
-
- lib/organo/reader.rb
|
115
139
|
- lib/organo/request.rb
|
116
|
-
- lib/organo/
|
117
|
-
- lib/organo/
|
118
|
-
- lib/organo/show.rb
|
119
|
-
- lib/organo/show_list.rb
|
120
|
-
- lib/organo/tools/local_search.rb
|
140
|
+
- lib/organo/tools/string_utils.rb
|
141
|
+
- lib/organo/tools/writer.rb
|
121
142
|
- lib/organo/version.rb
|
122
|
-
- lib/organo/writer.rb
|
123
143
|
homepage: https://gitlab.com/dkb-weeblets/organo
|
124
144
|
licenses:
|
125
145
|
- MIT
|
@@ -145,5 +165,5 @@ requirements: []
|
|
145
165
|
rubygems_version: 3.2.33
|
146
166
|
signing_key:
|
147
167
|
specification_version: 4
|
148
|
-
summary: Tool to build dataset from
|
168
|
+
summary: Tool to build dataset from Anime database APIs
|
149
169
|
test_files: []
|
@@ -1,50 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative '../../config'
|
4
|
-
require_relative '../../writer'
|
5
|
-
require_relative '../../reader'
|
6
|
-
require_relative '../../tools/local_search'
|
7
|
-
|
8
|
-
module Organo
|
9
|
-
module CLI
|
10
|
-
module Commands
|
11
|
-
module Anime
|
12
|
-
module Add
|
13
|
-
|
14
|
-
class SequelEntry < Dry::CLI::Command
|
15
|
-
desc 'Add anime sequel entry to anime in file'
|
16
|
-
argument :anime_mal_id, type: :integer, required: true, desc: 'Anime MyAnimeList ID'
|
17
|
-
argument :sequel_mal_id, type: :integer, required: true, desc: 'Sequel MyAnimeList ID'
|
18
|
-
argument :season_num, type: :integer, required: false, default: 0, desc: 'Season number'
|
19
|
-
argument :type, type: :string, required: false, default: '', values: %w[part movie special], desc: 'Type of sequel (part, movie, special)'
|
20
|
-
argument :type_num, type: :integer, required: false, default: 0, desc: 'The sequel type number'
|
21
|
-
|
22
|
-
def call(anime_mal_id:, sequel_mal_id:, season_num:, type:, type_num:, **)
|
23
|
-
if LocalSearch.find_anime_by_id(sequel_mal_id).nil?
|
24
|
-
json_obj = Query.get_anime_by_id(sequel_mal_id)
|
25
|
-
sequel = Sequel.new(
|
26
|
-
json_obj['mal_id'],
|
27
|
-
json_obj['title'],
|
28
|
-
json_obj['images']['jpg']['image_url'],
|
29
|
-
season_num,
|
30
|
-
type,
|
31
|
-
type_num
|
32
|
-
)
|
33
|
-
file_path = LocalSearch.find_file_by_anime_id(anime_mal_id)
|
34
|
-
show_list = Reader.read_file(file_path).each do |show|
|
35
|
-
show.sequels.push(sequel) if show.id == anime_mal_id.to_i
|
36
|
-
end
|
37
|
-
show_info = show_list.find { |show| show.id == anime_mal_id.to_i }
|
38
|
-
Writer.to_file(show_list, file_path)
|
39
|
-
puts "Added sequel \"#{sequel.title}\" (#{sequel.id}) to anime \"#{show_info.title}\" (#{anime_mal_id}) in #{file_path}."
|
40
|
-
else
|
41
|
-
puts 'This sequel already exists.'
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'httparty'
|
2
|
-
require_relative '../../reader'
|
3
|
-
|
4
|
-
module Organo
|
5
|
-
module CLI
|
6
|
-
module Commands
|
7
|
-
module Anime
|
8
|
-
module Get
|
9
|
-
|
10
|
-
class BrokenLinks < Dry::CLI::Command
|
11
|
-
desc 'Get list of anime IDs that have broken links'
|
12
|
-
|
13
|
-
def call(*)
|
14
|
-
show_list = Reader.read_all_files
|
15
|
-
broken_list = []
|
16
|
-
show_list.each do |show|
|
17
|
-
response = HTTParty.get(show.image_url)
|
18
|
-
next unless response.code == 404
|
19
|
-
|
20
|
-
broken_list.push(show.id)
|
21
|
-
end
|
22
|
-
puts broken_list.join(' ') unless broken_list.empty?
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative '../../config'
|
4
|
-
require_relative '../../tools/local_search'
|
5
|
-
|
6
|
-
module Organo
|
7
|
-
module CLI
|
8
|
-
module Commands
|
9
|
-
module Anime
|
10
|
-
|
11
|
-
class Search < Dry::CLI::Command
|
12
|
-
desc 'Search anime by query from files'
|
13
|
-
argument :query, type: :string, required: true, desc: 'Search query'
|
14
|
-
|
15
|
-
def call(query:, **)
|
16
|
-
puts (LocalSearch.find_anime_by_query(query).map{ |anime| anime.to_json })
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
require_relative '../../query'
|
2
|
-
require_relative '../../show_list'
|
3
|
-
|
4
|
-
module Organo
|
5
|
-
module CLI
|
6
|
-
module Commands
|
7
|
-
module API
|
8
|
-
module Search
|
9
|
-
|
10
|
-
class Anime < Dry::CLI::Command
|
11
|
-
desc "Get a list anime from query"
|
12
|
-
argument :query, type: :string, required: true, desc: "Search query"
|
13
|
-
option :type, type: :string, required: false, default: '', values: %w[tv movie ova special ona music], desc: "Type of anime"
|
14
|
-
option :limit, type: :integer, required: false, default: 5, desc: "Limit number of results"
|
15
|
-
|
16
|
-
def call(query:, type:, limit:, **)
|
17
|
-
json_obj = Query.search_anime(query, { 'type' => type, 'limit' => limit})
|
18
|
-
show_list = ShowList.create_search_show_list(json_obj)
|
19
|
-
puts show_list.to_json
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require_relative '../reader'
|
2
|
-
require_relative '../writer'
|
3
|
-
|
4
|
-
module Organo
|
5
|
-
module CLI
|
6
|
-
module Commands
|
7
|
-
|
8
|
-
class Merge < Dry::CLI::Command
|
9
|
-
desc "Merge edited seasonal files into one main file"
|
10
|
-
|
11
|
-
def call(*)
|
12
|
-
show_list = Reader.read_all_files
|
13
|
-
Writer.to_data_file(show_list, 'shows')
|
14
|
-
puts 'Edited files have been merged.'
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
data/lib/organo/reader.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'json'
|
4
|
-
require_relative 'config'
|
5
|
-
require_relative 'show'
|
6
|
-
|
7
|
-
module Organo
|
8
|
-
class Reader
|
9
|
-
def self.read_all_files
|
10
|
-
shows = []
|
11
|
-
Dir["#{Config::DEFAULT_DIR}/*.json"].each do |file_path|
|
12
|
-
shows = shows.union(Reader.read_file(file_path))
|
13
|
-
end
|
14
|
-
shows.sort_by(&:title)
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.read_file(file_path)
|
18
|
-
shows = []
|
19
|
-
file = File.read(file_path)
|
20
|
-
data = JSON.parse(file)
|
21
|
-
data.each do |show|
|
22
|
-
shows.push(
|
23
|
-
Show.new(
|
24
|
-
show['id'],
|
25
|
-
show['slug'],
|
26
|
-
show['title'],
|
27
|
-
show['image_url'],
|
28
|
-
show['search_query'],
|
29
|
-
show['links'],
|
30
|
-
show['sequels']
|
31
|
-
)
|
32
|
-
)
|
33
|
-
end
|
34
|
-
shows
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
38
|
-
end
|
data/lib/organo/search_show.rb
DELETED
@@ -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/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
|