twitter_images 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.ruby-version +1 -0
- data/.travis.yml +12 -0
- data/Gemfile +4 -0
- data/README.md +49 -0
- data/Rakefile +10 -0
- data/bin/twitter_images +7 -0
- data/lib/twitter_images.rb +171 -0
- data/lib/twitter_images/version.rb +3 -0
- data/twitter_images.gemspec +36 -0
- metadata +173 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1b8ee5e67155ed5b50b9c1c8d4e8d78c80714090
|
4
|
+
data.tar.gz: 51b4375e90187c6e572bed838d0ea6982d13a1ab
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9a28e3cc57105a81bcad0235ee8ba0d120e2e89e4386e1746ef5871929b178454016feee9907c04acef2ecf43c64d587161c636728160c443cdde9da769e33d6
|
7
|
+
data.tar.gz: e51778eda0feadf17a9b2039b3474a14e3e4c386e6c2601592c99b14e94f523ee131a0061b713f526733e082ec5115fc06adca479f3a4bc589236d485a4802a8
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.2.1
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# TwitterImages
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/Alehanz/twitter_images.svg?branch=master)](https://travis-ci.org/Alehanz/twitter_images) [![Coverage Status](https://coveralls.io/repos/Alehanz/twitter_images/badge.svg)](https://coveralls.io/r/Alehanz/twitter_images) [![Gem Version](https://badge.fury.io/rb/twitter_images.svg)](http://badge.fury.io/rb/twitter_images)
|
4
|
+
|
5
|
+
This is a CLI tool for downloading the most recent images off of twitter based
|
6
|
+
on the search terms you provide.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Execute this in the terminal:
|
11
|
+
|
12
|
+
$ gem install twitter_images
|
13
|
+
|
14
|
+
## Usage
|
15
|
+
|
16
|
+
In order to use this gem you have to set up your Twitter credentials.
|
17
|
+
You can get those at [Twitter app management page](https://apps.twitter.com/).
|
18
|
+
Create a new app, go to Keys and Access Tokens, generate your Access Token.
|
19
|
+
|
20
|
+
Then you can either set up
|
21
|
+
|
22
|
+
CONSUMER_KEY
|
23
|
+
CONSUMER_SECRET
|
24
|
+
ACCESS_TOKEN
|
25
|
+
ACCESS_SECRET
|
26
|
+
|
27
|
+
in your .bashrc, .bash_profile, .zshenv or whichever shell config you normally
|
28
|
+
use or you can just run
|
29
|
+
|
30
|
+
$ twitter_images
|
31
|
+
|
32
|
+
and set those up through the command prompts.
|
33
|
+
|
34
|
+
After that you'll need to specify an absolute path to the folder you want to
|
35
|
+
save your images to and specify search terms.
|
36
|
+
|
37
|
+
## Development
|
38
|
+
|
39
|
+
After checking out the repo, run `bundle` to install dependencies.
|
40
|
+
|
41
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
42
|
+
|
43
|
+
## Contributing
|
44
|
+
|
45
|
+
1. Fork it ( https://github.com/[my-github-username]/twitter_images/fork )
|
46
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
47
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
48
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
49
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/twitter_images
ADDED
@@ -0,0 +1,171 @@
|
|
1
|
+
require "twitter_images/version"
|
2
|
+
require 'rubygems'
|
3
|
+
require "open-uri"
|
4
|
+
require "fileutils"
|
5
|
+
require "json"
|
6
|
+
require "oauth"
|
7
|
+
require "ruby-progressbar"
|
8
|
+
|
9
|
+
|
10
|
+
module TwitterImages
|
11
|
+
class ImageDownloader
|
12
|
+
attr_accessor :images, :settings
|
13
|
+
|
14
|
+
def initialize(settings, images)
|
15
|
+
@settings = settings
|
16
|
+
@images = images
|
17
|
+
end
|
18
|
+
|
19
|
+
def download
|
20
|
+
settings.prepare
|
21
|
+
images.search
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class Images
|
26
|
+
attr_accessor :images
|
27
|
+
attr_reader :settings
|
28
|
+
|
29
|
+
def initialize(settings)
|
30
|
+
@images = images
|
31
|
+
@settings = settings
|
32
|
+
end
|
33
|
+
|
34
|
+
def search
|
35
|
+
get_images
|
36
|
+
save_images
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def get_images
|
42
|
+
@images = settings.output.inspect.scan(/http:\/\/pbs.twimg.com\/media\/\w+\.(?:jpg|png|gif)/)
|
43
|
+
raise StandardError, "Couldn't find any images" unless @images
|
44
|
+
end
|
45
|
+
|
46
|
+
def make_absolute(href, root)
|
47
|
+
URI.parse(root).merge(URI.parse(href)).to_s
|
48
|
+
end
|
49
|
+
|
50
|
+
def save_images
|
51
|
+
progressbar = ProgressBar.create(:total => images.count)
|
52
|
+
images.each do |src|
|
53
|
+
uri = make_absolute(src, settings.search)
|
54
|
+
File.open(File.basename(uri), 'wb'){ |f| f.write(open(uri).read) }
|
55
|
+
progressbar.increment
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
class Settings
|
61
|
+
attr_accessor :search, :directory, :output, :consumer_key, :access_token,
|
62
|
+
:address, :request, :http, :response
|
63
|
+
|
64
|
+
def initialize()
|
65
|
+
@search = search
|
66
|
+
@directory = directory
|
67
|
+
@output = output
|
68
|
+
@consumer_key = consumer_key
|
69
|
+
@access_token = access_token
|
70
|
+
@address = address
|
71
|
+
@request = request
|
72
|
+
@http = http
|
73
|
+
@response = response
|
74
|
+
end
|
75
|
+
|
76
|
+
def prepare
|
77
|
+
setup_credentials
|
78
|
+
get_directory
|
79
|
+
change_dir
|
80
|
+
get_search
|
81
|
+
establish_connection
|
82
|
+
end
|
83
|
+
|
84
|
+
def establish_connection
|
85
|
+
setup_address
|
86
|
+
setup_http
|
87
|
+
build_request
|
88
|
+
issue_request
|
89
|
+
get_output
|
90
|
+
end
|
91
|
+
|
92
|
+
private
|
93
|
+
|
94
|
+
def setup_credentials
|
95
|
+
decide
|
96
|
+
|
97
|
+
@consumer_key = OAuth::Consumer.new(ENV["CONSUMER_KEY"], ENV["CONSUMER_SECRET"])
|
98
|
+
|
99
|
+
@access_token = OAuth::Token.new(ENV["ACCESS_TOKEN"], ENV["ACCESS_SECRET"])
|
100
|
+
end
|
101
|
+
|
102
|
+
def decide
|
103
|
+
puts "Would your like to update your Twitter credentials now? [y/n]"
|
104
|
+
decision = gets.chomp
|
105
|
+
|
106
|
+
if decision == "y"
|
107
|
+
puts "Please enter your Consumer Key: "
|
108
|
+
ENV["CONSUMER_KEY"] = gets.chomp
|
109
|
+
puts "Please enter your Consumer Secret: "
|
110
|
+
ENV["CONSUMER_SECRET"] = gets.chomp
|
111
|
+
|
112
|
+
puts "Please enter your Access Token: "
|
113
|
+
ENV["ACCESS_TOKEN"] = gets.chomp
|
114
|
+
puts "Please enter your Access Secret: "
|
115
|
+
ENV["ACCESS_SECRET"] = gets.chomp
|
116
|
+
elsif decision == "n"
|
117
|
+
else
|
118
|
+
puts "Wrong answer, please select [y/n]"
|
119
|
+
decide
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def setup_http
|
124
|
+
# Set up Net::HTTP to use SSL, which is required by Twitter.
|
125
|
+
@http = Net::HTTP.new(address.host, address.port)
|
126
|
+
http.use_ssl = true
|
127
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
128
|
+
end
|
129
|
+
|
130
|
+
def build_request
|
131
|
+
# Build the request and authorize it with OAuth.
|
132
|
+
@request = Net::HTTP::Get.new(address.request_uri)
|
133
|
+
request.oauth!(http, consumer_key, access_token)
|
134
|
+
end
|
135
|
+
|
136
|
+
def issue_request
|
137
|
+
# Issue the request and return the response.
|
138
|
+
http.start
|
139
|
+
@response = http.request(request)
|
140
|
+
end
|
141
|
+
|
142
|
+
def get_output
|
143
|
+
@output = JSON.parse(response.body)
|
144
|
+
end
|
145
|
+
|
146
|
+
def setup_address
|
147
|
+
@address = URI("https://api.twitter.com/1.1/search/tweets.json?q=%23#{search}&mode=photos&count=100")
|
148
|
+
end
|
149
|
+
|
150
|
+
def get_directory
|
151
|
+
puts "Please enter the absolute path to the directory to save the images in: "
|
152
|
+
@directory = gets.chomp
|
153
|
+
raise StandardError, "Directory doesn't exist" unless Dir.exists?(@directory)
|
154
|
+
end
|
155
|
+
|
156
|
+
def change_dir
|
157
|
+
Dir.chdir(@directory)
|
158
|
+
end
|
159
|
+
|
160
|
+
def get_search
|
161
|
+
puts "Please enter the search terms: "
|
162
|
+
@search = gets.chomp.gsub(/\s/, "%20")
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
if $0 == __FILE__
|
167
|
+
settings = Settings.new
|
168
|
+
images = Images.new(settings)
|
169
|
+
ImageDownloader.new(settings, images).download
|
170
|
+
end
|
171
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'twitter_images/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "twitter_images"
|
8
|
+
spec.version = TwitterImages::VERSION
|
9
|
+
spec.authors = ["Alexey Zabelin"]
|
10
|
+
spec.email = ["zabelin.alex@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{A CLI tool that downloads the most recent images from twitter based on the search terms provided}
|
13
|
+
spec.description = %q{A CLI tool that downloads the most recent images from twitter based on the search terms provided. Please remember that you need to provide your own
|
14
|
+
consumer key and consumer secret as well as the access token and access token secret. You
|
15
|
+
can find those over here: https://apps.twitter.com Just create a placeholder app
|
16
|
+
and generate the required credentials.}
|
17
|
+
spec.homepage = "https://github.com/Alehanz/twitter_images"
|
18
|
+
|
19
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
if spec.respond_to?(:metadata)
|
24
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
25
|
+
end
|
26
|
+
|
27
|
+
spec.add_dependency "fileutils", "~> 0.7"
|
28
|
+
spec.add_dependency "json", "~> 1.8.2"
|
29
|
+
spec.add_dependency "oauth", "~> 0.4.7"
|
30
|
+
spec.add_dependency "ruby-progressbar", "~> 1.7.5"
|
31
|
+
|
32
|
+
spec.add_development_dependency "bundler", "~> 1.8"
|
33
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
34
|
+
spec.add_development_dependency "rspec"
|
35
|
+
spec.add_development_dependency "coveralls", "~> 0.8.1"
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,173 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: twitter_images
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alexey Zabelin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: fileutils
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.7'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: json
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.8.2
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.8.2
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: oauth
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.4.7
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.4.7
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: ruby-progressbar
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.7.5
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.7.5
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.8'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.8'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '10.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '10.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: coveralls
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 0.8.1
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 0.8.1
|
125
|
+
description: |-
|
126
|
+
A CLI tool that downloads the most recent images from twitter based on the search terms provided. Please remember that you need to provide your own
|
127
|
+
consumer key and consumer secret as well as the access token and access token secret. You
|
128
|
+
can find those over here: https://apps.twitter.com Just create a placeholder app
|
129
|
+
and generate the required credentials.
|
130
|
+
email:
|
131
|
+
- zabelin.alex@gmail.com
|
132
|
+
executables:
|
133
|
+
- twitter_images
|
134
|
+
extensions: []
|
135
|
+
extra_rdoc_files: []
|
136
|
+
files:
|
137
|
+
- ".gitignore"
|
138
|
+
- ".rspec"
|
139
|
+
- ".ruby-version"
|
140
|
+
- ".travis.yml"
|
141
|
+
- Gemfile
|
142
|
+
- README.md
|
143
|
+
- Rakefile
|
144
|
+
- bin/twitter_images
|
145
|
+
- lib/twitter_images.rb
|
146
|
+
- lib/twitter_images/version.rb
|
147
|
+
- twitter_images.gemspec
|
148
|
+
homepage: https://github.com/Alehanz/twitter_images
|
149
|
+
licenses: []
|
150
|
+
metadata:
|
151
|
+
allowed_push_host: https://rubygems.org
|
152
|
+
post_install_message:
|
153
|
+
rdoc_options: []
|
154
|
+
require_paths:
|
155
|
+
- lib
|
156
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
157
|
+
requirements:
|
158
|
+
- - ">="
|
159
|
+
- !ruby/object:Gem::Version
|
160
|
+
version: '0'
|
161
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
162
|
+
requirements:
|
163
|
+
- - ">="
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '0'
|
166
|
+
requirements: []
|
167
|
+
rubyforge_project:
|
168
|
+
rubygems_version: 2.4.5
|
169
|
+
signing_key:
|
170
|
+
specification_version: 4
|
171
|
+
summary: A CLI tool that downloads the most recent images from twitter based on the
|
172
|
+
search terms provided
|
173
|
+
test_files: []
|