tomosia_icon8_crawl 0.1.2 → 0.1.7

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: 2578a3056544b2c996f4bc667c341f0d297a3873f7ccd95f99c71de597fe124f
4
- data.tar.gz: b07c4616d4a6e077878e7039e131d5ae70a1933eb3c8f45500324621d58b8f41
3
+ metadata.gz: 255338f89b797ffceeb21f5d1a894a66c935b6d751df2638aab16c6c19c26036
4
+ data.tar.gz: 2021299e9056f9beae3448440904929205a11b93b66ff67553ee60ed26dcf07b
5
5
  SHA512:
6
- metadata.gz: 074a677795357e32188a3a2894b3e8f703589746045e3138634017e28da62462d8f8777df5054dfd81bad230bd3c25ca274b4a06583ff6bd74740621e03bc95e
7
- data.tar.gz: 68ec41c66819afd2b7559603aac3b738d302501074860792b4509855f57bab4aa902088cfc475ff35b382e7426f6a9c330965692fd43962fc2ec0021b6670906
6
+ metadata.gz: 3108b2c8bb8ead660702486b5544489909096053fe4bb107f8bc7e5b5b368499d024a29bbc02c987a2f2ed19f9e14746840bf0a9e97f37780040a2cc4a4101e5
7
+ data.tar.gz: cf59adedf520a0ac3f0206b40bfecfb11fb3fa3f2c51e2a4438060b2564e8d658e67c9d0bb666f3a7a92be9a6bf50abfc3ad58e5bf924b28672dedeaf8189c31
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,12 @@
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
- gem 'httparty', '~> 0.17.3'
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
+ gem 'httparty', '~> 0.17.3'
11
+ gem 'thor', '~> 1.0', '>= 1.0.1'
12
+ gem 'nokogiri', '~> 1.10', '>= 1.10.10'
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tomosia_icon8_crawl (0.1.2)
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
@@ -14,35 +14,50 @@ gem 'tomosia_icon8_crawl'
14
14
 
15
15
  And then execute:
16
16
 
17
- $ bundle install
17
+ $ bundle install
18
18
 
19
19
  Or install it yourself as:
20
20
 
21
- $ gem install tomosia_icon8_crawl
21
+ $ gem install tomosia_icon8_crawl
22
22
 
23
23
  ## Usage
24
24
 
25
- Commandline or Terminal:
26
- Download all photos including pages from icon8.com with keyword you search
27
- $ tomosia_icon8_crawl crawl "keyword" --destination="storage path"
28
- Download pictures with number you want to get from icon8.com with keyword to find
29
- $ tomosia_icon8_crawl crawl "keyword" --destination="storage path" --max=number
30
- Developers:
31
- Gemfile:
32
- $ gem 'tomosia_icon8_crawl'
33
- Require:
34
- $ require 'tomosia_icon8_crawl'
35
- Download all photos including pages from icon8.com with keyword you search
36
- $ TomosiaIcon8Crawl::CrawlIcon8.crawl("keyword", "destination")
37
- Download pictures with number you want to get from icon8.com with keyword to find
38
- $ TomosiaIcon8Crawl::CrawlIcon8.crawl("keyword", "destination", max)
39
- Help:
40
- - keyword is the word used for searching.
41
- ex: corona, car, virus,...
42
- - destination is the path of the directory where the image was downloaded.
43
- ex: E:\download, C:\download, C:\Desktop,...
44
- - max max is the number of images you want to download.
45
- ex: 100, 10, 5, 1000,...
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
+
46
61
 
47
62
 
48
63
  ## Development
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,150 @@
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 = nil)
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.to_s
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'], 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'], 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
+ end
82
+ end
83
+
84
+ # download image
85
+ def self.download_image(path, img)
86
+ timeout = 0
87
+ begin
88
+ open(img) do |image|
89
+ File.open(path, 'wb') do |file|
90
+ file.write(image.read)
91
+ @size = image.size
92
+ end
93
+ end
94
+ rescue
95
+ if timeout < 5
96
+ timeout += 1
97
+ p "Retry download image"
98
+ retry
99
+ end
100
+ end
101
+ end
102
+
103
+ # multi download image
104
+ def self.multi_download_image(path, imgs)
105
+ begin
106
+ threads = []
107
+ @data = []
108
+
109
+ imgs.each_with_index do |img, index|
110
+ # p index
111
+ title = File.basename(img, '.png')
112
+ des = path. + "/" + index.to_s + "-" + title + ".png"
113
+ ext = File.extname(img).delete('.')
114
+ threads << Thread.new do
115
+ download_image(des, img)
116
+ row = {"index" => index, "name" => title, "url" => img, "size" => @size, "extension" => ext}
117
+ @data.push(row)
118
+ end
119
+ end
120
+ threads.each{ |t| t.join }
121
+ rescue Exception => e
122
+ p "no data"
123
+ p e
124
+ end
125
+ end
126
+
127
+ # main
128
+ def self.crawl(keyword = nil, path = ".", max = nil)
129
+ begin
130
+
131
+ images = []
132
+ des = ""
133
+ json(keyword, max)
134
+ @responses['icons'].each_with_index do |item, index|
135
+
136
+ src = "https://img.icons8.com/#{item['platform']}/2x/#{item['commonName']}.png"
137
+
138
+ # add image
139
+ images.push(src)
140
+ end
141
+
142
+ multi_download_image(path, images)
143
+ save_file_excel(path, @data)
144
+ rescue Exception => e
145
+ p "--Runtime error--"
146
+ p e
147
+ end
148
+ end
149
+ end
149
150
  end
