organo 0.3.4 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/doc/anime.md +30 -8
  3. data/doc/readme.md +2 -2
  4. data/lib/organo/commands/anime/anime_add.rb +27 -22
  5. data/lib/organo/commands/anime/anime_find_broken_links.rb +31 -0
  6. data/lib/organo/commands/anime/anime_remove.rb +12 -12
  7. data/lib/organo/commands/anime/anime_set_sequel.rb +49 -0
  8. data/lib/organo/commands/anime/anime_show.rb +11 -13
  9. data/lib/organo/commands/anime/anime_update_image.rb +18 -33
  10. data/lib/organo/commands/anime/anime_update_query.rb +18 -19
  11. data/lib/organo/commands/api/api_get_anime.rb +5 -6
  12. data/lib/organo/commands/api/api_get_season.rb +6 -7
  13. data/lib/organo/commands/api/api_get_sequels.rb +5 -5
  14. data/lib/organo/commands/init.rb +32 -8
  15. data/lib/organo/commands/remote/remote_add.rb +14 -14
  16. data/lib/organo/commands/remote/remote_download.rb +10 -7
  17. data/lib/organo/commands/remote/remote_remove.rb +6 -4
  18. data/lib/organo/commands/remote/remote_upload.rb +6 -3
  19. data/lib/organo/commands/statistics.rb +8 -12
  20. data/lib/organo/commands/version.rb +3 -1
  21. data/lib/organo/query.rb +0 -1
  22. data/lib/organo/tools/string_utils.rb +28 -0
  23. data/lib/organo/{writer.rb → tools/writer.rb} +0 -5
  24. data/lib/organo/version.rb +1 -1
  25. data/lib/organo.rb +33 -47
  26. metadata +37 -17
  27. data/lib/organo/commands/anime/anime_add_sequel.rb +0 -50
  28. data/lib/organo/commands/anime/anime_get_broken_links.rb +0 -30
  29. data/lib/organo/commands/anime/anime_search.rb +0 -23
  30. data/lib/organo/commands/api/api_search_anime.rb +0 -27
  31. data/lib/organo/commands/merge.rb +0 -20
  32. data/lib/organo/reader.rb +0 -38
  33. data/lib/organo/search_show.rb +0 -58
  34. data/lib/organo/sequel.rb +0 -39
  35. data/lib/organo/show.rb +0 -36
  36. data/lib/organo/show_list.rb +0 -32
  37. data/lib/organo/tools/local_search.rb +0 -49
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f7145d1efb8ac5804c2c0d786c2854dd9d92b209fceb33ca02192ae86fe0e65a
4
- data.tar.gz: 77ff5845dd17c7ec583cbe5dace3833e52c3ca02e3d36b1b479d2140a97d908e
3
+ metadata.gz: 1babd85ffac4bb77177ade8a0a7f568ef67715df76d4ec2bf224ce016a973ba1
4
+ data.tar.gz: 967d6eafa28f342d82032a70a8452595239f01deb43525c211c56bba6f7ee6d8
5
5
  SHA512:
6
- metadata.gz: 03c4f273847259ab1af9319ec390df5badfdcf448a9208bb20992b5e1b3d8d06bd7a22580a1c54bdd7268e0595825d560ae9269bf8556b1c9178967e03aa9a26
7
- data.tar.gz: 5003d8cbac8a154dbcb57c2698504b86faef172a705d20b9d070f786a70c0ac53013e7ac5e24dac9699fec73808bcc244e1721531a43a47d5364459f3560213e
6
+ metadata.gz: 8f7a73df4cdb8163e61a720434693a2411500d087bc4da5fcddd61c4e7272ae0c65aee956b640a79afeba3bc96c3045f97f0a476d037d584e1632036ddc0298b
7
+ data.tar.gz: 7331b6d1abf07bf24d521efd5babcc552f38d9df151108c731f4a0b1c8035c729b7267ecbe43ae4e433b1ccb65d8d90c3424017e7fed4ffedd63dff04cb535ce
data/doc/anime.md CHANGED
@@ -2,27 +2,49 @@
2
2
 
3
3
  ## add
4
4
 
5
- Add anime entry to files.
5
+ Add anime entry to database.
6
6
  ```shell
7
7
  organo anime add MAL_ID
8
8
  ```
9
9
 
