tomosia_icon8_crawl 0.1.0 → 0.1.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 64b548596b79842fdf5f13b67ede80c078c9b59cbd2e7d152f903bb6c39f1e95
4
- data.tar.gz: '093cf7fc7e6c48529d4e6e51d128676b0657b012d7bf638e93ffe16032faf6f7'
3
+ metadata.gz: 1f31b322adad997e3fc62c5fb47c4c9c5053f8b56ce58843918de189b64bbebd
4
+ data.tar.gz: 35c6ee6157c954c09fc5223a33b909268bb6a00c9040734accee4881c6f7f4e9
5
5
  SHA512:
6
- metadata.gz: 25c6f7fb6908d44bac209b220e92213e8be54306492a28208ec4d01a655a3693cbbcd3156c091e2b2612039f8b8daf85c7b535641e28c56f505f7b3b145ad824
7
- data.tar.gz: 170d1aa030b0b71531ca65ca526fab66874c053d1ae743229a942c5e01bbb3cbfa689e00170ecbdc86e51460f6d7bdabd096645281b3a515789edbb959b88a37
6
+ metadata.gz: e7a13abfab173d318d405756a5d6637865d4eed4b0b8808690e81284d46dee3bc90deecfc691e3ef7e8e880984bf69bd5c0b2439d538581e3f25563f7aa0eae0
7
+ data.tar.gz: 8ce5c215458327b2723e40679c2463146f216149cc90b0157edd4d1cf235681a7daa08fb45421233b5eb1636100b3daa33ab59f550e918d69eb668978b5a7e95
data/.gitignore CHANGED
@@ -1,11 +1,11 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
9
-
10
- # rspec failure tracking
11
- .rspec_status
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec CHANGED
@@ -1,3 +1,3 @@
1
- --format documentation
2
- --color
3
- --require spec_helper
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -1,6 +1,6 @@
1
- ---
2
- language: ruby
3
- cache: bundler
4
- rvm:
5
- - 2.7.1
6
- before_install: gem install bundler -v 2.1.4
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.1
6
+ before_install: gem install bundler -v 2.1.4
@@ -1,74 +1,74 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- In the interest of fostering an open and welcoming environment, we as
6
- contributors and maintainers pledge to making participation in our project and
7
- our community a harassment-free experience for everyone, regardless of age, body
8
- size, disability, ethnicity, gender identity and expression, level of experience,
9
- nationality, personal appearance, race, religion, or sexual identity and
10
- orientation.
11
-
12
- ## Our Standards
13
-
14
- Examples of behavior that contributes to creating a positive environment
15
- include:
16
-
17
- * Using welcoming and inclusive language
18
- * Being respectful of differing viewpoints and experiences
19
- * Gracefully accepting constructive criticism
20
- * Focusing on what is best for the community
21
- * Showing empathy towards other community members
22
-
23
- Examples of unacceptable behavior by participants include:
24
-
25
- * The use of sexualized language or imagery and unwelcome sexual attention or
26
- advances
27
- * Trolling, insulting/derogatory comments, and personal or political attacks
28
- * Public or private harassment
29
- * Publishing others' private information, such as a physical or electronic
30
- address, without explicit permission
31
- * Other conduct which could reasonably be considered inappropriate in a
32
- professional setting
33
-
34
- ## Our Responsibilities
35
-
36
- Project maintainers are responsible for clarifying the standards of acceptable
37
- behavior and are expected to take appropriate and fair corrective action in
38
- response to any instances of unacceptable behavior.
39
-
40
- Project maintainers have the right and responsibility to remove, edit, or
41
- reject comments, commits, code, wiki edits, issues, and other contributions
42
- that are not aligned to this Code of Conduct, or to ban temporarily or
43
- permanently any contributor for other behaviors that they deem inappropriate,
44
- threatening, offensive, or harmful.
45
-
46
- ## Scope
47
-
48
- This Code of Conduct applies both within project spaces and in public spaces
49
- when an individual is representing the project or its community. Examples of
50
- representing a project or community include using an official project e-mail
51
- address, posting via an official social media account, or acting as an appointed
52
- representative at an online or offline event. Representation of a project may be
53
- further defined and clarified by project maintainers.
54
-
55
- ## Enforcement
56
-
57
- Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
- reported by contacting the project team at tt.ninh.le@tomosia.com. All
59
- complaints will be reviewed and investigated and will result in a response that
60
- is deemed necessary and appropriate to the circumstances. The project team is
61
- obligated to maintain confidentiality with regard to the reporter of an incident.
62
- Further details of specific enforcement policies may be posted separately.
63
-
64
- Project maintainers who do not follow or enforce the Code of Conduct in good
65
- faith may face temporary or permanent repercussions as determined by other
66
- members of the project's leadership.
67
-
68
- ## Attribution
69
-
70
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
- available at [https://contributor-covenant.org/version/1/4][version]
72
-
73
- [homepage]: https://contributor-covenant.org
74
- [version]: https://contributor-covenant.org/version/1/4/
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at tt.ninh.le@tomosia.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile CHANGED
@@ -1,10 +1,10 @@
1
- source "https://rubygems.org"
2
-
3
- # Specify your gem's dependencies in tomosia_icon8_crawl.gemspec
4
- gemspec
5
-
6
- gem "rake", "~> 12.0"
7
- gem "rspec", "~> 3.0"
8
- gem 'writeexcel', '~> 1.0', '>= 1.0.5'
9
- gem 'pry', '~> 0.13.1'
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in tomosia_icon8_crawl.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
8
+ gem 'writeexcel', '~> 1.0', '>= 1.0.5'
9
+ gem 'pry', '~> 0.13.1'
10
10
  gem 'httparty', '~> 0.17.3'
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tomosia_icon8_crawl (0.1.0)
4
+ tomosia_icon8_crawl (0.1.4)
5
5
  httparty
6
6
  nokogiri
7
7
  pry
@@ -1,21 +1,21 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2020 ninh-tomosia
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 ninh-tomosia
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md CHANGED
@@ -22,7 +22,43 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
- TODO: Write usage instructions here
25
+ ### Commandline or Terminal:
26
+
27
+ Download all photos including pages from icon8.com with keyword you search
28
+
29
+ $ tomosia_icon8_crawl crawl "keyword" --destination="storage path"
30
+
31
+ Download pictures with number you want to get from icon8.com with keyword to find
32
+
33
+ $ tomosia_icon8_crawl crawl "keyword" --destination="storage path" --max=number
34
+
35
+ ### Developers:
36
+
37
+ Gemfile:
38
+
39
+ $ gem 'tomosia_icon8_crawl'
40
+
41
+ Require:
42
+
43
+ $ require 'tomosia_icon8_crawl'
44
+
45
+ Download all photos including pages from icon8.com with keyword you search
46
+
47
+ $ TomosiaIcon8Crawl::CrawlIcon8.crawl("keyword", "destination")
48
+
49
+ Download pictures with number you want to get from icon8.com with keyword to find
50
+
51
+ $ TomosiaIcon8Crawl::CrawlIcon8.crawl("keyword", "destination", max)
52
+
53
+ Help:
54
+ - keyword is the word used for searching.
55
+ ex: corona, car, virus,...
56
+ - destination is the path of the directory where the image was downloaded.
57
+ ex: E:\download, C:\download, C:\Desktop,...
58
+ - max max is the number of images you want to download.
59
+ ex: 100, 10, 5, 1000,...
60
+
61
+
26
62
 
27
63
  ## Development
28
64
 
data/Rakefile CHANGED
@@ -1,11 +1,11 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
-
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
- task :default => :spec
7
- namespace :gem do
8
- task :build do
9
- system "rake build && rake install"
10
- end
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+ namespace :gem do
8
+ task :build do
9
+ system "rake build && rake install"
10
+ end
11
11
  end
@@ -1,14 +1,14 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "tomosia_icon8_crawl"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start(__FILE__)
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "tomosia_icon8_crawl"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup CHANGED
@@ -1,8 +1,8 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -1,149 +1,152 @@
1
- module TomosiaIcon8Crawl
2
- require 'open-uri'
3
- require "HTTParty"
4
- require 'pry'
5
- require 'WriteExcel'
6
- class CrawlIcon8
7
-
8
- # get data from website
9
- def self.json(key, max)
10
- if key == nil
11
- p "No data!"
12
- else
13
- if max == nil
14
- url = "https://search.icons8.com/api/iconsets/v5/search?term=#{key}"
15
- else
16
- url = "https://search.icons8.com/api/iconsets/v5/search?term=#{key}&amount=#{max}"
17
- end
18
- end
19
-
20
- page_data = HTTParty.get(url)
21
- @responses = page_data.parsed_response
22
- end
23
-
24
- # save file to txt
25
- def self.save_file_txt(index, name, url, size, extension)
26
- File.open("log_image.txt", "a+") do |f|
27
- f.write("#{index}. name: #{name} | url: #{url} | size: #{size}Kb | extension: #{extension} \n")
28
- end
29
- end
30
-
31
- # save file to excel
32
- def self.save_file_excel( path, data = {})
33
- begin
34
- des = path + '/export.xls'
35
- workbook = WriteExcel.new(des)
36
- format = workbook.add_format
37
- format.set_bold()
38
- format.set_align('center')
39
-
40
- data_col = workbook.add_format
41
- data_col.set_align('center')
42
- format_url = workbook.add_format
43
- format_url.set_color('blue')
44
- format_url.set_align('center')
45
-
46
- worksheet = workbook.add_worksheet
47
-
48
- worksheet.write_string(0, 0, 'STT', format)
49
- worksheet.write_string(0, 1, 'NAME', format)
50
- worksheet.write_string(0, 2, 'URL', format)
51
- worksheet.write_string(0, 3, 'SIZE', format)
52
- worksheet.write_string(0, 4, 'EXTENSION', format)
53
-
54
- multi = []
55
- data.each_with_index do |row, index|
56
- i = index + 1
57
- # p i
58
- # p row
59
- multi << Thread.new do
60
- row.each do |key, value|
61
- # p key
62
-
63
- worksheet.write_string(i, 0, row['index'], data_col)
64
- worksheet.write_string(i, 1, row['name'], data_col)
65
- worksheet.write_url(i, 2, row['url'], format_url)
66
- worksheet.write_string(i, 3, row['size'], data_col)
67
- worksheet.write_string(i, 4, row['extension'], data_col)
68
- end
69
- end
70
- end
71
- multi.each{ |m| m.join }
72
-
73
- workbook.close
74
- rescue Exception => e
75
- p "Can't saved file"
76
- p e
77
- # break
78
- end
79
- end
80
-
81
- # download image
82
- def self.download_image(path, img)
83
- timeout = 0
84
- begin
85
- open(img) do |image|
86
- File.open(path, 'wb') do |file|
87
- file.write(image.read)
88
- @size = image.size
89
- p @size
90
- end
91
- end
92
- rescue
93
- if timeout < 5
94
- timeout += 1
95
- p "Retry download image"
96
- retry
97
- end
98
- end
99
- end
100
-
101
- # multi download image
102
- def self.multi_download_image(path, imgs)
103
- begin
104
- threads = []
105
- @data = []
106
-
107
- imgs.each_with_index do |img, index|
108
- # p index
109
- title = File.basename(img, '.png')
110
- des = path. + "/" + index.to_s + "-" + title + ".png"
111
- ext = File.extname(img).delete('.')
112
- threads << Thread.new do
113
- download_image(des, img)
114
- @size = @size.to_s + "byte"
115
- row = {"index" => index, "name" => title, "url" => img, "size" => @size, "extension" => ext}
116
- @data.push(row)
117
- end
118
- end
119
- threads.each{ |t| t.join }
120
- rescue Exception => e
121
- p "no data"
122
- p e
123
- end
124
- end
125
-
126
- # main
127
- def self.crawl(keyword = nil, path = ".", max = nil)
128
- begin
129
-
130
- images = []
131
- des = ""
132
- json(keyword, max)
133
- @responses['icons'].each_with_index do |item, index|
134
-
135
- src = "https://img.icons8.com/#{item['platform']}/2x/#{item['commonName']}.png"
136
-
137
- # add image
138
- images.push(src)
139
- end
140
-
141
- multi_download_image(path, images)
142
- save_file_excel(path, @data)
143
- rescue Exception => e
144
- p "--Runtime error--"
145
- p e
146
- end
147
- end
148
- end
1
+ module TomosiaIcon8Crawl
2
+ require 'open-uri'
3
+ require "HTTParty"
4
+ require 'pry'
5
+ require 'WriteExcel'
6
+ class CrawlIcon8
7
+
8
+ # get data from website
9
+ def self.json(key, max)
10
+ if key == nil
11
+ p "No data!"
12
+ else
13
+ if max == nil
14
+ urlc = 'https://search.icons8.com/api/iconsets/v5/search?term=' + key + '&amount=1'
15
+ page = HTTParty.get(urlc)
16
+ res = page.parsed_response
17
+ countAll = res['parameters']['countAll']
18
+ url = 'https://search.icons8.com/api/iconsets/v5/search?term=' + key + '&amount=' + countAll
19
+ else
20
+ url = 'https://search.icons8.com/api/iconsets/v5/search?term=' + key + '&amount=' + max
21
+ end
22
+ end
23
+
24
+ page_data = HTTParty.get(url)
25
+ @responses = page_data.parsed_response
26
+ end
27
+
28
+ # save file to txt
29
+ def self.save_file_txt(index, name, url, size, extension)
30
+ File.open("log_image.txt", "a+") do |f|
31
+ f.write("#{index}. name: #{name} | url: #{url} | size: #{size}Kb | extension: #{extension} \n")
32
+ end
33
+ end
34
+
35
+ # save file to excel
36
+ def self.save_file_excel( path, data = {})
37
+ begin
38
+ des = path + '/export.xls'
39
+ workbook = WriteExcel.new(des)
40
+ format = workbook.add_format
41
+ format.set_bold()
42
+ format.set_align('center')
43
+
44
+ data_col = workbook.add_format
45
+ data_col.set_align('center')
46
+ format_url = workbook.add_format
47
+ format_url.set_color('blue')
48
+ format_url.set_align('center')
49
+
50
+ worksheet = workbook.add_worksheet
51
+
52
+ worksheet.write_string(0, 0, 'STT', format)
53
+ worksheet.write_string(0, 1, 'NAME', format)
54
+ worksheet.write_string(0, 2, 'URL', format)
55
+ worksheet.write_string(0, 3, 'SIZE(byte)', format)
56
+ worksheet.write_string(0, 4, 'EXTENSION', format)
57
+
58
+ multi = []
59
+ data.each_with_index do |row, index|
60
+ i = index + 1
61
+ # p i
62
+ # p row
63
+ multi << Thread.new do
64
+ row.each do |key, value|
65
+ # p key
66
+
67
+ worksheet.write_string(i, 0, row['index'].to_s, data_col)
68
+ worksheet.write_string(i, 1, row['name'], data_col)
69
+ worksheet.write_url(i, 2, row['url'], format_url)
70
+ worksheet.write_string(i, 3, row['size'].to_s, data_col)
71
+ worksheet.write_string(i, 4, row['extension'], data_col)
72
+ end
73
+ end
74
+ end
75
+ multi.each{ |m| m.join }
76
+
77
+ workbook.close
78
+ rescue Exception => e
79
+ p "Can't saved file"
80
+ # p e
81
+ # break
82
+ end
83
+ end
84
+
85
+ # download image
86
+ def self.download_image(path, img)
87
+ timeout = 0
88
+ begin
89
+ open(img) do |image|
90
+ File.open(path, 'wb') do |file|
91
+ file.write(image.read)
92
+ @size = image.size
93
+ # p @size
94
+ end
95
+ end
96
+ rescue
97
+ if timeout < 5
98
+ timeout += 1
99
+ p "Retry download image"
100
+ retry
101
+ end
102
+ end
103
+ end
104
+
105
+ # multi download image
106
+ def self.multi_download_image(path, imgs)
107
+ begin
108
+ threads = []
109
+ @data = []
110
+
111
+ imgs.each_with_index do |img, index|
112
+ # p index
113
+ title = File.basename(img, '.png')
114
+ des = path. + "/" + index.to_s + "-" + title + ".png"
115
+ ext = File.extname(img).delete('.')
116
+ threads << Thread.new do
117
+ download_image(des, img)
118
+ row = {"index" => index, "name" => title, "url" => img, "size" => @size, "extension" => ext}
119
+ @data.push(row)
120
+ end
121
+ end
122
+ threads.each{ |t| t.join }
123
+ rescue Exception => e
124
+ p "no data"
125
+ p e
126
+ end
127
+ end
128
+
129
+ # main
130
+ def self.crawl(keyword = nil, path = ".", max = nil)
131
+ begin
132
+
133
+ images = []
134
+ des = ""
135
+ json(keyword, max)
136
+ @responses['icons'].each_with_index do |item, index|
137
+
138
+ src = "https://img.icons8.com/#{item['platform']}/2x/#{item['commonName']}.png"
139
+
140
+ # add image
141
+ images.push(src)
142
+ end
143
+
144
+ multi_download_image(path, images)
145
+ save_file_excel(path, @data)
146
+ rescue Exception => e
147
+ p "--Runtime error--"
148
+ p e
149
+ end
150
+ end
151
+ end
149
152
  end
@@ -8,7 +8,7 @@ module TomosiaIcon8Crawl
8
8
  option :destination
9
9
  option :max
10
10
  def crawl(keyword)
11
- TomosiaIcon8Crawl::CrawlIcon8.crawl(keyword, options[:destination], options[:max].to_i)
11
+ TomosiaIcon8Crawl::CrawlIcon8.crawl(keyword, options[:destination], options[:max])
12
12
  end
13
13
  end
14
14
  end
@@ -1,3 +1,3 @@
1
- module TomosiaIcon8Crawl
2
- VERSION = "0.1.0"
3
- end
1
+ module TomosiaIcon8Crawl
2
+ VERSION = "0.1.5"
3
+ end
@@ -1,18 +1,18 @@
1
- require "bundler/setup"
2
- require "tomosia_icon8_crawl"
3
-
4
- RSpec.configure do |config|
5
-
6
- config.treat_symbols_as_metadata_keys_with_true_values = true
7
- config.run_all_when_everything_filtered = true
8
- config.filter_run :focus
9
- # Enable flags like --only-failures and --next-failure
10
- config.example_status_persistence_file_path = ".rspec_status"
11
-
12
- # Disable RSpec exposing methods globally on `Module` and `main`
13
- config.disable_monkey_patching!
14
-
15
- config.expect_with :rspec do |c|
16
- c.syntax = :expect
17
- end
18
- end
1
+ require "bundler/setup"
2
+ require "tomosia_icon8_crawl"
3
+
4
+ RSpec.configure do |config|
5
+
6
+ config.treat_symbols_as_metadata_keys_with_true_values = true
7
+ config.run_all_when_everything_filtered = true
8
+ config.filter_run :focus
9
+ # Enable flags like --only-failures and --next-failure
10
+ config.example_status_persistence_file_path = ".rspec_status"
11
+
12
+ # Disable RSpec exposing methods globally on `Module` and `main`
13
+ config.disable_monkey_patching!
14
+
15
+ config.expect_with :rspec do |c|
16
+ c.syntax = :expect
17
+ end
18
+ end
@@ -1,9 +1,9 @@
1
- RSpec.describe TomosiaIcon8Crawl do
2
- it "has a version number" do
3
- expect(TomosiaIcon8Crawl::VERSION).not_to be nil
4
- end
5
-
6
- it "does something useful" do
7
- expect(false).to eq(true)
8
- end
9
- end
1
+ RSpec.describe TomosiaIcon8Crawl do
2
+ it "has a version number" do
3
+ expect(TomosiaIcon8Crawl::VERSION).not_to be nil
4
+ end
5
+
6
+ it "does something useful" do
7
+ expect(false).to eq(true)
8
+ end
9
+ end
@@ -1,30 +1,30 @@
1
- require_relative 'lib/tomosia_icon8_crawl/version'
2
-
3
- Gem::Specification.new do |spec|
4
- spec.name = "tomosia_icon8_crawl"
5
- spec.version = TomosiaIcon8Crawl::VERSION
6
- spec.authors = ["ninh-tomosia"]
7
- spec.email = ["tt.ninh.le@tomosia.com"]
8
-
9
- spec.summary = %q{tomosia-icon8-crawl using download image from icon8.com}
10
- spec.homepage = "https://github.com/ninh-tomosia/tomosia-icon8-crawl"
11
- spec.license = "MIT"
12
- spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
13
-
14
- spec.add_development_dependency "bundler"
15
- spec.add_development_dependency "rake"
16
- spec.add_runtime_dependency "thor"
17
- spec.add_development_dependency "rspec"
18
- spec.add_runtime_dependency "httparty"
19
- spec.add_runtime_dependency "writeexcel"
20
- spec.add_runtime_dependency "nokogiri"
21
- spec.add_runtime_dependency "pry"
22
-
23
- # Specify which files should be added to the gem when it is released.
24
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
-
26
- spec.files = `git ls-files`.split("\n")
27
- spec.bindir = "exe"
28
- spec.executables = 'tomosia_icon8_crawl'
29
- spec.require_paths = ["lib"]
1
+ require_relative 'lib/tomosia_icon8_crawl/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "tomosia_icon8_crawl"
5
+ spec.version = TomosiaIcon8Crawl::VERSION
6
+ spec.authors = ["ninh-tomosia"]
7
+ spec.email = ["tt.ninh.le@tomosia.com"]
8
+
9
+ spec.summary = %q{tomosia-icon8-crawl using download image from icons8.com}
10
+ spec.homepage = "https://github.com/ninh-tomosia/tomosia-icon8-crawl"
11
+ spec.license = "MIT"
12
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
13
+
14
+ spec.add_development_dependency "bundler"
15
+ spec.add_development_dependency "rake"
16
+ spec.add_runtime_dependency "thor"
17
+ spec.add_development_dependency "rspec"
18
+ spec.add_runtime_dependency "httparty"
19
+ spec.add_runtime_dependency "writeexcel"
20
+ spec.add_runtime_dependency "nokogiri"
21
+ spec.add_runtime_dependency "pry"
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+
26
+ spec.files = `git ls-files`.split("\n")
27
+ spec.bindir = "exe"
28
+ spec.executables = 'tomosia_icon8_crawl'
29
+ spec.require_paths = ["lib"]
30
30
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tomosia_icon8_crawl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - ninh-tomosia
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-08-09 00:00:00.000000000 Z
11
+ date: 2020-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -170,5 +170,5 @@ requirements: []
170
170
  rubygems_version: 3.1.2
171
171
  signing_key:
172
172
  specification_version: 4
173
- summary: tomosia-icon8-crawl using download image from icon8.com
173
+ summary: tomosia-icon8-crawl using download image from icons8.com
174
174
  test_files: []