@@ -1,3 +1,3 @@
1
- module TomosiaIcon8Crawl
2
- VERSION = "0.1.2"
3
- end
1
+ module TomosiaIcon8Crawl
2
+ VERSION = "0.1.7"
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", '~> 1.0', '>= 1.0.1'
17
+ spec.add_development_dependency "rspec"
18
+ spec.add_runtime_dependency "httparty", '~> 0.17.3'
19
+ spec.add_runtime_dependency "writeexcel", '~> 1.0', '>= 1.0.5'
20
+ spec.add_runtime_dependency "nokogiri", '~> 1.10', '>= 1.10.10'
21
+ spec.add_runtime_dependency "pry", '~> 0.13.1'
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.2
4
+ version: 0.1.7
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
@@ -42,16 +42,22 @@ dependencies:
42
42
  name: thor
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
45
48
  - - ">="
46
49
  - !ruby/object:Gem::Version
47
- version: '0'
50
+ version: 1.0.1
48
51
  type: :runtime
49
52
  prerelease: false
50
53
  version_requirements: !ruby/object:Gem::Requirement
51
54
  requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '1.0'
52
58
  - - ">="
53
59
  - !ruby/object:Gem::Version
54
- version: '0'
60
+ version: 1.0.1
55
61
  - !ruby/object:Gem::Dependency
56
62
  name: rspec
57
63
  requirement: !ruby/object:Gem::Requirement
@@ -70,58 +76,70 @@ dependencies:
70
76
  name: httparty
71
77
  requirement: !ruby/object:Gem::Requirement
72
78
  requirements:
73
- - - ">="
79
+ - - "~>"
74
80
  - !ruby/object:Gem::Version
75
- version: '0'
81
+ version: 0.17.3
76
82
  type: :runtime
77
83
  prerelease: false
78
84
  version_requirements: !ruby/object:Gem::Requirement
79
85
  requirements:
80
- - - ">="
86
+ - - "~>"
81
87
  - !ruby/object:Gem::Version
82
- version: '0'
88
+ version: 0.17.3
83
89
  - !ruby/object:Gem::Dependency
84
90
  name: writeexcel
85
91
  requirement: !ruby/object:Gem::Requirement
86
92
  requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '1.0'
87
96
  - - ">="
88
97
  - !ruby/object:Gem::Version
89
- version: '0'
98
+ version: 1.0.5
90
99
  type: :runtime
91
100
  prerelease: false
92
101
  version_requirements: !ruby/object:Gem::Requirement
93
102
  requirements:
103
+ - - "~>"
104
+ - !ruby/object:Gem::Version
105
+ version: '1.0'
94
106
  - - ">="
95
107
  - !ruby/object:Gem::Version
96
- version: '0'
108
+ version: 1.0.5
97
109
  - !ruby/object:Gem::Dependency
98
110
  name: nokogiri
99
111
  requirement: !ruby/object:Gem::Requirement
100
112
  requirements:
113
+ - - "~>"
114
+ - !ruby/object:Gem::Version
115
+ version: '1.10'
101
116
  - - ">="
102
117
  - !ruby/object:Gem::Version
103
- version: '0'
118
+ version: 1.10.10
104
119
  type: :runtime
105
120
  prerelease: false
106
121
  version_requirements: !ruby/object:Gem::Requirement
107
122
  requirements:
123
+ - - "~>"
124
+ - !ruby/object:Gem::Version
125
+ version: '1.10'
108
126
  - - ">="
109
127
  - !ruby/object:Gem::Version
110
- version: '0'
128
+ version: 1.10.10
111
129
  - !ruby/object:Gem::Dependency
112
130
  name: pry
113
131
  requirement: !ruby/object:Gem::Requirement
114
132
  requirements:
115
- - - ">="
133
+ - - "~>"
116
134
  - !ruby/object:Gem::Version
117
- version: '0'
135
+ version: 0.13.1
118
136
  type: :runtime
119
137
  prerelease: false
120
138
  version_requirements: !ruby/object:Gem::Requirement
121
139
  requirements:
122
- - - ">="
140
+ - - "~>"
123
141
  - !ruby/object:Gem::Version
124
- version: '0'
142
+ version: 0.13.1
125
143
  description:
126
144
  email:
127
145
  - tt.ninh.le@tomosia.com
@@ -170,5 +188,5 @@ requirements: []
170
188
  rubygems_version: 3.1.2
171
189
  signing_key:
172
190
  specification_version: 4
173
- summary: tomosia-icon8-crawl using download image from icon8.com
191
+ summary: tomosia-icon8-crawl using download image from icons8.com
174
192
  test_files: []