backupmypics 0.1.0
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 +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +56 -0
- data/Rakefile +6 -0
- data/backupmypics.gemspec +26 -0
- data/bin/backupmypics +17 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/backupmypics.rb +40 -0
- data/lib/backupmypics/version.rb +3 -0
- metadata +142 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 12b95b0a11fb751c62d2d75d3f2618c6af156d2a
|
4
|
+
data.tar.gz: 1b6cd9cf4e9a800f95f6273ef5e47766d1572876
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 29a31d9bf57840e0a2228c172996cb0a31ab54d7fae8432dad702eeb324e4a3598b6cf95fa478371a41f57775c28462c756d1ad2e2b073312971a107e9ec74ee
|
7
|
+
data.tar.gz: f80f3753bb173b00d9a127d8c98fe01294be054688aca3998a0205be36dc1d4ef0352da528a6dfedc5a753302e1de251d7b21b52c5175025184346a646e61610
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 TODO: Write your name
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# Backupmypics
|
2
|
+
|
3
|
+
A simple gem to download pictures from an instagram profile through the CLI.
|
4
|
+
|
5
|
+
# I just developed this gem to study the Ruby language...
|
6
|
+
|
7
|
+
While developing this gem I gave my first steps in the language and could:
|
8
|
+
|
9
|
+
- Get familiar with the language (and [Ruby docs](#)!)
|
10
|
+
- Get to know and use RSpec and Nokogiri
|
11
|
+
- Learn the basics of how to create ruby gems
|
12
|
+
|
13
|
+
|
14
|
+
## Installation
|
15
|
+
|
16
|
+
Add this line to your application's Gemfile:
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
gem 'backupmypics'
|
20
|
+
```
|
21
|
+
|
22
|
+
And then execute:
|
23
|
+
|
24
|
+
$ bundle
|
25
|
+
|
26
|
+
Or install it yourself as:
|
27
|
+
|
28
|
+
$ gem install backupmypics
|
29
|
+
|
30
|
+
## Usage
|
31
|
+
|
32
|
+
At this time, it has some limitations:
|
33
|
+
|
34
|
+
- Can't handle private profiles. Only public ones.
|
35
|
+
- It only downloads the first ~9 pictures displayed when you access your profile. It's not requesting the next pages.
|
36
|
+
- Downloads all the pictures to a folder named `backupmypics` in your user home directory. Make sure it exists and have write access!
|
37
|
+
|
38
|
+
As soon as you have the gem installed, accessible through your CLI and you know the limitations, just type:
|
39
|
+
|
40
|
+
$ backupmypics -u my_instagram_username
|
41
|
+
|
42
|
+
...and wait the pictures come!
|
43
|
+
|
44
|
+
## TODO
|
45
|
+
|
46
|
+
- [ ] Add tests correctly
|
47
|
+
- [ ] Add async calls to get user data and download the pictures faster
|
48
|
+
- [ ] Download all the pictures from all pages, not only from the first page
|
49
|
+
- [ ] Add an option to user choose where to save the pictures
|
50
|
+
- [ ] Add Rubocop, Travis and CodeClimate
|
51
|
+
|
52
|
+
|
53
|
+
## License
|
54
|
+
|
55
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
56
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'backupmypics/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "backupmypics"
|
8
|
+
spec.version = Backupmypics::VERSION
|
9
|
+
spec.authors = ["Bruno Schmidt"]
|
10
|
+
spec.email = ["bruunoxp2@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Downloads all the photos from an user on instagram}
|
13
|
+
spec.homepage = "https://github.com/brunoschmello/backupmypics"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.executables = ["backupmypics"]
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
21
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
22
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
23
|
+
spec.add_dependency "nokogiri", "~> 1.6"
|
24
|
+
spec.add_dependency "json", "~> 2.0"
|
25
|
+
spec.add_dependency "chainable_methods", "~> 0.2"
|
26
|
+
end
|
data/bin/backupmypics
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'backupmypics'
|
3
|
+
require 'chainable_methods'
|
4
|
+
require 'optparse'
|
5
|
+
|
6
|
+
options = {}
|
7
|
+
OptionParser.new do |opts|
|
8
|
+
opts.on("-u USERNAME", "--username=USERNAME", "The instagram profile username that will have it's pics downloaded'") do |v|
|
9
|
+
options[:username] = v
|
10
|
+
end
|
11
|
+
end.parse!
|
12
|
+
|
13
|
+
CM(options[:username])
|
14
|
+
.Backupmypics.fetch_user_data
|
15
|
+
.Backupmypics.extract_pictures
|
16
|
+
.Backupmypics.download
|
17
|
+
.unwrap
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "backupmypics"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/backupmypics.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require "backupmypics/version"
|
2
|
+
require "open-uri"
|
3
|
+
require 'nokogiri'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
module Backupmypics
|
7
|
+
|
8
|
+
def self.fetch_user_data(user)
|
9
|
+
doc = Nokogiri::HTML(open(URI("https://instagram.com/#{user}")))
|
10
|
+
scripts = doc.css("body > script")[2].text
|
11
|
+
JSON.parse(scripts[21..-2])["entry_data"]["ProfilePage"][0]
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.extract_pictures(user_data)
|
15
|
+
pictures = Array.new
|
16
|
+
|
17
|
+
user_data["user"]["media"]["nodes"].each do |node|
|
18
|
+
pictures.push({node["code"] => node["display_src"]})
|
19
|
+
end
|
20
|
+
|
21
|
+
if user_data["user"]["media"]["page_info"]["has_next_page"]
|
22
|
+
return {:pictures => pictures, :next_id => user_data["user"]["media"]["page_info"]["end_cursor"]}
|
23
|
+
end
|
24
|
+
{:pictures => pictures, :next_id => nil}
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.download(items)
|
28
|
+
items[:pictures].each do |item|
|
29
|
+
name = item.keys.first
|
30
|
+
url = item.values.first
|
31
|
+
|
32
|
+
Dir.chdir("#{Dir.home}/backupmypics")
|
33
|
+
|
34
|
+
puts "Trying to save #{name} to #{Dir.home}/backupmypics"
|
35
|
+
File.open("#{name}.jpg", "wb") do |fo|
|
36
|
+
fo.write open(URI(url)).read
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
metadata
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: backupmypics
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bruno Schmidt
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-11-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.12'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: nokogiri
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.6'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.6'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: json
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: chainable_methods
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.2'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.2'
|
97
|
+
description:
|
98
|
+
email:
|
99
|
+
- bruunoxp2@gmail.com
|
100
|
+
executables:
|
101
|
+
- backupmypics
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".gitignore"
|
106
|
+
- ".rspec"
|
107
|
+
- ".travis.yml"
|
108
|
+
- Gemfile
|
109
|
+
- LICENSE.txt
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- backupmypics.gemspec
|
113
|
+
- bin/backupmypics
|
114
|
+
- bin/console
|
115
|
+
- bin/setup
|
116
|
+
- lib/backupmypics.rb
|
117
|
+
- lib/backupmypics/version.rb
|
118
|
+
homepage: https://github.com/brunoschmello/backupmypics
|
119
|
+
licenses:
|
120
|
+
- MIT
|
121
|
+
metadata: {}
|
122
|
+
post_install_message:
|
123
|
+
rdoc_options: []
|
124
|
+
require_paths:
|
125
|
+
- lib
|
126
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
requirements: []
|
137
|
+
rubyforge_project:
|
138
|
+
rubygems_version: 2.6.8
|
139
|
+
signing_key:
|
140
|
+
specification_version: 4
|
141
|
+
summary: Downloads all the photos from an user on instagram
|
142
|
+
test_files: []
|