10
- ## add sequel
10
+ ## set_sequel
11
11
 
12
- Add anime sequel entry to anime in file.
12
+ Sets anime as sequel and creates a sequel entry to database.
13
13
  ```shell
14
- organo anime add sequel ANIME_MAL_ID SEQUEL_MAL_ID
14
+ organo anime set_sequel PARENT_MAL_ID CHILD_MAL_ID
15
15
  ```
16
16
 
17
- ## get broken_links
17
+ ## find_broken_links
18
18
 
19
19
  Get list of anime IDs that have broken links.
20
20
  ```shell
21
- organo anime get broken_links
21
+ organo anime find_broken_links
22
22
  ```
23
23
 
24
24
  ## remove
25
- ## search
25
+
26
+ Remove anime entry from database.
27
+ ```shell
28
+ organo anime remove MAL_ID
29
+ ```
30
+
26
31
  ## show
32
+
33
+ Shows anime database entry in console.
34
+ ```shell
35
+ organo anime show MAL_ID
36
+ ```
37
+
27
38
  ## update image
28
- ## update query
39
+
40
+ Updates the `img_url` column of one or more anime to URL from the API.
41
+ ```shell
42
+ organo anime update image MAL_ID [...]
43
+ ```
44
+
45
+ ## update query
46
+
47
+ Updates the `search_query` column of anime to specified string.
48
+ ```shell
49
+ organo anime update query MAL_ID SEARCH_QUERY
50
+ ```
data/doc/readme.md CHANGED
@@ -3,9 +3,9 @@
3
3
  The tool is broken into 4 main subcommands.
4
4
 
5
5
  - [Anime](anime.md)
6
- - Manage and browse the local data files.
6
+ - Manage and browse the database.
7
7
  - [API](api.md)
8
- - Get data from Jikan API.
8
+ - Get data from APIs.
9
9
  - [Remote](remote.md)
10
10
  - Add FTP remote information to push the data to the website.
11
11
  - [Schedule](schedule.md)
@@ -1,35 +1,40 @@
1
- require_relative '../../config'
2
- require_relative '../../writer'
3
- require_relative '../../reader'
4
- require_relative '../../tools/local_search'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../query'
4
+ require_relative '../../tools/string_utils'
5
+ require 'sequel'
5
6
 
6
7
  module Organo
7
8
  module CLI
8
9
  module Commands
9
10
  module Anime
10
- module Add
11
11
 
12
- class AnimeEntry < Dry::CLI::Command
13
- desc 'Add anime entry to files'
14
- argument :mal_id, type: :integer, required: true, desc: 'MyAnimeList ID'
12
+ class AddEntry < Dry::CLI::Command
13
+ desc 'Add anime entry'
14
+ argument :mal_id, type: :integer, required: true, desc: 'MyAnimeList ID'
15
15
 
16
- def call(mal_id:, **)
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) : []
24
- Writer.to_file(show_list.push(show).sort_by(&:title), file_path)
25
- puts "Added anime \"#{show.title}\" (#{mal_id}) in #{file_path}"
26
- else
27
- puts 'Cannot add an already existing anime'
28
- end
16
+ def call(mal_id:, **)
17
+ db = Sequel.sqlite('./dkb_edited.db')
18
+ shows = db.from(:shows).where(mal_id: mal_id)
19
+ if shows.count.zero?
20
+ show_json = Query.get_anime_by_id(mal_id)
21
+ db.from(:shows).insert(
22
+ mal_id: show_json['mal_id'].to_i,
23
+ slug: StringUtils.create_slug(show_json['title']),
24
+ title: show_json['title'],
25
+ img_url: show_json['images']['jpg']['image_url'],
26
+ search_query: show_json['title'].gsub(':', ' -'),
27
+ is_sequel: false
28
+ )
29
+ shows = db.from(:shows).where(mal_id: mal_id)
30
+ puts 'Show has been added to database'
31
+ else
32
+ puts 'This show already exists'
29
33
  end
34
+ puts shows.first
30
35
  end
31
-
32
36
  end
37
+
33
38
  end
34
39
  end
35
40
  end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'httparty'
