yoyakutopten_scraper 0.0.2

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f2a680e79e875eba5b048a093dbb1816d430f388
4
+ data.tar.gz: 31969cc6a82f9258a250288010942b0c81a09ed5
5
+ SHA512:
6
+ metadata.gz: 3a397e45fd3a773e6b060fa7d49d6aca825dbf7789cb4bddf2a9e795b2d5040d57d3308a273dcefe25ec18f45e812a979ab853db3742bf3b764d6d91f4fb0592
7
+ data.tar.gz: 1a36aabf32e8ad59f22f3b920020771fb43e17dfb701276c10e4d3899cfb8d3747cb12c326a8516ec0a815b6078274ea17b9b88ed708f9e2b195ead2d03ba229
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.swp
19
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in yoyakutopten_scraper.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 ryysd
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # YoyakutoptenScraper
2
+
3
+ scraper for https://yoyaku-top10.jp.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'yoyakutopten_scraper'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install yoyakutopten_scraper
18
+
19
+ ## Usage
20
+
21
+ ## Contributing
22
+
23
+ 1. Fork it ( http://github.com/<my-github-username>/yoyakutopten_scraper/fork )
24
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
25
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
26
+ 4. Push to the branch (`git push origin my-new-feature`)
27
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/lib/test.rb ADDED
@@ -0,0 +1,14 @@
1
+ require 'yoyakutopten_scraper'
2
+
3
+ ranking = YoyakutoptenScraper::Ranking.new os_type: :ios, feed: :daily
4
+ ranking.update
5
+
6
+ app = ranking.results.first
7
+
8
+ app_detail = YoyakutoptenScraper::App.new app_id: app[:app_id], os_type: app[:os_type]
9
+ bonus_detail = YoyakutoptenScraper::Bonus.new bonus_id: app[:bonus_id], os_type: app[:os_type]
10
+
11
+ app_detail.update
12
+ p app_detail
13
+ bonus_detail.update
14
+ p bonus_detail
@@ -0,0 +1,12 @@
1
+ require "yoyakutopten_scraper/version"
2
+ require 'typhoeus'
3
+ require 'nokogiri'
4
+
5
+ require 'yoyakutopten_scraper/util'
6
+ require 'yoyakutopten_scraper/constant'
7
+ require 'yoyakutopten_scraper/ranking'
8
+ require 'yoyakutopten_scraper/app'
9
+ require 'yoyakutopten_scraper/bonus'
10
+
11
+ module YoyakutoptenScraper
12
+ end
@@ -0,0 +1,72 @@
1
+ module YoyakutoptenScraper
2
+ class App
3
+ def initialize(app_id:, os_type:)
4
+ @app_id = app_id
5
+ @os_type = os_type
6
+ end
7
+
8
+ def parse(html)
9
+ detail = (html.css '.app_detail_box').first
10
+ icon = (detail.css '.app_detail_img').first
11
+ title = (detail.css 'h1').first
12
+ publisher = (detail.css '.app_company').first
13
+ release = ((detail.css '.app_released').first.css 'dd').last
14
+ reservation = (detail.css '.app_booking').first
15
+ current_reserved = (reservation.css 'li')[1]
16
+ max_reserved = (reservation.css 'li')[2]
17
+
18
+ video = (html.css '.app_detail_movie').first
19
+
20
+ unless video.nil?
21
+ video_frame = (video.css 'iframe').first
22
+ video_url = video_frame.get_attribute 'src'
23
+ end
24
+
25
+ screenshot_container = (html.css '.gallery_wrap').first
26
+ screenshots = screenshot_container.css '.item'
27
+ screenshot_urls = screenshots.map do |ss|
28
+ rel_url = (ss.css 'img').first.get_attribute 'src'
29
+ YoyakutoptenScraper.make_absolute_url rel_url
30
+ end
31
+
32
+ description = (html.css '.app_description').first
33
+
34
+ bonus_detail = (html.css '.bonus_detail').first
35
+ unless bonus_detail.nil?
36
+ bonus = ((bonus_detail.css '.btn_bounus').first.css 'a').first
37
+
38
+ bonus_rel_url = bonus.get_attribute 'href'
39
+ bonus_rel_url.match %r!/[a-zA-Z]+/[a-zA-Z]+/(\w+)!
40
+ bonus_url = YoyakutoptenScraper.make_absolute_url bonus_rel_url
41
+ bonus_id = $1
42
+ else
43
+ bonus_id = ''
44
+ bonus_url = ''
45
+ end
46
+
47
+ @title = title.text
48
+ @icon = (YoyakutoptenScraper.make_absolute_url (icon.get_attribute 'src'))
49
+ @publisher = publisher.text
50
+ @release = release.text
51
+ @current_reserved = current_reserved.text
52
+ @max_reserved = max_reserved.text
53
+ @screenshot_urls = screenshot_urls
54
+ @description = description.text
55
+ @video_url = video_url
56
+ @bonus_id = bonus_id
57
+ @bonus_url = bonus_url
58
+ @website_url = (YoyakutoptenScraper.make_absolute_url ("#{YoyakutoptenScraper::PC_PREFIX}/#{@app_id}"))
59
+ end
60
+
61
+ def update
62
+ query = "#{YoyakutoptenScraper::HOST}/#{YoyakutoptenScraper::PC_PREFIX}/#{@app_id}"
63
+ user_agents = YoyakutoptenScraper::USER_AGENTS[@os_type]
64
+ request = Typhoeus::Request.new query,
65
+ method: 'get',
66
+ headers: {:"User-Agent" => user_agents},
67
+ followlocation: true
68
+ response = request.run
69
+ self.parse (Nokogiri::HTML.parse response.body)
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,35 @@
1
+ module YoyakutoptenScraper
2
+ class Bonus
3
+ def initialize(bonus_id:, os_type:)
4
+ @bonus_id = bonus_id
5
+ @os_type = os_type
6
+ end
7
+
8
+ def parse(html)
9
+ img = ((html.css '.app_detail_bonus_imgArea').first.css 'img').first
10
+ description = (html.css '.app_description').first
11
+
12
+ detail = (html.css '.reserv_detail').first
13
+ reserved_num = (detail.css '.reserv_detail_num').first
14
+ current_reserved = (reserved_num.css 'li')[1]
15
+ max_reserved = (reserved_num.css 'li')[2]
16
+
17
+ @img_url = (img.get_attribute 'src')
18
+ @description = description.text
19
+ @current_reserved = current_reserved.text
20
+ @max_reserved = max_reserved.text
21
+ end
22
+
23
+ def update
24
+ query = "#{YoyakutoptenScraper::HOST}/#{YoyakutoptenScraper::MOBILE_PREFIX}/#{@bonus_id}/bonus"
25
+ user_agents = YoyakutoptenScraper::USER_AGENTS[@os_type]
26
+ request = Typhoeus::Request.new query,
27
+ method: 'get',
28
+ headers: {:"User-Agent" => user_agents},
29
+ followlocation: true
30
+
31
+ response = request.run
32
+ self.parse (Nokogiri::HTML.parse response.body)
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,8 @@
1
+ module YoyakutoptenScraper
2
+ HOST = 'https://yoyaku-top10.jp'.freeze
3
+ PC_PREFIX = 'u/a'
4
+ MOBILE_PREFIX = 'sp/r'
5
+ ANDROID_USER_AGENT = 'Mozilla/5.0 (Linux; U; Android 1.6; ja-jp; IS01 Build/S3082) AppleWebKit/528.5+ (KHTML, like Gecko) Version/3.1.2 Mobile Safari/525.20.1'
6
+ IOS_USER_AGENT = 'Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A403 Safari/8536.25'
7
+ USER_AGENTS = {ios: IOS_USER_AGENT, android: ANDROID_USER_AGENT}
8
+ end
@@ -0,0 +1,70 @@
1
+ module YoyakutoptenScraper
2
+ class Ranking
3
+ TYPE = [:daily, :total, :new]
4
+ attr_accessor :feed, :os_type, :results
5
+
6
+ def initialize(feed:, os_type:, options: {})
7
+ @feed = feed
8
+ @os_type = os_type
9
+ end
10
+
11
+ def parse(html)
12
+ apps = html.css '.rank_content'
13
+
14
+ @results = apps.map do |app|
15
+ title = (app.css '.rank_title').first
16
+ price = (app.css '.rank_price').first
17
+ banner = ((app.css '.rank_bnr').first.css 'a').first
18
+ banner_img = (banner.css 'img').first
19
+
20
+ info = (app.css '.bg_rank_summary').first
21
+ release = ((info.css '.rank_released').first.css 'li').last
22
+
23
+ detail_rel_url = banner.get_attribute 'href'
24
+ detail_rel_url.match %r!/[a-zA-Z]+/[a-zA-Z]+/(\w+)!
25
+ detail_url = YoyakutoptenScraper.make_absolute_url detail_rel_url
26
+ app_id = $1
27
+
28
+ special = (info.css '.btn_special').first
29
+
30
+ unless special.nil?
31
+ bonus = (special.css 'a').first
32
+ bonus_rel_url = bonus.get_attribute 'href'
33
+ bonus_rel_url.match %r!/[a-zA-Z]+/[a-zA-Z]+/(\w+)!
34
+ bonus_url = YoyakutoptenScraper.make_absolute_url bonus_rel_url
35
+ bonus_id = $1
36
+ else
37
+ bonus_id = ''
38
+ bonus_url = ''
39
+ end
40
+
41
+ banner_rel_url = (banner_img.get_attribute 'src')
42
+ banner_url = YoyakutoptenScraper.make_absolute_url banner_rel_url
43
+
44
+ {
45
+ title: title.text,
46
+ price: (price.text == 'FREE' ? 0 : price.text),
47
+ detail_url: detail_url,
48
+ banner_img_url: banner_url,
49
+ app_id: app_id,
50
+ release: release.text,
51
+ bonus_id: bonus_id,
52
+ bonus_url: bonus_url,
53
+ os_type: @os_type
54
+ }
55
+ end
56
+ end
57
+
58
+ def update
59
+ query = "#{YoyakutoptenScraper::HOST}/pc/r/#{@os_type}/#{@feed}"
60
+ user_agents = YoyakutoptenScraper::USER_AGENTS[@os_type]
61
+ request = Typhoeus::Request.new query,
62
+ method: 'get',
63
+ headers: {:"User-Agent" => user_agents},
64
+ followlocation: true
65
+
66
+ response = request.run
67
+ self.parse (Nokogiri::HTML.parse response.body)
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,5 @@
1
+ module YoyakutoptenScraper
2
+ def self.make_absolute_url(url)
3
+ "#{YoyakutoptenScraper::HOST}/#{url}"
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module YoyakutoptenScraper
2
+ VERSION = "0.0.2"
3
+ end
@@ -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 'yoyakutopten_scraper/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "yoyakutopten_scraper"
8
+ spec.version = YoyakutoptenScraper::VERSION
9
+ spec.authors = ["ryysd"]
10
+ spec.email = ["ry.ysd01@gmail.com"]
11
+ spec.summary = %q{scraper for https://yoyaku-top10.jp.}
12
+ spec.description = %q{scraper for https://yoyaku-top10.jp.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+
24
+ spec.add_dependency 'nokogiri'
25
+ spec.add_dependency 'typhoeus'
26
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yoyakutopten_scraper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - ryysd
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-03 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.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: nokogiri
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
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: typhoeus
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: scraper for https://yoyaku-top10.jp.
70
+ email:
71
+ - ry.ysd01@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - lib/test.rb
82
+ - lib/yoyakutopten_scraper.rb
83
+ - lib/yoyakutopten_scraper/app.rb
84
+ - lib/yoyakutopten_scraper/bonus.rb
85
+ - lib/yoyakutopten_scraper/constant.rb
86
+ - lib/yoyakutopten_scraper/ranking.rb
87
+ - lib/yoyakutopten_scraper/util.rb
88
+ - lib/yoyakutopten_scraper/version.rb
89
+ - yoyakutopten_scraper.gemspec
90
+ homepage: ''
91
+ licenses:
92
+ - MIT
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.2.0
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: scraper for https://yoyaku-top10.jp.
114
+ test_files: []
115
+ has_rdoc: