hexapic 0.1.4 → 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
  SHA1:
3
- metadata.gz: ec414c571a2ba9cd65bf7dd058f93b3520a6a400
4
- data.tar.gz: 5dc1213003aede65f59fa46720ce513cb3bda170
3
+ metadata.gz: cc9e1b4bf02aaef6e17971a0435f97ca300b76c7
4
+ data.tar.gz: 21e3a40efedb163ea1629da7aa699b210141b5ef
5
5
  SHA512:
6
- metadata.gz: e4920f3f2566399fea4dd0deef648c51e166731b28edffee50d643578473bd67c82aa4a85161a98a74d832cec1e51ae180a1a798b1b0f462f9f5f37f2185859f
7
- data.tar.gz: a71e7d7b8cf7268a3086a879e15e4dac0a4ae7dd4a5df924200df53157bf98c7320e9860f3c7ad68d08989f2a4099db05bf10b5d2f9e8bb3584d6e2bc1f9e679
6
+ metadata.gz: e17b104798c2cc6acc93cef6aa34358f0f3630d051cb840bf1d0fb4e5cceb11378116b45f2849f20483bb1beb9c05d49ee249d5e16d2098d2f33a863b8ef5296
7
+ data.tar.gz: a895a87b30d28e3bccc241775bef9bc52ff7c31b8e12c715aa81386fe43c90d8565719e697e2f75448be42ccadbcdde2268d6e313d352c7b49cf199d973f280e
@@ -11,10 +11,16 @@ include Hexapic
11
11
  require 'choice'
12
12
 
13
13
  def set_wallpaper
14
- tags = Choice.choices[:tags] || ENV['WALLPAPER_TAGS'] || 'nature'
15
14
  repository = Choice.choices[:repository] || ENV['WALLPAPER_REPOSITPRY'] || :instagram
16
- runner = Hexapic::Runner.new(tags)
17
- runner.run(repository)
15
+ query = Choice.choices[:tags] || Choice.choices[:username]
16
+ runner = Hexapic::Runner.new
17
+ type = if Choice.choices[:tags]
18
+ :tags
19
+ elsif Choice.choices[:username]
20
+ :username
21
+ end
22
+
23
+ runner.run(repository, query, type)
18
24
  end
19
25
 
20
26
  def print_version
@@ -33,19 +39,26 @@ Choice.options do
33
39
  option :repository do
34
40
  long '--repository=REPOSITORY'
35
41
  short '-r'
36
- desc 'Chose where to load pictures. Chose one of flickr, instagram.'
42
+ desc 'Chose where to load pictures from. Chose one of flickr, instagram. Default is instagram'
37
43
  cast Symbol
38
44
  end
39
45
 
40
46
  option :tags do
41
47
  long '--tags=TAGS'
42
48
  short '-t'
43
- desc 'comma separated list of tags'
49
+ desc 'Comma separated list of tags'
50
+ cast String
51
+ end
52
+
53
+ option :username do
54
+ long '--username=USERNAME'
55
+ short '-u'
56
+ desc 'Instagram username'
44
57
  cast String
45
58
  end
46
59
  end
47
60
 
48
- if Choice.choices[:tags]
61
+ if Choice.choices[:tags] || Choice.choices[:username]
49
62
  begin
50
63
  set_wallpaper
51
64
  rescue Exception => e
@@ -11,6 +11,10 @@ module Hexapic
11
11
  end
12
12
  end
13
13
 
14
+ def search_by_user(username, count = 100)
15
+ user_media(search_user(username), count)
16
+ end
17
+
14
18
  def search(tag, count = 20)
15
19
  tag = URI.encode(tag)
16
20
  res = @conn.get("tags/#{tag}/media/recent",{client_id: @client_id, count: count})
@@ -21,10 +25,39 @@ module Hexapic
21
25
  id: img['id'],
22
26
  likes: img['likes']['count'],
23
27
  link: img['link'],
24
- url: img['images']['standard_resolution']['url']
28
+ url: img['images']['standard_resolution']['url'],
29
+ width: img['images']['standard_resolution']['width'],
30
+ height: img['images']['standard_resolution']['height']
25
31
  }
26
32
  end
27
33
  end
34
+
35
+ def user_media(user_id, count)
36
+ res = @conn.get("users/#{user_id}/media/recent/", {client_id: @client_id, count: count})
37
+ data = JSON.parse(res.body)['data']
38
+
39
+ data.map do |img|
40
+ {
41
+ id: img['id'],
42
+ likes: img['likes']['count'],
43
+ link: img['link'],
44
+ url: img['images']['standard_resolution']['url'],
45
+ width: img['images']['standard_resolution']['width'],
46
+ height: img['images']['standard_resolution']['height']
47
+ }
48
+ end
49
+ end
50
+
51
+ def search_user(username)
52
+ puts "Searching user #{username}"
53
+ username = URI.encode(username)
54
+ res = @conn.get("users/search", {q: username, client_id: @client_id})
55
+ data = JSON.parse(res.body)['data'].first
56
+ raise UserNotFound.new("User with name #{username} not found") if data.nil?
57
+ puts "Find user #{data['username']} #{data['first_name']} #{data['last_name']} with id #{data['id']}"
58
+
59
+ data['id']
60
+ end
28
61
  end
29
62
  end
30
63
  end
@@ -31,6 +31,16 @@ module Hexapic
31
31
  raise ImagesNotFound.new("Found only #{pics.size} images. Need #{COUNT}.") if pics.size < COUNT
32
32
  pics
33
33
  end
34
+
35
+ def find_pictures_by_username(username)
36
+ puts "Getting last images from user #{username}"
37
+ pics = @instagram.search_by_user(username).sample(COUNT).map do |r|
38
+ Picture.new(r[:url], r[:link], r[:id])
39
+ end
40
+
41
+ raise ImagesNotFound.new("Found only #{pics.size} images. Need #{COUNT}.") if pics.size < COUNT
42
+ pics
43
+ end
34
44
  end
35
45
 
36
46
  class FlickrRepository
@@ -1,14 +1,17 @@
1
1
  module Hexapic
2
- class Runner
3
- def initialize(tags)
4
- @tags = tags.to_s
5
- end
6
-
7
- def run(repository = :instagram)
2
+ class Runner
3
+ def run(repository = :instagram, query, type)
8
4
  collage = Collage.new
9
5
  setter = WallpaperSetter.build
10
6
  repository = Repository::LIST[repository].new
11
- pictures = repository.find_pictures(@tags)
7
+ picture = nil
8
+ case type
9
+ when :tags
10
+ pictures = repository.find_pictures(query)
11
+ when :username
12
+ pictures = repository.find_pictures_by_username(query)
13
+ end
14
+
12
15
  picture = collage.make(pictures)
13
16
 
14
17
  setter.set picture.path
@@ -1,3 +1,3 @@
1
1
  module Hexapic
2
- VERSION = '0.1.4'
2
+ VERSION = '0.1.5'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hexapic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ilya Siganov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-16 00:00:00.000000000 Z
11
+ date: 2014-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler