flickr_cli 0.2.0 → 0.2.1

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.
data/bin/flickr_cli CHANGED
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'yaml'
3
3
  require 'flickr_cli'
4
- require 'image_cutter'
5
4
  FlickrCli.start_program
data/lib/flickr_cli.rb CHANGED
@@ -1,12 +1,10 @@
1
1
  # Extental Dependencies
2
2
  require 'rubygems'
3
- require 'tempfile'
4
3
  require 'flickraw'
5
- require 'net/http'
6
- require 'cgi'
7
4
  require 'launchy'
8
5
  require 'highline/import'
9
- require 'RMagick'
6
+ require 'asciiart'
7
+
10
8
  # Internal Libraries
11
9
  require 'authentication'
12
10
  require 'menu'
data/lib/menu.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  module FlickrCli
2
2
  module Menu
3
+ @cached_art = {}
3
4
 
4
5
  def self.main_menu
5
6
  choose do |menu|
@@ -23,7 +24,7 @@ module FlickrCli
23
24
  menu.choice(photo) do
24
25
  # When you choose a photo...
25
26
  FlickrCli::Menu.download_and_print(photos.detect{|x| x.title == photo})
26
- puts "Press any ENTER to continue"
27
+ puts "Press ENTER to continue"
27
28
  do_nothing = STDIN.gets
28
29
  self.menu_for(FlickrCli::Menu.menu_for(contact, the_page))
29
30
  end
@@ -41,28 +42,28 @@ module FlickrCli
41
42
  end
42
43
 
43
44
  def self.download_and_print(picked_photo)
45
+ if @cached_art["photo_#{picked_photo.id}"]
46
+ puts @cached_art["photo_#{picked_photo.id}"]
47
+ else
48
+ photos = flickr.photos.getSizes(:photo_id => picked_photo.id)
49
+ download_url = nil
44
50
 
45
- photos = flickr.photos.getSizes(:photo_id => picked_photo.id)
46
- download_url = nil
47
-
48
- ["Large", "Medium"].each do |style|
49
- if picture = photos.find{ |photo| photo.label == style }
50
- download_url = picture.source
51
+ ["Large", "Medium"].each do |style|
52
+ if picture = photos.find{ |photo| photo.label == style }
53
+ download_url = picture.source
54
+ end
55
+ break if download_url
51
56
  end
52
- break if download_url
57
+ @cached_art["photo_#{picked_photo.id}"] = AsciiArt.new(download_url).to_ascii_art(width: 175)
58
+
59
+ puts @cached_art["photo_#{picked_photo.id}"]
53
60
  end
54
-
55
- my_file = Tempfile.new("tempimage#{File.basename(download_url)}")
56
- my_file << Net::HTTP.get_response(URI.parse(download_url)).body
57
- my_file.close
58
- puts FlickrCli::ImageCutter.convert_to_ascii(my_file.path)
59
- my_file.delete
60
61
  end
61
62
 
62
63
  def self.good_by_message
63
64
  ["Be that way",
64
65
  "Goodbye - I'll never love again",
65
- "See you later, bye!",
66
+ "I love my wife, is that a crime?",
66
67
  "Goodbye - Flickr? I hardly know her"].shuffle[0]
67
68
  end
68
69
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flickr_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-14 00:00:00.000000000 Z
12
+ date: 2013-01-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: highline
@@ -60,14 +60,30 @@ dependencies:
60
60
  - !ruby/object:Gem::Version
61
61
  version: 0.8.4
62
62
  - !ruby/object:Gem::Dependency
63
- name: rmagick
63
+ name: asciiart
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - '='
68
+ - !ruby/object:Gem::Version
69
+ version: 0.0.4
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - '='
76
+ - !ruby/object:Gem::Version
77
+ version: 0.0.4
78
+ - !ruby/object:Gem::Dependency
79
+ name: pry
64
80
  requirement: !ruby/object:Gem::Requirement
65
81
  none: false
66
82
  requirements:
67
83
  - - ! '>='
68
84
  - !ruby/object:Gem::Version
69
85
  version: '0'
70
- type: :runtime
86
+ type: :development
71
87
  prerelease: false
72
88
  version_requirements: !ruby/object:Gem::Requirement
73
89
  none: false
@@ -86,7 +102,6 @@ files:
86
102
  - bin/flickr_cli
87
103
  - lib/authentication.rb
88
104
  - lib/flickr_cli.rb
89
- - lib/image_cutter.rb
90
105
  - lib/menu.rb
91
106
  homepage: https://github.com/nodanaonlyzuul/flickr_cli
92
107
  licenses: []
data/lib/image_cutter.rb DELETED
@@ -1,51 +0,0 @@
1
-
2
-
3
- module FlickrCli
4
- module ImageCutter
5
-
6
- CHARS = [" ", ".", "~", ":", "+", "=", "o", "*", "x", "^", "%", "#", "@", "$", "M", "W"]
7
- FONT_ROWS = 8
8
- FONT_COLS = 4
9
-
10
- def self.convert_to_ascii(file)
11
-
12
- img = Magick::Image.read(file).first
13
-
14
- img.resize_to_fit!('728')
15
-
16
- # Compute the image size in ASCII "pixels" and resize the image to have
17
- # those dimensions. The resulting image does not have the same aspect
18
- # ratio as the original, but since our "pixels" are twice as tall as
19
- # they are wide we'll get our proportions back (roughly) when we render.
20
-
21
- pr = img.rows / FONT_ROWS
22
- pc = img.columns / FONT_COLS
23
- img.resize!(pc, pr)
24
-
25
- img = img.quantize(16, Magick::GRAYColorspace)
26
- img = img.normalize
27
-
28
- # Depending on compile-time options for ImageMagick - pixel instensity is stored in different scales
29
- # This will calculate the correct denominator to use
30
- quantum_calc = Magick::QuantumRange / Magick::QuantumPixel.to_i
31
-
32
- # Draw the image surrounded by a border. The `view' method is slow but
33
- # it makes it easy to address individual pixels. In grayscale images,
34
- # all three RGB channels have the same value so the red channel is as
35
- # good as any for choosing which character to represent the intensity of
36
- # this particular pixel.
37
-
38
- border = '+' + ('-' * pc) + '+'
39
- puts border
40
-
41
- img.view(0, 0, pc, pr) do |view|
42
- pr.times do |i|
43
- putc '|'
44
- pc.times { |j| putc CHARS[view[i][j].red/quantum_calc] }
45
- puts '|'
46
- end
47
- end
48
- border
49
- end
50
- end
51
- end