picfisher 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: da4504372d6b3cceb6deda036fda5f51f8d46c44726ebed76636aa02c49fa4b9
4
- data.tar.gz: 446d39d4044826782748ca34c5a346560d6ae5490290afeb371323976ace6b06
3
+ metadata.gz: d6b49dc4c4a306ff17087d90b81c875043f63062b1760eb0f481e2968b44dd66
4
+ data.tar.gz: 4caafb009411921cef9a4c3c60a8e231072de6a369f6b4e7a5386d636534d241
5
5
  SHA512:
6
- metadata.gz: 5d2921671fd3e415c4f354ec1f0e67c62d95d3e2a470f4c1dd4db5de44169984d4ad42ee9657e246c6555f1ac18b312d05e8c9e12e37290bda3ae776b582d727
7
- data.tar.gz: 7be9a0990f49777ddd3d911801d1a3ef61b69c966df20dc483b6c870c9731bf6812109bfe6af22dab5e40f000e2d3b4a523fcef2a4c9673de561787300a9e563
6
+ metadata.gz: 8cb50f69831f0421ec7cda95a942730ebdec12ceadc664a7c65fbba5322ee0c6315b5eefa06440041106756c3ba54c1fcad876c180abf551047b299da09fa2d7
7
+ data.tar.gz: 56739738de69a7e0f314815c0665018d516af93cc39451884ae8abe2ac1ba56db02a45cc4e272cab14a9bb32653fbd66e569bc0482999444702bb0ce9b2b8133
data/CHANGELOG.md CHANGED
@@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.2.0] - 2024-05-30
9
+
10
+ ### Added
11
+
12
+ - Debug Level is 'info' by default
13
+ - Error handling when image URL is not valid
14
+
15
+
8
16
  ## [0.1.0] - 2024-05-30
9
17
 
10
18
  ### Added
data/README.md CHANGED
@@ -28,7 +28,7 @@ With log
28
28
  DEBUG_LEVEL=debug picfisher images.txt ~/Downloads/fished_images
29
29
  ```
30
30
 
31
- Accepted values for `DEBUG_LEVEL`: `debug`, `info`, `error`.
31
+ Accepted values for `DEBUG_LEVEL`: `debug`, `info`, `error`, `silence`.
32
32
 
33
33
  ## Development
34
34
 
data/TODO.md CHANGED
@@ -5,3 +5,4 @@
5
5
  - Add a progress bar for the downloading phase.
6
6
  - Allow multiple concurrent downloads. Add an extra param to decide the number, default `5`
7
7
  - Add error handling to the Downloader. Many things can be wrong when connecting to the internet.
8
+ - Allow URLs without image extension. This requires the source urls file to have a predictable estructure. Or we request all the images and check the media type of the response.
@@ -4,8 +4,20 @@ module PicFisher
4
4
  module Downloader
5
5
  # TODO: We need to add error handling here
6
6
  def self.download(url, output_path)
7
- PicFisher::Log.debug("Downloading #{url} to #{output_path}")
7
+ PicFisher::Log.debug("Fishing #{url} to #{output_path}")
8
8
 
9
+ begin
10
+ _dowload(url, output_path)
11
+ rescue OpenURI::HTTPError => e
12
+ message = "Failed to fish #{url}: #{e}"
13
+ PicFisher::Log.error(message)
14
+ raise PicFisher::Error.new(message)
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ def self._dowload(url, output_path)
9
21
  io_stream = OpenURI::open_uri(url)
10
22
 
11
23
  File.open(output_path, "wb") do |f|
@@ -8,7 +8,12 @@ module PicFisher
8
8
  urls = PicFisher::URLExtractor.extract(file_to_string)
9
9
  urls.each do |url|
10
10
  sanitized_url = PicFisher::Sanitizer.sanitize_image_url(url)
11
- PicFisher::Downloader.download(url, "#{output_directory_path}/#{sanitized_url}")
11
+
12
+ begin
13
+ PicFisher::Downloader.download(url, "#{output_directory_path}/#{sanitized_url}")
14
+ rescue PicFisher::Error
15
+ PicFisher::Log.error("Failed to fish #{url}. Skipping...")
16
+ end
12
17
  end
13
18
  end
14
19
  end
data/lib/picfisher/log.rb CHANGED
@@ -1,19 +1,19 @@
1
1
  module PicFisher
2
2
  module Log
3
3
  def self.debug(message)
4
- if ["debug"].include? ENV["DEBUG_LEVEL"]
4
+ if ["debug"].include? debug_level
5
5
  output(:debug, message)
6
6
  end
7
7
  end
8
8
 
9
9
  def self.info(message)
10
- if ["debug", "info"].include? ENV["DEBUG_LEVEL"]
10
+ if ["debug", "info"].include? debug_level
11
11
  output(:info, message)
12
12
  end
13
13
  end
14
14
 
15
15
  def self.error(message)
16
- if ["debug", "info", "error"].include? ENV["DEBUG_LEVEL"]
16
+ if ["debug", "info", "error"].include? debug_level
17
17
  output(:error, message)
18
18
  end
19
19
  end
@@ -24,5 +24,9 @@ module PicFisher
24
24
  final_message = "PicFisher [#{level.upcase}] #{message}"
25
25
  Kernel.puts(final_message)
26
26
  end
27
+
28
+ def self.debug_level
29
+ ENV["DEBUG_LEVEL"] || "info" # default is info
30
+ end
27
31
  end
28
32
  end
@@ -6,7 +6,7 @@ module PicFisher
6
6
  result =
7
7
  url
8
8
  .sub(/#{filename_extension_escaped}$/, "")
9
- .gsub(/[^\w\s_-]+/, "_")
9
+ .gsub(/[^\w\s-]+/, "_")
10
10
  .gsub(/(^|\b\s)\s+($|\s?\b)/, "\\1\\2")
11
11
  .gsub(/\s+/, "_")
12
12
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PicFisher
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
data/lib/picfisher.rb CHANGED
@@ -27,7 +27,7 @@ module PicFisher
27
27
  end
28
28
 
29
29
  if !Dir.exist?(output_directory_path)
30
- message = "Directory not found: #{images_file_path}"
30
+ message = "Directory not found: #{output_directory_path}"
31
31
  PicFisher::Log.error(message)
32
32
  raise PicFisher::Error.new(message)
33
33
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: picfisher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fernando Guillen