picker 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +6 -0
- data/bin/picker +69 -0
- data/lib/picker.rb +14 -0
- data/lib/picker/facebook.rb +162 -0
- data/lib/picker/version.rb +3 -0
- data/picker.rdoc +5 -0
- metadata +193 -0
data/README.rdoc
ADDED
data/bin/picker
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'gli'
|
3
|
+
begin # XXX: Remove this begin/rescue before distributing your app
|
4
|
+
require 'picker'
|
5
|
+
rescue LoadError
|
6
|
+
STDERR.puts "In development, you need to use `bundle exec bin/picker` to run your app"
|
7
|
+
STDERR.puts "At install-time, RubyGems will make sure lib, etc. are in the load path"
|
8
|
+
STDERR.puts "Feel free to remove this message from bin/picker now"
|
9
|
+
exit 64
|
10
|
+
end
|
11
|
+
|
12
|
+
include GLI::App
|
13
|
+
|
14
|
+
program_desc 'Picker lets you scrape pictures from social networks, simply..'
|
15
|
+
|
16
|
+
version Picker::VERSION
|
17
|
+
|
18
|
+
desc 'Scrape pictures from facebook.com as per your needs..'
|
19
|
+
arg_name 'user_id_or_name' #, multiple: true, optional: true
|
20
|
+
command :facebook do |c|
|
21
|
+
c.action do |global_options,options,args|
|
22
|
+
# puts global_options.inspect, options.inspect, args.inspect
|
23
|
+
|
24
|
+
@fb = Picker::Facebook.new
|
25
|
+
@fb.user = args.first
|
26
|
+
@fb.download_albums_via_fql
|
27
|
+
@fb.download_tagged_via_fql
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
desc 'Scrape pictures from facebook.com for all females..'
|
32
|
+
command :facebook_females do |c|
|
33
|
+
c.action do |global_options,options,args|
|
34
|
+
@fb = Picker::Facebook.new
|
35
|
+
@fb.user = nil
|
36
|
+
friends = @fb.find_female_friends
|
37
|
+
friends.each do |friend|
|
38
|
+
if friend["sex"] == "female" || friend["uid"] == "503341844"
|
39
|
+
say "downloading images for: #{friend["name"]}"
|
40
|
+
@fb.user = friend["uid"]
|
41
|
+
@fb.download_albums_via_fql
|
42
|
+
@fb.download_tagged_via_fql
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
pre do |global,command,options,args|
|
49
|
+
# Pre logic here
|
50
|
+
# Return true to proceed; false to abort and not call the
|
51
|
+
# chosen command
|
52
|
+
# Use skips_pre before a command to skip this block
|
53
|
+
# on that command only
|
54
|
+
true
|
55
|
+
end
|
56
|
+
|
57
|
+
post do |global,command,options,args|
|
58
|
+
# Post logic here
|
59
|
+
# Use skips_post before a command to skip this
|
60
|
+
# block on that command only
|
61
|
+
end
|
62
|
+
|
63
|
+
on_error do |exception|
|
64
|
+
# Error logic here
|
65
|
+
# return false to skip default error handling
|
66
|
+
true
|
67
|
+
end
|
68
|
+
|
69
|
+
exit run(ARGV)
|
data/lib/picker.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'picker/version.rb'
|
2
|
+
|
3
|
+
# Add requires for other files you add to your project here, so
|
4
|
+
# you just need to require this one file in your bin file
|
5
|
+
|
6
|
+
require 'fb_graph'
|
7
|
+
require 'highline/import'
|
8
|
+
require 'uri'
|
9
|
+
require 'yaml'
|
10
|
+
require 'pry'
|
11
|
+
require 'ruby-progressbar'
|
12
|
+
|
13
|
+
|
14
|
+
require 'picker/facebook.rb'
|
@@ -0,0 +1,162 @@
|
|
1
|
+
module Picker
|
2
|
+
class Facebook
|
3
|
+
APP_ID = "238077826328712"
|
4
|
+
SECRET = "17859f155d2d7734cabb3e1b78d3306b"
|
5
|
+
|
6
|
+
attr_reader :app, :user
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@app = FbGraph::Application.new(APP_ID, :secret => SECRET)
|
10
|
+
|
11
|
+
data = read_yaml
|
12
|
+
unless data[:fb_long_token] && @app.debug_token(data[:fb_long_token]).is_valid
|
13
|
+
save_access_token
|
14
|
+
end
|
15
|
+
|
16
|
+
token
|
17
|
+
end
|
18
|
+
|
19
|
+
def get_oauth_token
|
20
|
+
scope = ["user_photos", "friends_photos", "user_about_me", "friends_about_me"]
|
21
|
+
oauth_uri = "https://www.facebook.com/dialog/oauth?client_id=#{APP_ID}"
|
22
|
+
oauth_uri += "&redirect_uri=https://www.facebook.com/connect/login_success.html"
|
23
|
+
oauth_uri += "&scope=" + scope.join(",")
|
24
|
+
oauth_uri += "&response_type=token"
|
25
|
+
|
26
|
+
say "Copy the following URI and open it in browser."
|
27
|
+
say "Then, paste the URI for the page with \"success\" message here.."
|
28
|
+
say oauth_uri
|
29
|
+
puts
|
30
|
+
|
31
|
+
success_uri = ask("Success URI? ").strip
|
32
|
+
@access_token = URI.parse(success_uri).fragment.split("&").first.split("=").last
|
33
|
+
end
|
34
|
+
|
35
|
+
def get_long_token
|
36
|
+
uri = "https://graph.facebook.com/oauth/access_token"
|
37
|
+
data = "client_id=#{APP_ID}&client_secret=#{SECRET}&"
|
38
|
+
data += "grant_type=fb_exchange_token&fb_exchange_token=#{@access_token}"
|
39
|
+
response = `curl -s -d "#{data}" "#{uri}"`
|
40
|
+
@long_token = response.split("&").first.split("=").last
|
41
|
+
end
|
42
|
+
|
43
|
+
def save_access_token
|
44
|
+
data = read_yaml
|
45
|
+
data = data.merge({
|
46
|
+
fb_access_token: get_oauth_token,
|
47
|
+
fb_long_token: get_long_token
|
48
|
+
})
|
49
|
+
write_yaml(data)
|
50
|
+
end
|
51
|
+
|
52
|
+
def token
|
53
|
+
data = read_yaml
|
54
|
+
@token = data[:fb_long_token]
|
55
|
+
end
|
56
|
+
|
57
|
+
def query(query)
|
58
|
+
FbGraph::Query.new(query).fetch(@token)
|
59
|
+
end
|
60
|
+
|
61
|
+
def find_female_friends
|
62
|
+
response = query "SELECT uid, name, sex FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())"
|
63
|
+
response.reject{|x| x["sex"] == "male"}
|
64
|
+
end
|
65
|
+
|
66
|
+
def user=(name = nil)
|
67
|
+
@user = name ? FbGraph::User.fetch(name, :access_token => @token)
|
68
|
+
: FbGraph::User.me(@token)
|
69
|
+
end
|
70
|
+
|
71
|
+
def download_albums_via_fql
|
72
|
+
# create a directory for this user
|
73
|
+
path = File.join(ENV['HOME'], "picker", @user.name)
|
74
|
+
FileUtils.mkdir_p path
|
75
|
+
|
76
|
+
# change to this directory
|
77
|
+
Dir.chdir(path) do
|
78
|
+
@all_photos = []
|
79
|
+
|
80
|
+
albums = query "SELECT aid, name, photo_count FROM album WHERE owner = #{@user.identifier}"
|
81
|
+
albums.each do |album|
|
82
|
+
FileUtils.mkdir_p album["name"]
|
83
|
+
progress = ProgressBar.create(
|
84
|
+
:title => album["name"],
|
85
|
+
:total => album["photo_count"],
|
86
|
+
:format => '%t ( %c/%C ) |%b>>%i| %f'
|
87
|
+
)
|
88
|
+
photos = query "SELECT pid, caption, images FROM photo WHERE aid = \"#{album["aid"]}\""
|
89
|
+
Dir.chdir(album["name"]) do
|
90
|
+
photos.each do |photo|
|
91
|
+
unless @all_photos.include?(photo["pid"])
|
92
|
+
@all_photos.push photo["pid"]
|
93
|
+
# select the largest image for download
|
94
|
+
size = 0; source = "";
|
95
|
+
photo["images"].each do |img|
|
96
|
+
dim = img["height"] * img["width"]
|
97
|
+
if size < dim
|
98
|
+
size = dim
|
99
|
+
source = img["source"]
|
100
|
+
end
|
101
|
+
end
|
102
|
+
system("wget -qct 3 #{source}") unless File.exists?(File.basename(source))
|
103
|
+
end
|
104
|
+
progress.increment
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def download_tagged_via_fql
|
112
|
+
# create a directory for this user
|
113
|
+
path = File.join(ENV['HOME'], "picker", @user.name)
|
114
|
+
FileUtils.mkdir_p path
|
115
|
+
|
116
|
+
# change to this directory
|
117
|
+
Dir.chdir(path) do
|
118
|
+
# download all tagged images for this user
|
119
|
+
album_name = "Tagged Photos"
|
120
|
+
FileUtils.mkdir_p album_name
|
121
|
+
photos = query "SELECT pid, caption, images FROM photo WHERE pid IN
|
122
|
+
(SELECT pid FROM photo_tag WHERE subject = #{@user.identifier})"
|
123
|
+
progress = ProgressBar.create(
|
124
|
+
:title => album_name,
|
125
|
+
:total => photos.count,
|
126
|
+
:format => '%t ( %c/%C ) |%b>>%i| %f'
|
127
|
+
)
|
128
|
+
Dir.chdir(album_name) do
|
129
|
+
photos.each do |photo|
|
130
|
+
unless @all_photos.include?(photo["pid"])
|
131
|
+
@all_photos.push photo["pid"]
|
132
|
+
# select the largest image for download
|
133
|
+
size = 0; source = "";
|
134
|
+
photo["images"].each do |img|
|
135
|
+
dim = img["height"] * img["width"]
|
136
|
+
if size < dim
|
137
|
+
size = dim
|
138
|
+
source = img["source"]
|
139
|
+
end
|
140
|
+
end
|
141
|
+
system("wget -qct 3 #{source}") unless File.exists?(File.basename(source))
|
142
|
+
progress.increment
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
private
|
151
|
+
|
152
|
+
def read_yaml
|
153
|
+
file = File.join(ENV['HOME'], ".picker")
|
154
|
+
File.exists?(file) ? YAML::load_file(file) : {}
|
155
|
+
end
|
156
|
+
|
157
|
+
def write_yaml(data)
|
158
|
+
file = File.join(ENV['HOME'], ".picker")
|
159
|
+
File.open(file, "w") {|f| f.puts data.to_yaml}
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
data/picker.rdoc
ADDED
metadata
ADDED
@@ -0,0 +1,193 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: picker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Nikhil Gupta
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-18 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: highline
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: ruby-progressbar
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: fb_graph
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: pry
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: rake
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: rdoc
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: aruba
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: gli
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - '='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: 2.5.3
|
134
|
+
type: :runtime
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - '='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: 2.5.3
|
142
|
+
description:
|
143
|
+
email: me@nikhgupta.com
|
144
|
+
executables:
|
145
|
+
- picker
|
146
|
+
extensions: []
|
147
|
+
extra_rdoc_files:
|
148
|
+
- README.rdoc
|
149
|
+
- picker.rdoc
|
150
|
+
files:
|
151
|
+
- bin/picker
|
152
|
+
- lib/picker/version.rb
|
153
|
+
- lib/picker.rb
|
154
|
+
- lib/picker/facebook.rb
|
155
|
+
- README.rdoc
|
156
|
+
- picker.rdoc
|
157
|
+
homepage: http://nikhgupta.com
|
158
|
+
licenses: []
|
159
|
+
post_install_message:
|
160
|
+
rdoc_options:
|
161
|
+
- --title
|
162
|
+
- picker
|
163
|
+
- --main
|
164
|
+
- README.rdoc
|
165
|
+
- -ri
|
166
|
+
require_paths:
|
167
|
+
- lib
|
168
|
+
- lib
|
169
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
170
|
+
none: false
|
171
|
+
requirements:
|
172
|
+
- - ! '>='
|
173
|
+
- !ruby/object:Gem::Version
|
174
|
+
version: '0'
|
175
|
+
segments:
|
176
|
+
- 0
|
177
|
+
hash: 1644716752488261609
|
178
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
179
|
+
none: false
|
180
|
+
requirements:
|
181
|
+
- - ! '>='
|
182
|
+
- !ruby/object:Gem::Version
|
183
|
+
version: '0'
|
184
|
+
segments:
|
185
|
+
- 0
|
186
|
+
hash: 1644716752488261609
|
187
|
+
requirements: []
|
188
|
+
rubyforge_project:
|
189
|
+
rubygems_version: 1.8.24
|
190
|
+
signing_key:
|
191
|
+
specification_version: 3
|
192
|
+
summary: Picker is a gem that lets you scrape your social networks, the way you want..
|
193
|
+
test_files: []
|