organo 0.3.2 → 0.3.4

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: 8691436aa9cdcb12c5de1da33b147103bcfa5d2459a3ad6b0ad868b4b49b2b44
4
- data.tar.gz: 3f1b7419aaee87053d5b74f0227e6b9c5e4c36d783b672dafebbd6f3d1c07091
3
+ metadata.gz: f7145d1efb8ac5804c2c0d786c2854dd9d92b209fceb33ca02192ae86fe0e65a
4
+ data.tar.gz: 77ff5845dd17c7ec583cbe5dace3833e52c3ca02e3d36b1b479d2140a97d908e
5
5
  SHA512:
6
- metadata.gz: 7e3e5e6c5e8898ab4552bd2b9cf108aef4de0075f13e5e1731cf4bda3917534cc19c88ecfc545ac41396d7f33e01311408d600b33e2331bbbfcd28a2f4decdad
7
- data.tar.gz: 14046ec16b3a0986312e78567e226089346d1bba28a0d05b0c10996d7916e7c5a9787f9312ce567dcbf0f588f43485b17a57df2d0b526eb4ddacde29b9810bb7
6
+ metadata.gz: 03c4f273847259ab1af9319ec390df5badfdcf448a9208bb20992b5e1b3d8d06bd7a22580a1c54bdd7268e0595825d560ae9269bf8556b1c9178967e03aa9a26
7
+ data.tar.gz: 5003d8cbac8a154dbcb57c2698504b86faef172a705d20b9d070f786a70c0ac53013e7ac5e24dac9699fec73808bcc244e1721531a43a47d5364459f3560213e
data/README.md CHANGED
@@ -2,6 +2,27 @@
2
2
 
