kansou 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: 7ebef03ef65f002dee29af40bd1999d55620b6de
4
+ data.tar.gz: 09e29408067cba750290fac63a2e1df77d120890
5
+ SHA512:
6
+ metadata.gz: a0d9f1caebc81233a49728548d390e5c151aeb28d63578193df56dcd5a617cc08b01505f1eb4e46c63ddc68de98a98e861e1de037596dabce914a1a02bb3584a
7
+ data.tar.gz: 615f2c62c47fef5c1a0486993d2f4af153a0e96a828bd0b6efec9a4dbca041d422216fde7185511f5b033dc510c2edcd57e4ad14f9f4ec95e3bc028f9b64a01a
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ .DS_Store
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in kansou.gemspec
4
+ gemspec
@@ -0,0 +1,44 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ kansou (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ansi (1.5.0)
10
+ ast (2.1.0)
11
+ diff-lcs (1.2.5)
12
+ oga (1.3.1)
13
+ ast
14
+ ruby-ll (~> 2.1)
15
+ rake (10.4.2)
16
+ rspec (3.3.0)
17
+ rspec-core (~> 3.3.0)
18
+ rspec-expectations (~> 3.3.0)
19
+ rspec-mocks (~> 3.3.0)
20
+ rspec-core (3.3.2)
21
+ rspec-support (~> 3.3.0)
22
+ rspec-expectations (3.3.1)
23
+ diff-lcs (>= 1.2.0, < 2.0)
24
+ rspec-support (~> 3.3.0)
25
+ rspec-mocks (3.3.2)
26
+ diff-lcs (>= 1.2.0, < 2.0)
27
+ rspec-support (~> 3.3.0)
28
+ rspec-support (3.3.0)
29
+ ruby-ll (2.1.2)
30
+ ansi
31
+ ast
32
+
33
+ PLATFORMS
34
+ ruby
35
+
36
+ DEPENDENCIES
37
+ bundler (~> 1.9)
38
+ kansou!
39
+ oga
40
+ rake (~> 10.0)
41
+ rspec
42
+
43
+ BUNDLED WITH
44
+ 1.10.6
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 punchdrunker
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,55 @@
1
+ # THIS LIBRARY IS WORK IN PROGRESS
2
+
3
+ # Kansou
4
+
5
+ https://circleci.com/gh/punchdrunker/kansou.png?circle-token=bfc0f99f7488f950f6e1743d65247a1f28d071c5
6
+
7
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/kansou`. To experiment with that code, run `bin/console` for an interactive prompt.
8
+
9
+ TODO: Delete this and the text above, and describe your gem
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'kansou'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install kansou
26
+
27
+ ## Usage
28
+
29
+ ```
30
+ require 'kansou'
31
+
32
+ # reviews for Android app
33
+ review = Kansou::GooglePlayReview.new("jp.mixi")
34
+ p review.fetch # => prints reviews as array
35
+
36
+ # reviews for iOS app
37
+ review = Kansou::AppStoreReview.new(285951864)
38
+ p review.fetch # => prints reviews as array
39
+ ```
40
+
41
+ ## Development
42
+
43
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
44
+
45
+ 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`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
46
+
47
+ ## Contributing
48
+
49
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/kansou. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
50
+
51
+
52
+ ## License
53
+
54
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
55
+
@@ -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,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "kansou"
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,2 @@
1
+ machine:
2
+ timezone: Asia/Tokyo
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'kansou/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "kansou"
8
+ spec.version = Kansou::VERSION
9
+ spec.authors = ["punchdrunker"]
10
+ spec.email = ["takafumi.nanao@mixi.co.jp"]
11
+
12
+ spec.summary = %q{scraping app reviews in google play store and ios app store}
13
+ spec.description = %q{Kansou is scraping tool for user reviews of smart phone apps}
14
+ spec.homepage = "https://github.com/punchdrunker/kansou"
15
+ spec.license = "MIT"
16
+
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.9"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec"
26
+ spec.add_development_dependency "oga"
27
+ end
@@ -0,0 +1,6 @@
1
+ require "kansou/version"
2
+ require "kansou/app_store_review"
3
+ require "kansou/google_play_review"
4
+
5
+ module Kansou
6
+ end
@@ -0,0 +1,108 @@
1
+ require 'open-uri'
2
+ require 'oga'
3
+
4
+ module Kansou
5
+ class AppStoreReview
6
+ def initialize(app_id)
7
+ return nil unless app_id
8
+
9
+ @app_id = app_id
10
+ end
11
+ def fetch(page_amount=1)
12
+ reviews = []
13
+ max_page = page_amount - 1
14
+ (0..max_page).each do |page|
15
+ xml = download(page)
16
+ reviews.concat(parse(xml))
17
+ end
18
+ return reviews
19
+ end
20
+
21
+ def download(page=0)
22
+ base_url = "https://itunes.apple.com"
23
+ user_agent = "iTunes/9.2 (Windows; Microsoft Windows 7 "\
24
+ + "Home Premium Edition (Build 7600)) AppleWebKit/533.16"
25
+
26
+ url = base_url + "/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id="\
27
+ + @app_id.to_s + "&pageNumber="+page.to_s+"&sortOrdering=4&type=Purple+Software"
28
+ xml = open(url, 'User-Agent' => user_agent, 'X-Apple-Store-Front' => '143462-1').read
29
+ return xml
30
+ end
31
+
32
+ def parse(xml)
33
+ items = []
34
+ users = []
35
+ versions = []
36
+ dates = []
37
+ i = 0
38
+ document = Oga.parse_xml(xml)
39
+
40
+ expression = 'TextView[topInset="0"][styleSet="basic13"][squishiness="1"][leftInset="0"][truncation="right"][textJust="left"][maxLines="1"]'
41
+ document.css(expression).each do |elm|
42
+ if elm.text =~ /by/
43
+ tmp_array = elm.text.gsub(" ", "").split("\n")
44
+ info = []
45
+ tmp_array.each do |v|
46
+ if v!=""&&v!="-"&&v!="by"
47
+ info.push v
48
+ end
49
+ end
50
+ users.push info[0]
51
+
52
+ if info[1]
53
+ versions.push(get_version(info[1]))
54
+ else
55
+ versions.push("")
56
+ end
57
+
58
+ if info[2]
59
+ dates.push(info[2])
60
+ else
61
+ dates.push("")
62
+ end
63
+ end
64
+ end
65
+
66
+ titles = []
67
+ document.css('TextView[styleSet="basic13"][textJust="left"][maxLines="1"]').each do |elm|
68
+ elm.css('b').each do |e|
69
+ titles.push e.text
70
+ end
71
+ end
72
+
73
+ stars = []
74
+ document.css('HBoxView[topInset="1"]').each do |elm|
75
+ stars.push elm.attribute("alt").value.gsub(/ stars*/,"")
76
+ end
77
+
78
+ bodies = []
79
+ document.css('TextView[styleSet="normal11"]').each do |elm|
80
+ bodies.push(elm.text.gsub("\n", "<br />"))
81
+ end
82
+
83
+ count = stars.size - 1
84
+ (0..count).each do |key|
85
+ item = {
86
+ :star => stars[key],
87
+ :user => users[key],
88
+ :date => dates[key],
89
+ :title => titles[key],
90
+ :body => bodies[key],
91
+ :version => versions[key],
92
+ :app_id => @app_id
93
+ }
94
+ items.push(item)
95
+ end
96
+ return items
97
+ end
98
+
99
+ def get_version(text)
100
+ version = nil
101
+ if /Version([\d\.]+)/ =~ text
102
+ version = $1
103
+ end
104
+ return version
105
+ end
106
+
107
+ end
108
+ end
@@ -0,0 +1,85 @@
1
+ require 'json'
2
+ require 'oga'
3
+
4
+ module Kansou
5
+ class GooglePlayReview
6
+ def initialize(app_id)
7
+ return nil unless app_id
8
+
9
+ @app_id = app_id
10
+ end
11
+
12
+ def fetch(pages=1)
13
+ reviews = []
14
+ pages.times do |page|
15
+ result = download(@app_id, page)
16
+ if result
17
+ reviews.concat(parse(result))
18
+ end
19
+ end
20
+ return reviews
21
+ end
22
+
23
+ private
24
+ def download(app_id, page=0)
25
+ http = Net::HTTP.new('play.google.com', 443)
26
+ http.use_ssl = true
27
+ path = "/store/getreviews"
28
+ data = "id=#{app_id}&reviewSortOrder=0&reviewType=1&pageNum=#{page}"
29
+ response = http.post(path, data)
30
+ return response.body
31
+ end
32
+
33
+ def parse(input_text)
34
+ input_text = remove_unused_lines(input_text)
35
+ json = JSON.load(input_text)
36
+ body = json[0][2]
37
+
38
+ titles = []
39
+ bodies = []
40
+ dates = []
41
+ stars = []
42
+ authors = []
43
+ document = Oga.parse_html(body)
44
+ main_expression = 'div[class="single-review"]'
45
+ title_expression = 'span[class="review-title"]'
46
+ body_expression = 'div[class="review-body"]'
47
+ date_expression = 'span[class="review-date"]'
48
+ star_expression = 'div[class="current-rating"]'
49
+ author_expression = 'span[class="author-name"]'
50
+
51
+ document.css(main_expression).each do |elm|
52
+ elm.css(title_expression).each { |title_node| titles.push(title_node.text) }
53
+ elm.css(body_expression).each { |body_node| bodies.push(body_node.text) }
54
+ elm.css(date_expression).each { |date_node| dates.push(date_node.text) }
55
+ elm.css(star_expression).each { |star_node| stars.push(process_star_count(star_node)) }
56
+ elm.css(author_expression).each { |author_node| authors.push(author_node.text.strip) }
57
+ end
58
+
59
+ reviews = []
60
+ count = stars.size - 1
61
+ (0..count).each do |key|
62
+ item = {
63
+ :star => stars[key],
64
+ :user => authors[key],
65
+ :date => dates[key],
66
+ :title => titles[key],
67
+ :body => bodies[key],
68
+ :app_id => @app_id
69
+ }
70
+ reviews.push(item)
71
+ end
72
+ return reviews
73
+ end
74
+
75
+ def remove_unused_lines(text)
76
+ lines = text.split("\n")
77
+ return lines[2] + "]"
78
+ end
79
+
80
+ def process_star_count(node)
81
+ widths = node.attribute("style").value.match("width: ([0-9]+)")
82
+ star = widths[1].to_i / 20
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,3 @@
1
+ module Kansou
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,58 @@
1
+ require 'open-uri'
2
+
3
+ # this is a script to get sample data for test.
4
+ # set constatns below
5
+ # usage:
6
+ # ruby sample_data_fetcher.rb
7
+
8
+ APP_STORE_APP_ID = "000000000"
9
+ GOOGLE_PLAY_APP_ID = "com.example"
10
+ GSUTIL_PATH = "/path/to/gsutil"
11
+ BUCKET_ID = "pubsite_prod_rev_00000000000000000000"
12
+
13
+ def fetch_app_store_reviews
14
+ base_url = "https://itunes.apple.com"
15
+ user_agent = "iTunes/9.2 (Windows; Microsoft Windows 7 "\
16
+ + "Home Premium Edition (Build 7600)) AppleWebKit/533.16"
17
+
18
+ page = 0
19
+ url = base_url + "/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id="\
20
+ + APP_STORE_APP_ID + "&pageNumber="+page.to_s+"&sortOrdering=4&type=Purple+Software"
21
+ xml = open(url, 'User-Agent' => user_agent, 'X-Apple-Store-Front' => '143462-1').read
22
+ return xml
23
+ end
24
+
25
+ def fetch_google_play_reviews
26
+ csv = _get_csv_name
27
+ result = _copy_csv(csv)
28
+ end
29
+
30
+ def _get_csv_name
31
+ ym = Time.now.strftime("%Y%m")
32
+ csv = "reviews_#{GOOGLE_PLAY_APP_ID}_#{ym}.csv"
33
+ return csv
34
+ end
35
+
36
+ def _copy_csv(csv)
37
+ return -1 unless GSUTIL_PATH
38
+ return -1 unless BUCKET_ID
39
+
40
+ cmd = GSUTIL_PATH
41
+ bucket_id = BUCKET_ID
42
+ value = `#{cmd} cp gs://#{bucket_id}/reviews/#{csv} ./`
43
+ return 1 if $?.exited?
44
+ return -1
45
+ end
46
+
47
+
48
+ if APP_STORE_APP_ID
49
+ xml = fetch_app_store_reviews
50
+ file_name = "app_store_reviews.xml"
51
+ File.open(file_name, 'w') {|file|
52
+ file.write xml
53
+ }
54
+ end
55
+
56
+ if GOOGLE_PLAY_APP_ID && GSUTIL_PATH && BUCKET_ID
57
+ fetch_google_play_reviews
58
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kansou
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - punchdrunker
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-12-22 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.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
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: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: oga
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Kansou is scraping tool for user reviews of smart phone apps
70
+ email:
71
+ - takafumi.nanao@mixi.co.jp
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - CODE_OF_CONDUCT.md
80
+ - Gemfile
81
+ - Gemfile.lock
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - bin/console
86
+ - bin/setup
87
+ - circle.yml
88
+ - kansou.gemspec
89
+ - lib/kansou.rb
90
+ - lib/kansou/app_store_review.rb
91
+ - lib/kansou/google_play_review.rb
92
+ - lib/kansou/version.rb
93
+ - tool/sample_data_fetcher.rb
94
+ homepage: https://github.com/punchdrunker/kansou
95
+ licenses:
96
+ - MIT
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.4.5.1
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: scraping app reviews in google play store and ios app store
118
+ test_files: []