GeoScraper 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/.gitignore +19 -0
- data/Gemfile +4 -0
- data/GeoScraper.gemspec +27 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +6 -0
- data/lib/GeoScraper.rb +8 -0
- data/lib/GeoScraper/core.rb +44 -0
- data/lib/GeoScraper/foursquare.rb +18 -0
- data/lib/GeoScraper/gnavi.rb +24 -0
- data/lib/GeoScraper/sanzeromin.rb +25 -0
- data/lib/GeoScraper/tabelog.rb +27 -0
- data/lib/GeoScraper/version.rb +3 -0
- data/lib/GeoScraper/yelp.rb +19 -0
- data/spec/GeoScraper_spec.rb +52 -0
- data/spec/spec_helper.rb +8 -0
- metadata +118 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5caa254cac2c48a1048d3c0d9432603fa24ce81d
|
4
|
+
data.tar.gz: f9df9458ad9c2eba5a2d800ce7f2e5869508862c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b3f469bfe1a36ba5c6c92beb8eabf1a2d2fd6f1ea69442bcb52cbbc3266c1ae2e471774f62ae7a838894aba6f890bcec899edac67897e1a7c848c48fbc256f03
|
7
|
+
data.tar.gz: f6e4fe8fb6cd71eaffe37e31d967fdd81a3a0fc4b4a8a4f11a44e308e3478b9126480e5d87bc284746753840062b50a6bf89d4f0cd6463ada3f36ed116804bb6
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/GeoScraper.gemspec
ADDED
@@ -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 'GeoScraper/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "GeoScraper"
|
8
|
+
spec.version = GeoScraper::VERSION
|
9
|
+
spec.authors = ["isamu arimoto"]
|
10
|
+
spec.email = ["isamu@to-kyo.to"]
|
11
|
+
spec.description = %q{GeoScraper is location data (latitude/longitude) scraper.}
|
12
|
+
spec.summary = %q{GeoScraper is location data (latitude/longitude) scraper.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
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.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
|
25
|
+
spec.add_dependency "nokogiri"
|
26
|
+
|
27
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 isamu arimoto
|
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,31 @@
|
|
1
|
+
# GeoScraper
|
2
|
+
|
3
|
+
GeoScraper is location data (latitude/longitude) scraper.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'GeoScraper'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install GeoScraper
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
gs = GeoScraper.new(uri)
|
22
|
+
gs.lon # get longitude
|
23
|
+
gs.lat # get latitude
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/GeoScraper.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require "open-uri"
|
2
|
+
require "nokogiri"
|
3
|
+
|
4
|
+
class GeoScraper
|
5
|
+
@@pattern = []
|
6
|
+
|
7
|
+
@url = ""
|
8
|
+
@matches = nil
|
9
|
+
@result = nil
|
10
|
+
|
11
|
+
def initialize url
|
12
|
+
@url = url
|
13
|
+
@@pattern.each do |pattern|
|
14
|
+
if @matches = pattern[0].match(@url)
|
15
|
+
extend Object.const_get("GeoScraper::" + pattern[1])
|
16
|
+
@matches = Regexp.last_match
|
17
|
+
@result = scrape
|
18
|
+
break
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def get_doc uri
|
24
|
+
Nokogiri::HTML.parse(open(uri, "User-Agent" => "Mozilla/5.0 Geo Scraper").read)
|
25
|
+
end
|
26
|
+
|
27
|
+
def has_data?
|
28
|
+
!@result.nil?
|
29
|
+
end
|
30
|
+
|
31
|
+
def lon
|
32
|
+
if has_data?
|
33
|
+
@result["longitude"].to_f
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def lat
|
38
|
+
if has_data?
|
39
|
+
@result["latitude"].to_f
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class GeoScraper
|
2
|
+
@@pattern << [/https?:\/\/(\w+\.)?foursquare.com\//, "FourSquare"]
|
3
|
+
|
4
|
+
module FourSquare
|
5
|
+
def scrape
|
6
|
+
doc = get_doc @url
|
7
|
+
meta = doc.css('meta').inject({}) {|s, v|
|
8
|
+
s[v.attr('property')] ||= v.attr('content')
|
9
|
+
s[v.attr('name')] ||= v.attr('content')
|
10
|
+
s
|
11
|
+
}
|
12
|
+
{
|
13
|
+
"longitude" => meta["playfoursquare:location:longitude"],
|
14
|
+
"latitude" => meta["playfoursquare:location:latitude"]
|
15
|
+
}
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class GeoScraper
|
2
|
+
@@pattern << [/http:\/\/r\.gnavi\.co\.jp\/(\w+)\//, "Gnavi"]
|
3
|
+
|
4
|
+
module Gnavi
|
5
|
+
def scrape
|
6
|
+
uri = "http://r.gnavi.co.jp/#{@matches[1]}/map/"
|
7
|
+
|
8
|
+
doc = get_doc(uri)
|
9
|
+
if figureCanvas = doc.xpath("//div[@id='figureCanvas']")
|
10
|
+
value = figureCanvas[0].attributes["class"].value
|
11
|
+
geo = value.split(" ").inject({}){|s, v|
|
12
|
+
values = v.split(":")
|
13
|
+
s[values[0]] = values[1]
|
14
|
+
s
|
15
|
+
}
|
16
|
+
end
|
17
|
+
{
|
18
|
+
"longitude" => geo["lng"],
|
19
|
+
"latitude" => geo["lat"]
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class GeoScraper
|
2
|
+
@@pattern << [/^http:\/\/30min.jp\/place/, "SanzeroMin"]
|
3
|
+
|
4
|
+
module SanzeroMin
|
5
|
+
def scrape
|
6
|
+
doc = get_doc @url
|
7
|
+
|
8
|
+
lon = nil
|
9
|
+
lat = nil
|
10
|
+
doc.css("script").select{|script|
|
11
|
+
script.inner_text.match(/SZAreaMatch/)
|
12
|
+
}[0].inner_text.split("\n").each {|line|
|
13
|
+
if line =~ /SZAreaMatch\.longitude/
|
14
|
+
lon = line.scan(/^\-|\d[\d\-\.]+/)[0]
|
15
|
+
elsif line =~ /SZAreaMatch\.latitude/
|
16
|
+
lat = line.scan(/^\-|\d[\d\-\.]+/)[0]
|
17
|
+
end
|
18
|
+
}
|
19
|
+
{
|
20
|
+
"longitude" => lon,
|
21
|
+
"latitude" => lat
|
22
|
+
}
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class GeoScraper
|
2
|
+
@@pattern << [/http:\/\/tabelog\.com(\/[A-Za-z\d]+){4}/, "Tabelog"]
|
3
|
+
|
4
|
+
module Tabelog
|
5
|
+
def scrape
|
6
|
+
url = @matches[0] + "/dtlmap/"
|
7
|
+
doc = get_doc url
|
8
|
+
|
9
|
+
lon = nil
|
10
|
+
lat = nil
|
11
|
+
doc.css("script").select{|script|
|
12
|
+
script.inner_text.match(/LatLng/)
|
13
|
+
}[0].inner_text.split("\n").each {|line|
|
14
|
+
if line =~ /var\ lng/
|
15
|
+
lon = line.scan(/^\-|\d[\d\-\.]+/)[0]
|
16
|
+
elsif line =~ /var\ lat/
|
17
|
+
lat = line.scan(/^\-|\d[\d\-\.]+/)[0]
|
18
|
+
end
|
19
|
+
}
|
20
|
+
{
|
21
|
+
"longitude" => lon,
|
22
|
+
"latitude" => lat
|
23
|
+
}
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class GeoScraper
|
2
|
+
@@pattern << [/http:\/\/www\.yelp\.com\//, "Yelp"]
|
3
|
+
|
4
|
+
module Yelp
|
5
|
+
def scrape
|
6
|
+
doc = get_doc @url
|
7
|
+
|
8
|
+
meta = doc.css('meta').inject({}) {|s, v|
|
9
|
+
s[v.attr('property')] ||= v.attr('content')
|
10
|
+
s[v.attr('name')] ||= v.attr('content')
|
11
|
+
s
|
12
|
+
}
|
13
|
+
{
|
14
|
+
"longitude" => meta['place:location:longitude'],
|
15
|
+
"latitude" => meta['place:location:latitude']
|
16
|
+
}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe GeoScraper do
|
4
|
+
before do
|
5
|
+
end
|
6
|
+
|
7
|
+
it 'should get geo data from foursquare' do
|
8
|
+
uri = "https://ja.foursquare.com/v/%E6%9D%B1%E4%BA%AC%E3%83%89%E3%83%BC%E3%83%A0-tokyo-dome/4b7544c3f964a520a8032ee3"
|
9
|
+
gs = GeoScraper.new(uri)
|
10
|
+
|
11
|
+
gs.lon.should == 139.7519087791443
|
12
|
+
gs.lat.should == 35.705584611645335
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should get geo data from yelp' do
|
16
|
+
uri = "http://www.yelp.com/biz/greenhearts-family-farm-csa-san-francisco"
|
17
|
+
gs = GeoScraper.new(uri)
|
18
|
+
|
19
|
+
gs.lon.should == -122.4355626
|
20
|
+
gs.lat.should == 37.7733623
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should get geo data from 30min' do
|
24
|
+
gs = GeoScraper.new "http://30min.jp/place/5561"
|
25
|
+
|
26
|
+
gs.lon.should == 139.78297
|
27
|
+
gs.lat.should == 35.684971
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should get geo data from gnavi' do
|
31
|
+
gs = GeoScraper.new "http://r.gnavi.co.jp/g398542/map/"
|
32
|
+
|
33
|
+
gs.lon.should == 139.77357
|
34
|
+
gs.lat.should == 35.627817
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should get geo data from tabelog' do
|
38
|
+
uri = "http://tabelog.com/tokyo/A1311/A131102/13003661/dtlmap/"
|
39
|
+
gs = GeoScraper.new(uri)
|
40
|
+
|
41
|
+
gs.lon.should == 139.795076693823
|
42
|
+
gs.lat.should == 35.7104300850057
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should get geo data from tabelog no map url' do
|
46
|
+
uri = "http://tabelog.com/tokyo/A1311/A131102/13003661/"
|
47
|
+
gs = GeoScraper.new(uri)
|
48
|
+
|
49
|
+
gs.lon.should == 139.795076693823
|
50
|
+
gs.lat.should == 35.7104300850057
|
51
|
+
end
|
52
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: GeoScraper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- isamu arimoto
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-06-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.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
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: 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: nokogiri
|
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: GeoScraper is location data (latitude/longitude) scraper.
|
70
|
+
email:
|
71
|
+
- isamu@to-kyo.to
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- Gemfile
|
78
|
+
- GeoScraper.gemspec
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- lib/GeoScraper.rb
|
83
|
+
- lib/GeoScraper/core.rb
|
84
|
+
- lib/GeoScraper/foursquare.rb
|
85
|
+
- lib/GeoScraper/gnavi.rb
|
86
|
+
- lib/GeoScraper/sanzeromin.rb
|
87
|
+
- lib/GeoScraper/tabelog.rb
|
88
|
+
- lib/GeoScraper/version.rb
|
89
|
+
- lib/GeoScraper/yelp.rb
|
90
|
+
- spec/GeoScraper_spec.rb
|
91
|
+
- spec/spec_helper.rb
|
92
|
+
homepage: ''
|
93
|
+
licenses:
|
94
|
+
- MIT
|
95
|
+
metadata: {}
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 2.0.2
|
113
|
+
signing_key:
|
114
|
+
specification_version: 4
|
115
|
+
summary: GeoScraper is location data (latitude/longitude) scraper.
|
116
|
+
test_files:
|
117
|
+
- spec/GeoScraper_spec.rb
|
118
|
+
- spec/spec_helper.rb
|