4
+ require 'sequel'
5
+
6
+ module Organo
7
+ module CLI
8
+ module Commands
9
+ module Anime
10
+
11
+ class FindBrokenLinks < Dry::CLI::Command
12
+ desc 'Get list of anime IDs that have broken links'
13
+
14
+ def call(*)
15
+ db = Sequel.sqlite('dkb_edited.db')
16
+ shows = db.from(:shows)
17
+ broken_list = []
18
+ shows.each do |show|
19
+ response = HTTParty.get(show[:img_url])
20
+ next unless response.code == 404
21
+
22
+ broken_list.push(show[:mal_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
@@ -1,24 +1,24 @@
1
- require_relative '../../config'
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
  module Anime
7
-
8
- class Remove < Dry::CLI::Command
9
+ class RemoveEntry < Dry::CLI::Command
9
10
  desc 'Remove anime entry from files'
10
11
  argument :mal_id, type: :integer, required: true, desc: 'MyAnimeList ID'
11
12
 
12
13
  def call(mal_id:, **)
13
- Dir["#{Config::DEFAULT_DIR}/*.json"].each do |file_path|
14
- shows_list = Reader.read_file(file_path)
15
- show_index = shows_list.find_index { |s| s.id.to_s == mal_id.to_s }
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
14
+ db = Sequel.sqlite('./dkb_edited.db')
15
+ shows = db.from(:shows).where(mal_id: mal_id)
16
+ if shows.count.zero?
17
+ puts 'This show doesn\'t exist.'
18
+ else
19
+ puts 'Removed show.'
20
+ puts shows.first
21
+ shows.delete
22
22
  end
23
23
  end
24
24
  end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'sequel'
4
+
5
+ module Organo
6
+ module CLI
7
+ module Commands
8
+ module Anime
9
+
10
+ class SequelEntry < Dry::CLI::Command
11
+ desc 'Set show entry as sequel to another show'
12
+ argument :parent_id, type: :integer, required: true, desc: 'Anime MyAnimeList ID'
13
+ argument :child_id, type: :integer, required: true, desc: 'Sequel MyAnimeList ID'
14
+ argument :type, type: :string, required: false, default: 'season', values: %w[season movie ova], desc: 'Type of sequel (season, movie, ova)'
15
+ argument :type_num, type: :integer, required: false, default: 0, desc: 'The sequel type number'
16
+ argument :subtype, type: :string, required: false, default: '', values: %w[part special ova], desc: 'Type of sequel (part, special, ova)'
17
+ argument :subtype_num, type: :integer, required: false, default: 0, desc: 'The sequel subtype number'
18
+ argument :subtype_selector, type: :integer, required: false, default: -1, desc: 'The sequel subtype selector'
19
+
20
+ def call(parent_id:, child_id:, type:, type_num:, subtype:, subtype_num:, subtype_selector:, **)
21
+ db = Sequel.sqlite('dkb_edited.db')
22
+ parent_show = db.from(:shows).where(mal_id: parent_id)
23
+ child_show = db.from(:shows).where(mal_id: child_id)
24
+ if parent_show.count.positive? && child_show.count.positive?
25
+ if db.from(:sequels).where(parent_id: parent_id, child_id: child_id).count.positive?
26
+ puts 'This sequel entry already exist.'
27
+ else
28
+ db.from(:sequels).insert(
29
+ parent_id: parent_id,
30
+ child_id: child_id,
31
+ type: type,
32
+ type_num: type_num,
33
+ subtype: subtype,
34
+ subtype_num: subtype_num,
35
+ subtype_selector: subtype_selector
36
+ )
37
+ child_show.update(is_sequel: true)
38
+ puts "#{child_show.first[:title]}(#{child_show.first[:mal_id]}) is now a sequel to #{parent_show.first[:title]}(#{parent_show.first[:mal_id]})"
39
+ end
40
+ else
41
+ puts "Parent or child show doesn't exist."
42
+ end
43
+ end
44
+
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -1,26 +1,24 @@
1
- require_relative '../../config'
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
  module Anime
7
9
 
8
- class Show < Dry::CLI::Command
9
- desc 'Show anime entry from files'
10
+ class ShowEntry < Dry::CLI::Command
11
+ desc 'Show anime entry'
10
12
  argument :mal_id, type: :integer, required: true, desc: 'MyAnimeList ID'
11
13
 
12
14
  def call(mal_id:, **)
13
- found = false
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.id.to_s == mal_id.to_s }
17
- next if show.nil?
18
-
19
- found = true
20
- puts show.to_json
21
- break
15
+ db = Sequel.sqlite('dkb_edited.db')
16
+ show = db.from(:shows).where(mal_id: mal_id)
17
+ if show.count.positive?
18
+ puts show.first
19
+ else
20
+ puts "ID #{mal_id} doesn't exist in the database."
22
21
  end
23
- puts 'Entry not found.' unless found
24
22
  end
25
23
  end
26
24
 
@@ -1,48 +1,33 @@
1
- require_relative '../../config'
1
+ # frozen_string_literal: true
2
+
3
+ require 'sequel'
2
4
  require_relative '../../query'
3
- require_relative '../../writer'
4
- require_relative '../../reader'
5
5
 
6
6
  module Organo
7
7
  module CLI
8
8
  module Commands
9
9
  module Anime
10
- module Update
11
-
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'
15
10
 
16
- def call(mal_id_list:, **)
17
- found = false
18
- Dir["#{Config::DEFAULT_DIR}/*.json"].each do |file_path|
19
- shows_list = Reader.read_file(file_path)
20
- mal_id_list.each_with_index do |mal_id, index|
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
27
- next if show.nil?
11
+ class UpdateImage < Dry::CLI::Command
12
+ desc 'Update cover image for the specified anime'
13
+ argument :mal_id_list, type: :array, required: true, desc: 'MyAnimeList ID list'
28
14
 
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
37
- Writer.to_file(shows_list, file_path)
38
- sleep(1) if mal_id_list.size > 1 && index < (mal_id.size - 1)
39
- end
15
+ def call(mal_id_list:, **)
16
+ db = Sequel.sqlite('dkb_edited.db')
17
+ mal_id_list.each do |mal_id|
18
+ show = db.from(:shows).where(mal_id: mal_id)
19
+ api_image = Query.get_anime_image(mal_id)
20
+ if show.count.positive?
21
+ show.update(img_url: api_image)
22
+ puts "Updated image of #{show.first[:title]} (#{mal_id})"
23
+ puts api_image
24
+ else
25
+ puts "ID #{mal_id} doesn't exist in the database."
40
26
  end
41
- puts found ? 'Cover image(s) has been updated.' : 'Entry not found.'
42
27
  end
43
28
  end
44
-
45
29
  end
30
+
46
31
  end
47
32
  end
48
33
  end
@@ -1,32 +1,31 @@
1
- require_relative '../../config'
2
- require_relative '../../writer'
3
- require_relative '../../reader'
1
+ # frozen_string_literal: true
2
+
3
+ require 'sequel'
4
4
 
5
5
  module Organo
6
6
  module CLI
7
7
  module Commands
8
8
  module Anime
9
- module Update
10
-
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'
15
9
 
16
- def call(mal_id:, search_query:, **)
17
- Dir["#{Config::DEFAULT_DIR}/*.json"].each do |file_path|
18
- shows_list = Reader.read_file(file_path)
19
- show = shows_list.find { |s| s.id.to_s == mal_id.to_s }
20
- next if show.nil?
10
+ class UpdateSearchQuery < Dry::CLI::Command
11
+ desc 'Update search query for the specified anime'
12
+ argument :mal_id, type: :integer, required: true, desc: 'MyAnimeList ID'
13
+ argument :search_query, type: :string, required: true, desc: 'String query for Nyaa Torrents search'
21
14
 
22
- show.search_query = search_query
23
- Writer.to_file(shows_list, file_path)
24
- puts 'Search query has been updated.'
25
- end
15
+ def call(mal_id:, search_query:, **)
16
+ db = Sequel.sqlite('dkb_edited.db')
17
+ show = db.from(:shows).where(mal_id: mal_id)
18
+ if show.count.positive?
19
+ old_query = show.first[:search_query]
20
+ show.update(search_query: search_query)
21
+ puts "Updated search query of #{show.first[:title]} (#{mal_id})"
22
+ puts "#{old_query} --> #{search_query}"
23
+ else
24
+ puts "ID #{mal_id} doesn't exist in the database."
26
25
  end
27
26
  end
28
-
29
27
  end
28
+
30
29
  end
31
30
  end
32
31
  end
@@ -1,5 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative '../../query'
2
- require_relative '../../show_list'
3
4
 
4
5
  module Organo
5
6
  module CLI
@@ -8,13 +9,11 @@ module Organo
8
9
  module Get
9
10
 
10
11
  class Anime < Dry::CLI::Command
11
- desc "Get anime with specific ID from API"
12
- argument :mal_id, type: :integer, required: true, desc: "MyAnimeList ID"
12
+ desc 'Get anime with specific ID from API'
13
+ argument :mal_id, type: :integer, required: true, desc: 'MyAnimeList ID'
13
14
 
14
15
  def call(mal_id:, **)
15
- json_obj = Query.get_anime_by_id(mal_id)
16
- show = SearchShow.new(json_obj['mal_id'], json_obj['title'], json_obj['images']['jpg']['image_url'])
17
- puts show.to_json
16
+ puts Query.get_anime_by_id(mal_id)
18
17
  end
19
18
  end
20
19
 
@@ -1,5 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative '../../query'
2
- require_relative '../../show_list'
3
4
 
4
5
  module Organo
5
6
  module CLI
@@ -8,14 +9,12 @@ module Organo
8
9
  module Get
9
10
 
10
11
  class Season < Dry::CLI::Command
11
- desc "Get list of anime for a specific season"
12
- argument :season, type: :string, required: true, desc: "Winter, Spring, Summer or Fall"
13
- argument :year, type: :integer, required: true, desc: "Year"
12
+ desc 'Get list of anime for a specific season'
13
+ argument :season, type: :string, required: true, desc: 'Winter, Spring, Summer or Fall'
14
+ argument :year, type: :integer, required: true, desc: 'Year'
14
15
 
15
16
  def call(season:, year:, **)
16
- json_obj = Query.get_anime_season(season, year)
17
- show_list = ShowList.create_search_show_list(json_obj)
18
- puts show_list.to_json
17
+ puts Query.get_anime_season(season, year)
19
18
  end
20
19
  end
21
20
 
@@ -1,5 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative '../../query'
2
- require_relative '../../show_list'
3
4
 
4
5
  module Organo
5
6
  module CLI
@@ -8,12 +9,11 @@ module Organo
8
9
  module Get
9
10
 
10
11
  class Sequels < Dry::CLI::Command
11
- desc "Get list of sequels for a specific anime"
12
- argument :mal_id, type: :integer, required: true, desc: "MyAnimeList ID"
12
+ desc 'Get list of sequels for a specific anime'
13
+ argument :mal_id, type: :integer, required: true, desc: 'MyAnimeList ID'
13
14
 
14
15
  def call(mal_id:, **)
15
- sequels = ShowList.create_search_sequel_list(Query.get_anime_sequel(mal_id))
16
- puts sequels.to_json
16
+ puts Query.get_anime_sequel(mal_id)
17
17
  end
18
18
  end
19
19
 
@@ -1,19 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'sequel'
4
+
1
5
  module Organo
2
6
  module CLI
3
7
  module Commands
4
8
 
5
9
  class Init < Dry::CLI::Command
6
- desc "Initialize directory with default files and directories"
10
+ desc 'Initialize database'
7
11
 
8
12
  def call(*)
9
13
  Dir.mkdir './.organo' unless File.exist?('./.organo')
10
- Dir.mkdir './.organo/datafiles' unless File.exist?('./.organo/datafiles')
11
- File.write(
12
- './shows.config.json',
13
- '{"last_id":0,"schema":{"id":"integer","slug":"string","title":"string",' \
14
- '"image_url":"string","sequels":"string","search_query":"string"}}'
15
- )
16
- puts 'Initialized organo directory'
14
+
15
+ db = Sequel.sqlite('dkb_edited.db')
16
+ unless db.table_exists?(:shows)
17
+ db.create_table(:shows) do
18
+ Integer :mal_id
19
+ String :slug, unique: true, null: true
20
+ String :title
21
+ String :img_url
22
+ String :search_query, null: true
23
+ Boolean :is_sequel
24
+ primary_key %i[mal_id]
25
+ end
26
+ end
27
+
28
+ unless db.table_exists?(:sequels)
29
+ db.create_table(:sequels) do
30
+ Integer :parent_id
31
+ Integer :child_id
32
+ String :type, default: 'season'
33
+ Integer :type_num, default: 0
34
+ String :subtype, default: ''
35
+ Integer :subtype_num, default: 0
36
+ Integer :subtype_selector, default: -1
37
+ primary_key %i[parent_id child_id]
38
+ end
39
+ end
40
+
17
41
  end
18
42
  end
19
43
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative '../../config'
2
4
 
3
5
  module Organo
@@ -5,28 +7,26 @@ module Organo
5
7
  module Commands
6
8
  module Remote
7
9
 
8
- class Add < Dry::CLI::Command
9
- desc "Add remote FTP server to config file"
10
- argument :env, type: :string, required: true, desc: "Remote environment name"
11
- argument :url, type: :string, required: true, desc: "FTP server url"
12
- option :username, type: :string, default: '', desc: "FTP account username"
13
- option :password, type: :string, default: '', desc: "FTP account password"
14
- option :directory, type: :string, default: '', desc: "FTP directory"
10
+ class AddEntry < Dry::CLI::Command
11
+ desc 'Add remote FTP server to config file'
12
+ argument :env, type: :string, required: true, desc: 'Remote environment name'
13
+ argument :url, type: :string, required: true, desc: 'FTP server url'
14
+ option :username, type: :string, default: '', desc: 'FTP account username'
15
+ option :password, type: :string, default: '', desc: 'FTP account password'
16
+ option :directory, type: :string, default: '', desc: 'FTP directory'
15
17
 
16
18
  def call(env:, url:, username:, password:, directory:, **)
17
- config = File.exist?(Config::DEFAULT_FILE) ? JSON.parse(File.read(Config::DEFAULT_FILE)) : Array.new
19
+ config = File.exist?(Config::DEFAULT_FILE) ? JSON.parse(File.read(Config::DEFAULT_FILE)) : []
18
20
  section = config.find { |option| option['section'] == 'remotes' }
19
21
  remote = { env: env, url: url, username: username, password: password, directory: directory }
20
22
  if section.nil?
21
- section = { section: 'remotes', entries: []}
23
+ section = { section: 'remotes', entries: [] }
22
24
  config.push(section)
23
25
  section[:entries].push(remote)
26
+ elsif section['entries'].find { |entry| entry['env'] == env }.nil?
27
+ section['entries'].push(remote)
24
28
  else
25
- if section['entries'].find { |entry| entry['env'] == env }.nil?
26
- section['entries'].push(remote)
27
- else
28
- puts 'Environment name is already used'
29
- end
29
+ puts 'Environment name is already used'
30
30
  end
31
31
  File.write(Config::DEFAULT_FILE, JSON.pretty_generate(config))
32
32
  end
@@ -1,4 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'net/ftp'
4
+ require_relative '../../config'
2
5
 
3
6
  module Organo
4
7
  module CLI
@@ -6,14 +9,14 @@ module Organo
6
9
  module Remote
7
10
 
8
11
  class Download < Dry::CLI::Command
9
- desc "Download data from website"
10
- argument :env, type: :string, required: true, desc: "Environment"
12
+ desc 'Download data from website'
13
+ argument :env, type: :string, required: true, desc: 'Environment'
11
14
 
12
15
  def call(env:, **)
13
16
  config = File.exist?(Config::DEFAULT_FILE) ? JSON.parse(File.read(Config::DEFAULT_FILE)) : nil
14
17
  section = config.find { |option| option['section'] == 'remotes' }
15
18
  if section.nil?
16
- puts "No remote is configured in the configuration file"
19
+ puts 'No remote is configured in the configuration file'
17
20
  else
18
21
  credentials = section['entries'].find { |entry| entry['env'] == env }
19
22
  if credentials.nil?
@@ -22,11 +25,11 @@ module Organo
22
25
  Net::FTP.open(credentials['url']) do |ftp|
23
26
  ftp.login(credentials['username'], credentials['password'])
24
27
  ftp.chdir(credentials['directory'])
25
- if File.exist?('shows.data.json')
26
- File.delete('shows.data.json.old') if File.exist?('shows.data.json.old')
27
- File.rename('shows.data.json', 'shows.data.json.old')
28
+ if File.exist?('dkb_edited.db')
29
+ File.delete('dkb_edited.db.old') if File.exist?('dkb_edited.db.old')
30
+ File.rename('dkb_edited.db', 'dkb_edited.db.old')
28
31
  end
29
- ftp.getbinaryfile('shows.data.json')
32
+ ftp.getbinaryfile('dkb_edited.db')
30
33
  end
31
34
  end
32
35
  end