3
3
  Organo is named after the mafia group that runs the city of Lux in the anime [Texhnolyze](https://myanimelist.net/anime/26/Texhnolyze).
4
4
 
5
- This tool has been made to manage data that is shown on the DKB Anime Community website. It uses to the [JikanAPI](https://jikan.moe), an unofficial MyAnimeList API, to get data.
5
+ ## Description
6
6
 
7
- **This tool is still under construction. Documentation is coming soon.**
7
+ This tool has been made to manage data that is shown on the DKB Anime Community website. It uses to the [JikanAPI](https://jikan.moe), an unofficial MyAnimeList API, and [AnimeSchedule](https://animeschedule.net) to get data.
8
+
9
+ **This tool is still under construction.**
10
+
11
+ ## Requirements
12
+
13
+ - Ruby 3.0+
14
+
15
+ Earlier versions of ruby might work, but the tool will not be tested against them.
16
+
17
+ ## Installation
18
+
19
+ The tool is available through [Rubygems](https://rubygems.org)
20
+ ```shell
21
+ gem install organo
22
+ ```
23
+
24
+ ## Documentation
25
+
26
+ **Documentation is still incomplete.**
27
+
28
+ The documentation is available in the `doc/` directory. Follow this [link](doc/readme.md).
data/doc/anime.md ADDED
@@ -0,0 +1,28 @@
1
+ # Anime
2
+
3
+ ## add
4
+
5
+ Add anime entry to files.
6
+ ```shell
7
+ organo anime add MAL_ID
8
+ ```
9
+
10
+ ## add sequel
11
+
12
+ Add anime sequel entry to anime in file.
13
+ ```shell
14
+ organo anime add sequel ANIME_MAL_ID SEQUEL_MAL_ID
15
+ ```
16
+
17
+ ## get broken_links
18
+
19
+ Get list of anime IDs that have broken links.
20
+ ```shell
21
+ organo anime get broken_links
22
+ ```
23
+
24
+ ## remove
25
+ ## search
26
+ ## show
27
+ ## update image
28
+ ## update query
data/doc/api.md ADDED
@@ -0,0 +1,6 @@
1
+ # API
2
+
3
+ ## get anime
4
+ ## get season
5
+ ## get sequels
6
+ ## search anime
data/doc/readme.md ADDED
@@ -0,0 +1,12 @@
1
+ # Organo documentation
2
+
3
+ The tool is broken into 4 main subcommands.
4
+
5
+ - [Anime](anime.md)
6
+ - Manage and browse the local data files.
7
+ - [API](api.md)
8
+ - Get data from Jikan API.
9
+ - [Remote](remote.md)
10
+ - Add FTP remote information to push the data to the website.
11
+ - [Schedule](schedule.md)
12
+ - Manage the weekly schedule.
data/doc/remote.md ADDED
@@ -0,0 +1,6 @@
1
+ # Remote
2
+
3
+ ## add
4
+ ## download
5
+ ## remove
6
+ ## upload
data/doc/schedule.md ADDED
@@ -0,0 +1,3 @@
1
+ # Schedule
2
+
3
+ ## create
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Organo
4
+ class AnimeScheduleAPI
5
+ BASE_URL = 'https://animeschedule.net/api/'
6
+
7
+ def self.get_url(endpoint, api_version = 'v3', key = '')
8
+ "#{BASE_URL}#{api_version}/#{endpoint}"
9
+ end
10
+ end
11
+ end
@@ -1,6 +1,7 @@
1
1
  require_relative '../../config'
2
2
  require_relative '../../writer'
3
3
  require_relative '../../reader'
4
+ require_relative '../../tools/local_search'
4
5
 
5
6
  module Organo
6
7
  module CLI
@@ -13,15 +14,15 @@ module Organo
13
14
  argument :mal_id, type: :integer, required: true, desc: 'MyAnimeList ID'
14
15
 
15
16
  def call(mal_id:, **)
16
- json_obj = Query.get_anime_by_id(mal_id)
17
- show = SearchShow.new(json_obj['mal_id'], json_obj['title'], json_obj['images']['jpg']['image_url'])
18
- show_type = json_obj['type']
19
- file_name = (show_type == 'TV' ? "#{json_obj['year']}_#{json_obj['season']}" : show_type.downcase)
20
- file_path = "#{Config::DEFAULT_DIR}/#{file_name}.json"
21
- show_list = File.exist?(file_path) ? Reader.read_file(file_path) : []
22
- if show_list.find_index { |s| s.id.to_s == mal_id.to_s }.nil?
17
+ if LocalSearch.find_anime_by_id(mal_id).nil?
18
+ json_obj = Query.get_anime_by_id(mal_id)
19
+ show = SearchShow.new(json_obj['mal_id'], json_obj['title'], json_obj['images']['jpg']['image_url'])
20
+ show_type = json_obj['type']
21
+ file_name = (show_type == 'TV' ? "#{json_obj['year']}_#{json_obj['season']}" : show_type.downcase)
22
+ file_path = "#{Config::DEFAULT_DIR}/#{file_name}.json"
23
+ show_list = File.exist?(file_path) ? Reader.read_file(file_path) : []
23
24
  Writer.to_file(show_list.push(show).sort_by(&:title), file_path)
24
- puts "Added anime \"#{show.title}\" (#{mal_id})"
25
+ puts "Added anime \"#{show.title}\" (#{mal_id}) in #{file_path}"
25
26
  else
26
27
  puts 'Cannot add an already existing anime'
27
28
  end
@@ -1,6 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative '../../config'
2
4
  require_relative '../../writer'
3
5
  require_relative '../../reader'
6
+ require_relative '../../tools/local_search'
4
7
 
5
8
  module Organo
6
9
  module CLI
@@ -17,21 +20,25 @@ module Organo
17
20
  argument :type_num, type: :integer, required: false, default: 0, desc: 'The sequel type number'
18
21
 
19
22
  def call(anime_mal_id:, sequel_mal_id:, season_num:, type:, type_num:, **)
20
- json_obj = Query.get_anime_by_id(sequel_mal_id)
21
- Dir["#{Config::DEFAULT_DIR}/*.json"].each do |file_path|
22
- shows_list = Reader.read_file(file_path)
23
- show = shows_list.find { |s| s.id.to_s == anime_mal_id.to_s }
24
- next if show.nil?
25
-
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
29
- sequel = Sequel.new(json_obj['mal_id'], json_obj['title'], json_obj['images']['jpg']['image_url'], season_num, type, type_num)
30
- show.sequels.push(sequel)
31
- Writer.to_file(shows_list, file_path)
32
- puts "Added sequel \"#{sequel.title}\" (#{sequel.id}) to anime."
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
33
36
  end
34
- break
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.'
35
42
  end
36
43
  end
37
44
  end
@@ -1,4 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative '../../config'
4
+ require_relative '../../tools/local_search'
2
5
 
3
6
  module Organo
4
7
  module CLI
@@ -10,13 +13,7 @@ module Organo
10
13
  argument :query, type: :string, required: true, desc: 'Search query'
11
14
 
12
15
  def call(query:, **)
13
- found_list = []
14
- Dir["#{Config::DEFAULT_DIR}/*.json"].each do |file_path|
15
- shows_list = Reader.read_file(file_path)
16
- show = shows_list.find { |s| s.title.downcase.include? query }
17
- found_list.push(show) unless show.nil?
18
- end
19
- puts found_list.to_json
16
+ puts (LocalSearch.find_anime_by_query(query).map{ |anime| anime.to_json })
20
17
  end
21
18
  end
22
19
 
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../config'
4
+ require_relative '../../animeschedule_api'
5
+
6
+ module Organo
7
+ module CLI
8
+ module Commands
9
+ module API
10
+ module Get
11
+
12
+ class Schedule < Dry::CLI::Command
13
+ desc 'Get anime release schedule of a specified season'
14
+ argument :season, type: :string, required: true, desc: 'Winter, Spring, Summer or Fall'
15
+ argument :year, type: :integer, required: true, desc: 'Year'
16
+
17
+ def call(season:, year:, **)
18
+ # Get the list of anime mal_id
19
+ # show_list = Reader.read_file("#{Config::DEFAULT_DIR}/#{year}-#{season.downcase}.json")
20
+
21
+ config = JSON.parse(File.read(Config::DEFAULT_FILE))
22
+ section = config.find { |option| option['section'] == 'api' }
23
+ key = (section['entries'].find { |entry| entry['name'] == 'AnimeSchedule' })['key']
24
+
25
+ count = 0
26
+ page = 1
27
+ total = 0
28
+ anime_list = []
29
+ loop do
30
+ data = JSON.parse(
31
+ RestClient.get(
32
+ "#{AnimeScheduleAPI.get_url('anime', 'v3')}?mt=all&years=#{year}&seasons=#{season}&media-types=tv&page=#{page}",
33
+ { Authorization: "Bearer #{key}" }
34
+ )
35
+ )
36
+ total = data['totalAmount'].to_i
37
+ page += 1
38
+ count += data['anime'].size
39
+ anime_list.concat(data['anime'])
40
+ break if count >= total
41
+ end
42
+
43
+ draft_schedule = []
44
+ anime_list.each do |anime|
45
+ air_time = DateTime.parse(anime['premier'])
46
+ draft_schedule.push(
47
+ {
48
+ slug: anime['route'],
49
+ title: anime['title'],
50
+ weekday: air_time.strftime('%A').downcase
51
+ }
52
+ )
53
+ end
54
+
55
+ file = File.read('schedule.json')
56
+ schedule = JSON.parse(file)
57
+ schedule.each do |weekday|
58
+ draft_schedule.each do |anime|
59
+ next unless anime[:weekday].eql? weekday['weekday']
60
+
61
+ weekday['shows'].push(
62
+ { slug: anime[:slug], title: anime[:title], time: '' }
63
+ )
64
+ end
65
+ end
66
+ Writer.to_file(schedule, 'schedule.json')
67
+ end
68
+ end
69
+
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
@@ -6,10 +6,10 @@ module Organo
6
6
  module Schedule
7
7
 
8
8
  class Create < Dry::CLI::Command
9
- desc "Initialize directory with default files and directories"
9
+ desc 'Initialize directory with default files and directories'
10
10
 
11
11
  def call(*)
12
- content = Array.new
12
+ content = []
13
13
  Date::DAYNAMES.each do |dname|
14
14
  content.push({ 'weekday' => dname.downcase, 'shows' => [] } )
15
15
  end
data/lib/organo/config.rb CHANGED
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Organo
2
4
  class Config
3
5
  DEFAULT_FILE = './.organo/config.json'
4
6
  DEFAULT_DIR = './.organo/datafiles'
5
7
  end
6
- end
8
+ end
@@ -8,4 +8,4 @@ module Organo
8
8
  "#{BASE_URL}#{api_version}/#{endpoint}"
9
9
  end
10
10
  end
11
- end
11
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ require_relative '../reader'
5
+
6
+ module Organo
7
+ class LocalSearch
8
+
9
+ def self.find_anime_by_id(mal_id)
10
+ anime_list = Reader.read_all_files
11
+ get_anime_obj(mal_id, anime_list)
12
+ end
13
+
14
+ def self.get_anime_obj(mal_id, anime_list)
15
+ return_value = nil
16
+ anime_list.each do |anime|
17
+ if anime.id == mal_id.to_i || anime.sequels.find { |sequel| sequel['id'] == mal_id.to_i }
18
+ return_value = anime
19
+ break
20
+ end
21
+ end
22
+ return_value
23
+ end
24
+
25
+ def self.find_file_by_anime_id(mal_id)
26
+ return_value = nil
27
+ Dir["#{Config::DEFAULT_DIR}/*.json"].each do |file_path|
28
+ anime_list = Reader.read_file(file_path)
29
+ unless get_anime_obj(mal_id, anime_list).nil?
30
+ return_value = file_path
31
+ break
32
+ end
33
+ end
34
+ return_value
35
+ end
36
+
37
+ def self.find_anime_by_query(query)
38
+ anime_list = Reader.read_all_files
39
+ return_value = []
40
+ anime_list.each do |anime|
41
+ if (anime.title.downcase.include? query.downcase) ||
42
+ (anime.sequels.find { |sequel| sequel['title'].downcase.include? query.downcase })
43
+ return_value.push(anime)
44
+ end
45
+ end
46
+ return_value
47
+ end
48
+ end
49
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Organo
4
- VERSION = '0.3.2'
4
+ VERSION = '0.3.4'
5
5
  end
data/lib/organo.rb CHANGED
@@ -13,6 +13,7 @@ require_relative 'organo/commands/api/api_get_anime'
13
13
  require_relative 'organo/commands/api/api_get_sequels'
14
14
  require_relative 'organo/commands/api/api_get_season'
15
15
  require_relative 'organo/commands/api/api_search_anime'
16
+ require_relative 'organo/commands/api/api_get_schedule'
16
17
  require_relative 'organo/commands/remote/remote_add'
17
18
  require_relative 'organo/commands/remote/remote_remove'
18
19
  require_relative 'organo/commands/remote/remote_download'
@@ -46,6 +47,7 @@ module Organo
46
47
  prefix.register 'get season', API::Get::Season
47
48
  prefix.register 'get sequels', API::Get::Sequels
48
49
  prefix.register 'search anime', API::Search::Anime
50
+ prefix.register 'get schedule', API::Get::Schedule
49
51
  end
50
52
  register 'merge', Merge
51
53
  register 'statistics', Statistics
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.2
4
+ version: 0.3.4
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-03-21 00:00:00.000000000 Z
11
+ date: 2023-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-cli
@@ -78,8 +78,14 @@ files:
78
78
  - Gemfile
79
79
  - LICENSE.txt
80
80
  - README.md
81
+ - doc/anime.md
82
+ - doc/api.md
83
+ - doc/readme.md
84
+ - doc/remote.md
85
+ - doc/schedule.md
81
86
  - exe/organo
82
87
  - lib/organo.rb
88
+ - lib/organo/animeschedule_api.rb
83
89
  - lib/organo/commands/anime/anime_add.rb
84
90
  - lib/organo/commands/anime/anime_add_sequel.rb
85
91
  - lib/organo/commands/anime/anime_get_broken_links.rb
@@ -89,6 +95,7 @@ files:
89
95
  - lib/organo/commands/anime/anime_update_image.rb
90
96
  - lib/organo/commands/anime/anime_update_query.rb
91
97
  - lib/organo/commands/api/api_get_anime.rb
98
+ - lib/organo/commands/api/api_get_schedule.rb
92
99
  - lib/organo/commands/api/api_get_season.rb
93
100
  - lib/organo/commands/api/api_get_sequels.rb
94
101
  - lib/organo/commands/api/api_search_anime.rb
@@ -110,6 +117,7 @@ files:
110
117
  - lib/organo/sequel.rb
111
118
  - lib/organo/show.rb
112
119
  - lib/organo/show_list.rb
120
+ - lib/organo/tools/local_search.rb
113
121
  - lib/organo/version.rb
114
122
  - lib/organo/writer.rb
115
123
  homepage: https://gitlab.com/dkb-weeblets/organo