android_reviews 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8aa10d844718876bba16958406f8c051903e2cbb
4
+ data.tar.gz: b341d934c1bcc44eca3f2e38cf44d7447747d213
5
+ SHA512:
6
+ metadata.gz: cfcaccad6c65fa527e53050dd7fb5f56175b8c64249a1244aa344a2732c86f5324a70f009b17c9fd8e8715caaa199cf38b93671932601e4f340b1c8f669abda5
7
+ data.tar.gz: 34840720e6f1d417248a2fcc9088e010597321d336f7031d050544db2e06e43c3b466f22114395198a6e4b4f8674bc32a24cb6054b61d0760fdd07fef0b6195d
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.10.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in android_reviews.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Carl Mercier
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.
@@ -0,0 +1,38 @@
1
+ # AndroidReviews
2
+
3
+ Simple Ruby Gem to scrape Android reviews from the Google Play Store
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'android_reviews'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install android_reviews
20
+
21
+ ## Usage
22
+
23
+ `ar = AndroidReviews.new 'com.facebook.katana'
24
+ ar.reviews # => returns an array
25
+ ar.each_review do |review| # => yields as reviews are scraped. Recommended.
26
+ puts review
27
+ end
28
+ `
29
+
30
+ ## Contributing
31
+
32
+ Bug reports and pull requests are welcome on GitHub at https://github.com/cmer/android_reviews.
33
+
34
+
35
+ ## License
36
+
37
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
38
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'android_reviews/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "android_reviews"
8
+ spec.version = AndroidReviews::VERSION
9
+ spec.authors = ["Carl Mercier"]
10
+ spec.email = ["carl@carlmercier.com"]
11
+
12
+ spec.summary = %q{Android Play Store app reviews scraper for Ruby}
13
+ spec.description = %q{Android Play Store app reviews scraper for Ruby}
14
+ spec.homepage = "http://github.com/cmer/android_reviews"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency('nokogiri', '~> 1.6.7rc3')
23
+ spec.add_dependency('rest-client', '~> 2.0.0rc2')
24
+ spec.add_development_dependency "bundler", "~> 1.10"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.4"
27
+ spec.add_development_dependency "vcr", "~> 3.0"
28
+ spec.add_development_dependency "webmock"
29
+ spec.add_development_dependency "byebug"
30
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "android_reviews"
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
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,92 @@
1
+ require 'android_reviews/version'
2
+ require 'android_reviews/throttled_error'
3
+ require 'object'
4
+ require 'rest-client'
5
+ require 'nokogiri'
6
+
7
+ class AndroidReviews
8
+ attr_accessor :pages_per_minute, :language, :user_agent, :review_sort_order, :review_type
9
+
10
+ URL = "https://play.google.com/store/getreviews?authuser=0"
11
+ DEFAULT_USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36"
12
+
13
+ def initialize(app_id, pages_per_minute: 6, language: 'en', user_agent: DEFAULT_USER_AGENT)
14
+ @app_id = app_id
15
+ @pages_per_minute = pages_per_minute
16
+ @language = language
17
+ @user_agent = user_agent
18
+ @review_sort_order = 0
19
+ @review_type = 0
20
+ end
21
+
22
+ def each_review
23
+ count = 0
24
+ current_page = 0
25
+
26
+ while body = fetch(current_page)
27
+ body.gsub!(/^\)\]\}\'/, '')
28
+ parsed = JSON.parse(body)
29
+ html = parsed[0][2]
30
+ html_doc = Nokogiri::HTML(html)
31
+
32
+ html_doc.css('.single-review').each do |node|
33
+ count += 1
34
+ review = review_from_node(node)
35
+ yield review
36
+ end # review loop
37
+
38
+ current_page += 1
39
+ throttle_sleep
40
+ end # page loop
41
+
42
+ count
43
+ end
44
+
45
+ def reviews
46
+ reviews = []
47
+ each_review do |r|
48
+ reviews << r
49
+ end
50
+ reviews
51
+ end
52
+
53
+ protected
54
+ def fetch(page)
55
+ headers = {
56
+ "origin" => "https://play.google.com",
57
+ "accept-encoding" => "gzip, deflate",
58
+ "accept-language" => "en-US,en;q=0.8",
59
+ "user-agent" => @user_agent,
60
+ "content-type" => "application/x-www-form-urlencoded;charset=UTF-8",
61
+ "accept" => "*/*",
62
+ "referer" => "https://play.google.com/store/apps/details?id=#{@app_id}&hl=#{@language}",
63
+ "authority" => "play.google.com"
64
+ }
65
+
66
+ data = "reviewType=#{@review_type}&pageNum=#{page}&id=#{@app_id}&reviewSortOrder=#{@review_sort_order}&xhr=1&hl=#{@language}"
67
+
68
+ response = nil
69
+ begin
70
+ response = RestClient.post URL, data, headers
71
+ response.code == 200 ? response.body : nil
72
+ rescue RestClient::Found
73
+ raise ThrottledError
74
+ nil
75
+ end
76
+ end
77
+
78
+ def review_from_node(node)
79
+ {
80
+ author_name: node.css('.author-name a').text.strip,
81
+ review_date: Date.parse(node.css('.review-date').text.strip),
82
+ rating: node.css('.review-info-star-rating .tiny-star').attr('aria-label').text.match(/([1-5])/)[0].strip,
83
+ title: node.css('.review-title').text.strip,
84
+ body: node.search('.review-body').xpath('text()').text.strip,
85
+ avatar_url: node.css('.responsive-img-hdpi .author-image').attr('style').text.match(/\((.*)\)/)[1]
86
+ }
87
+ end
88
+
89
+ def throttle_sleep
90
+ sleep(60 / pages_per_minute.to_f) if pages_per_minute
91
+ end
92
+ end
@@ -0,0 +1,7 @@
1
+ class AndroidReviews
2
+ class ThrottledError < StandardError
3
+ def initialize(msg="Google Play Store throttled you!")
4
+ super(msg)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ class AndroidReviews
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,9 @@
1
+ class Object
2
+ def blank?
3
+ respond_to?(:empty?) ? empty? : !self
4
+ end
5
+
6
+ def present?
7
+ !blank?
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,171 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: android_reviews
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Carl Mercier
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-11-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.6.7rc3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.6.7rc3
27
+ - !ruby/object:Gem::Dependency
28
+ name: rest-client
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 2.0.0rc2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 2.0.0rc2
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.4'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.4'
83
+ - !ruby/object:Gem::Dependency
84
+ name: vcr
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
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: byebug
113
+ requirement: !ruby/object:Gem::Requirement
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
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: Android Play Store app reviews scraper for Ruby
126
+ email:
127
+ - carl@carlmercier.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - ".rspec"
134
+ - ".travis.yml"
135
+ - Gemfile
136
+ - LICENSE.txt
137
+ - README.md
138
+ - Rakefile
139
+ - android_reviews.gemspec
140
+ - bin/console
141
+ - bin/setup
142
+ - lib/android_reviews.rb
143
+ - lib/android_reviews/throttled_error.rb
144
+ - lib/android_reviews/version.rb
145
+ - lib/object.rb
146
+ homepage: http://github.com/cmer/android_reviews
147
+ licenses:
148
+ - MIT
149
+ metadata: {}
150
+ post_install_message:
151
+ rdoc_options: []
152
+ require_paths:
153
+ - lib
154
+ required_ruby_version: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - ">="
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ required_rubygems_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ requirements: []
165
+ rubyforge_project:
166
+ rubygems_version: 2.4.5
167
+ signing_key:
168
+ specification_version: 4
169
+ summary: Android Play Store app reviews scraper for Ruby
170
+ test_files: []
171
+ has_rdoc: