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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1babd85ffac4bb77177ade8a0a7f568ef67715df76d4ec2bf224ce016a973ba1
|
4
|
+
data.tar.gz: 967d6eafa28f342d82032a70a8452595239f01deb43525c211c56bba6f7ee6d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
5
|
+
Add anime entry to database.
|
6
6
|
```shell
|
7
7
|
organo anime add MAL_ID
|
8
8
|
```
|
9
9
|
|
10
|
-
##
|
10
|
+
## set_sequel
|
11
11
|
|
12
|
-
|
12
|
+
Sets anime as sequel and creates a sequel entry to database.
|
13
13
|
```shell
|
14
|
-
organo anime
|
14
|
+
organo anime set_sequel PARENT_MAL_ID CHILD_MAL_ID
|
15
15
|
```
|
16
16
|
|
17
|
-
##
|
17
|
+
## find_broken_links
|
18
18
|
|
19
19
|
Get list of anime IDs that have broken links.
|
20
20
|
```shell
|
21
|
-
organo anime
|
21
|
+
organo anime find_broken_links
|
22
22
|
```
|
23
23
|
|
24
24
|
## remove
|
25
|
-
|
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
|
-
|
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
|
6
|
+
- Manage and browse the database.
|
7
7
|
- [API](api.md)
|
8
|
-
- Get data from
|
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
|
-
|
2
|
-
|
3
|
-
require_relative '../../
|
4
|
-
require_relative '../../tools/
|
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
|
-
|
13
|
-
|
14
|
-
|
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
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
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
|
-
|
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
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
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
|
-
|
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
|
9
|
-
desc 'Show anime entry
|
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
|
-
|
14
|
-
|
15
|
-
|
16
|
-
show
|
17
|
-
|
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
|
-
|
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
|
-
|
17
|
-
|
18
|
-
|
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
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
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
|
-
|
2
|
-
|
3
|
-
|
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
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
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
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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
|
12
|
-
argument :mal_id, type: :integer, required: true, desc:
|
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
|
-
|
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
|
12
|
-
argument :season, type: :string, required: true, desc:
|
13
|
-
argument :year, type: :integer, required: true, desc:
|
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
|
-
|
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
|
12
|
-
argument :mal_id, type: :integer, required: true, desc:
|
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
|
-
|
16
|
-
puts sequels.to_json
|
16
|
+
puts Query.get_anime_sequel(mal_id)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
data/lib/organo/commands/init.rb
CHANGED
@@ -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
|
10
|
+
desc 'Initialize database'
|
7
11
|
|
8
12
|
def call(*)
|
9
13
|
Dir.mkdir './.organo' unless File.exist?('./.organo')
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
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
|
9
|
-
desc
|
10
|
-
argument :env, type: :string, required: true, desc:
|
11
|
-
argument :url, type: :string, required: true, desc:
|
12
|
-
option :username, type: :string, default: '', desc:
|
13
|
-
option :password, type: :string, default: '', desc:
|
14
|
-
option :directory, type: :string, default: '', desc:
|
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)) :
|
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
|
-
|
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
|
10
|
-
argument :env, type: :string, required: true, desc:
|
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
|
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?('
|
26
|
-
File.delete('
|
27
|
-
File.rename('
|
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('
|
32
|
+
ftp.getbinaryfile('dkb_edited.db')
|
30
33
|
end
|
31
34
|
end
|
32
35
|
end
|