gramscraper 0.0.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.
- checksums.yaml +7 -0
- data/lib/gramscraper.rb +56 -0
- metadata +45 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: bb199df60b20ff966719255379c5ad733e0d0620
|
|
4
|
+
data.tar.gz: a8e8eb0124fab7bf5546a88daec57a9c50878a42
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 19b98973b231b04e86480f54c6dd7ae1b43b301d548331231cec5ca93cabba3792b8f8a6a24d00a80a8e78331b4f29e8801cabe8318a1d32dcc704de79ae2fa7
|
|
7
|
+
data.tar.gz: afd47a211e4292d5bc1239553682a2ce6d50c51a896b637e4f45af3b13f9acb70fee4acef35d7e4598eb6cbd19e229c45b9962db7436f4595f8278ec6ebcc4ab
|
data/lib/gramscraper.rb
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
require 'httparty'
|
|
2
|
+
|
|
3
|
+
class Gramscraper
|
|
4
|
+
|
|
5
|
+
def self.scrape(username)
|
|
6
|
+
# Base URL for instagram media
|
|
7
|
+
base_url = "https://www.instagram.com/#{username}/media"
|
|
8
|
+
|
|
9
|
+
# Initialise the url (without max_id token)
|
|
10
|
+
url = base_url
|
|
11
|
+
|
|
12
|
+
# Initialise instagram array
|
|
13
|
+
instagram = Array.new
|
|
14
|
+
|
|
15
|
+
while true
|
|
16
|
+
# Use HTTParty to retrieve the JSON response
|
|
17
|
+
page = HTTParty.get(url).parsed_response
|
|
18
|
+
|
|
19
|
+
# Reset last_id
|
|
20
|
+
last_id = ""
|
|
21
|
+
|
|
22
|
+
page["items"].each do |page_item|
|
|
23
|
+
|
|
24
|
+
# Post ID
|
|
25
|
+
last_id = page_item["id"]
|
|
26
|
+
|
|
27
|
+
# Image Caption
|
|
28
|
+
caption = page_item["caption"]["text"] unless page_item["caption"].nil?
|
|
29
|
+
|
|
30
|
+
# Get images in every resolution available
|
|
31
|
+
thumbnail = page_item["images"]["thumbnail"]["url"] unless page_item["images"].nil?
|
|
32
|
+
low_resolution = page_item["images"]["low_resolution"]["url"] unless page_item["images"].nil?
|
|
33
|
+
standard_resolution = page_item["images"]["standard_resolution"]["url"] unless page_item["images"].nil?
|
|
34
|
+
|
|
35
|
+
# Copy data to hash
|
|
36
|
+
instagram_item = {
|
|
37
|
+
:last_id => last_id, :caption => caption, :thumbnail => thumbnail, :low_resolution => low_resolution, :standard_resolution => standard_resolution,
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
# Add instagram item hash to array
|
|
41
|
+
instagram << instagram_item
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# If there are more photos to scraper, capture the last_id and use it as token to ?max_id=
|
|
45
|
+
if page["more_available"]==true
|
|
46
|
+
next_page_token = "/?max_id=#{last_id}" # e.g. /?max_id=1537732482693479519_54429723
|
|
47
|
+
url = base_url + next_page_token
|
|
48
|
+
|
|
49
|
+
# Else there are no more photos so end the loop
|
|
50
|
+
else
|
|
51
|
+
break
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
instagram
|
|
55
|
+
end
|
|
56
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: gramscraper
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Glenn Dimaliwat
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2017-10-11 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: A simple instagram scraping gem which retrieves all your photos (thumbnails,
|
|
14
|
+
low res, standard res) in instagram with image caption
|
|
15
|
+
email: glenn.dimaliwat@gmail.com
|
|
16
|
+
executables: []
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- lib/gramscraper.rb
|
|
21
|
+
homepage: http://rubygems.org/gems/gramscraper
|
|
22
|
+
licenses:
|
|
23
|
+
- MIT
|
|
24
|
+
metadata: {}
|
|
25
|
+
post_install_message:
|
|
26
|
+
rdoc_options: []
|
|
27
|
+
require_paths:
|
|
28
|
+
- lib
|
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
35
|
+
requirements:
|
|
36
|
+
- - ">="
|
|
37
|
+
- !ruby/object:Gem::Version
|
|
38
|
+
version: '0'
|
|
39
|
+
requirements: []
|
|
40
|
+
rubyforge_project:
|
|
41
|
+
rubygems_version: 2.6.11
|
|
42
|
+
signing_key:
|
|
43
|
+
specification_version: 4
|
|
44
|
+
summary: Instagram Photo Scraper
|
|
45
|
+
test_files: []
|