the_country_identity 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.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +51 -0
- data/Rakefile +2 -0
- data/lib/the_country_identity/version.rb +3 -0
- data/lib/the_country_identity.rb +141 -0
- data/the_country_identity.gemspec +21 -0
- metadata +69 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Raul Pino
|
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,51 @@
|
|
1
|
+
# TheCountryIdentity
|
2
|
+
|
3
|
+
Celebrating the premiere of "The Bourne Legacy" in Venezuela and honoring the first film "The Bourne Identity"...
|
4
|
+
|
5
|
+
I give you __the_country_identity__, a gem for get information from [CIA World Factbook](https://www.cia.gov/library/publications/the-world-factbook/). This is based on [semantic_crawler](https://github.com/obale/semantic_crawler) appproach.
|
6
|
+
|
7
|
+
* Important! Right now the [endpoint of University of Mannheim](http://www4.wiwiss.fu-berlin.de/factbook/data/) its down.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
gem 'the_country_identity'
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install the_country_identity
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
> country = TheCountryIdentity::Of.new("Venezuela")
|
26
|
+
=> #<TheCountryIdentity::Of:0x007f083417a4d8 @country_name="Venezuela", @url="http://www4.wiwiss.fu-berlin.de/factbook/data/venezuela">
|
27
|
+
|
28
|
+
> country.population_total
|
29
|
+
=> 28,047,938
|
30
|
+
|
31
|
+
> country.get_property("lifeexpectancyatbirth_totalpopulation")
|
32
|
+
=> 74.08
|
33
|
+
|
34
|
+
## Roadmap
|
35
|
+
|
36
|
+
* Search for more public RDF, sparql or even json endpoints for fetching data.
|
37
|
+
* Optimize data scrapping testing other gem like nokogiri.
|
38
|
+
|
39
|
+
## Contributing
|
40
|
+
|
41
|
+
1. Fork it
|
42
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
43
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
44
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
45
|
+
5. Create new Pull Request
|
46
|
+
|
47
|
+
## License
|
48
|
+
|
49
|
+
© 2012 by [Raul Pino](https://github.com/p1nox) for [Alphadeville](https://github.com/alphadeville), published under MIT license.
|
50
|
+
|
51
|
+
Some portions of this software corresponds to [© 2012 Alex Oberhauser MIT license](https://github.com/obale/semantic_crawler/blob/develop/MIT-LICENSE)
|
data/Rakefile
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
require "the_country_identity/version"
|
2
|
+
|
3
|
+
module TheCountryIdentity
|
4
|
+
|
5
|
+
class Of
|
6
|
+
|
7
|
+
# Endpoint of University of Mannheim
|
8
|
+
@@URI_PREFIX = "http://www4.wiwiss.fu-berlin.de/factbook/data/"
|
9
|
+
# TODO - find other endpoints
|
10
|
+
|
11
|
+
# Predefined RDFS/OWL namespaces used for RDF file parsing
|
12
|
+
@@NAMESPACES = {
|
13
|
+
"factbook" => "http://www4.wiwiss.fu-berlin.de/factbook/ns#",
|
14
|
+
"rdfs" => "http://www.w3.org/2000/01/rdf-schema#",
|
15
|
+
"rdf" => "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
16
|
+
}
|
17
|
+
|
18
|
+
# Country name given as input during the object creation.
|
19
|
+
attr_reader :country_name
|
20
|
+
|
21
|
+
# The complete URL of the country. Could be also wrong,
|
22
|
+
# if the country_name is not valid.
|
23
|
+
attr_reader :url
|
24
|
+
|
25
|
+
# Get Country Information from the CIA Factbook. see
|
26
|
+
# http://www4.wiwiss.fu-berlin.de/factbook/
|
27
|
+
#
|
28
|
+
# Example:
|
29
|
+
# >> austria = SemanticCrawler::Factbook::Country.new("austria")
|
30
|
+
# >> puts austria.background
|
31
|
+
#
|
32
|
+
# Arguments:
|
33
|
+
# new_country_name: (String)
|
34
|
+
def initialize(new_country_name)
|
35
|
+
if !new_country_name.nil?
|
36
|
+
@country_name = new_country_name
|
37
|
+
@url = @@URI_PREFIX + @country_name.downcase.gsub(" ", "_").gsub("usa", "united_states")
|
38
|
+
begin
|
39
|
+
fetch_rdf
|
40
|
+
rescue => e
|
41
|
+
$log.error("Not able to get country information, through exception: #{e}")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# Returns the country name (rdfs:label)
|
47
|
+
# XXX: If nothing was found this method returns
|
48
|
+
# <?xml version="1.0"?>
|
49
|
+
def name
|
50
|
+
get_rdfs_property("label", "/rdf:RDF/rdf:Description/factbook:landboundary/factbook:Country")
|
51
|
+
end
|
52
|
+
|
53
|
+
# Returns background information about the country
|
54
|
+
def background
|
55
|
+
get_property("background")
|
56
|
+
end
|
57
|
+
|
58
|
+
# Returns background information about the country
|
59
|
+
def population_total
|
60
|
+
get_property("population_total")
|
61
|
+
end
|
62
|
+
|
63
|
+
# Returns geographiccoordinates latitude
|
64
|
+
def latitude
|
65
|
+
get_property("geographiccoordinates_latitude")
|
66
|
+
end
|
67
|
+
|
68
|
+
# Returns geographiccoordinates longitude
|
69
|
+
def longitude
|
70
|
+
get_property("geographiccoordinates_longitude")
|
71
|
+
end
|
72
|
+
|
73
|
+
# Returns landboundary
|
74
|
+
def landboundary
|
75
|
+
if !@doc.nil?
|
76
|
+
@doc.xpath("//factbook:landboundary/rdf:Description/@rdf:about", @@NAMESPACES)
|
77
|
+
else
|
78
|
+
nil
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# Returns terrain description (human readable)
|
83
|
+
def terrain
|
84
|
+
get_property("terrain")
|
85
|
+
end
|
86
|
+
|
87
|
+
# Returns the total number of airports in the country
|
88
|
+
def airports_total
|
89
|
+
get_property("airports_total")
|
90
|
+
end
|
91
|
+
|
92
|
+
# Returns the number of helicopter airports
|
93
|
+
def heliports
|
94
|
+
get_property("heliports")
|
95
|
+
end
|
96
|
+
|
97
|
+
# Returns climate description (human readable)
|
98
|
+
def climate
|
99
|
+
get_property("climate")
|
100
|
+
end
|
101
|
+
|
102
|
+
# Returns location description (human readable)
|
103
|
+
def location
|
104
|
+
get_property("location")
|
105
|
+
end
|
106
|
+
|
107
|
+
|
108
|
+
# Abstract method that allows to fetch factbook properties via
|
109
|
+
# xpath
|
110
|
+
def get_property(property_name, prefix = "/" )
|
111
|
+
if !@doc.nil?
|
112
|
+
@doc.xpath(prefix + "/factbook:" + property_name + "/text()", @@NAMESPACES)
|
113
|
+
else
|
114
|
+
nil
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
# @return [String] The document serialized as XML
|
119
|
+
def xml_document
|
120
|
+
@doc.to_s
|
121
|
+
end
|
122
|
+
|
123
|
+
# Abstract method that allows to fetch rdfs properties via
|
124
|
+
# xpath
|
125
|
+
def get_rdfs_property(property_name, prefix = "/")
|
126
|
+
if !@doc.nil?
|
127
|
+
@doc.xpath(prefix + "/rdfs:" + property_name + "/text()", @@NAMESPACES)
|
128
|
+
else
|
129
|
+
nil
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
private
|
134
|
+
# Retrieves the RDF stream
|
135
|
+
def fetch_rdf
|
136
|
+
@doc = Nokogiri::XML(open(@url))
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/the_country_identity/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
|
6
|
+
gem.name = "the_country_identity"
|
7
|
+
gem.version = TheCountryIdentity::VERSION
|
8
|
+
gem.authors = ["Raul Pino"]
|
9
|
+
gem.email = ["ipinoraul@gmail.com"]
|
10
|
+
gem.description = %q{Fetch data from CIA World Factbook}
|
11
|
+
gem.summary = %q{CIA World Factbook Scrapper}
|
12
|
+
gem.homepage = "https://github.com/p1nox/the_country_identity"
|
13
|
+
|
14
|
+
gem.files = `git ls-files`.split($\)
|
15
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.require_paths = ["lib"]
|
18
|
+
|
19
|
+
gem.add_dependency "nokogiri" # XML Parsing
|
20
|
+
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: the_country_identity
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Raul Pino
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-23 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: nokogiri
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: Fetch data from CIA World Factbook
|
31
|
+
email:
|
32
|
+
- ipinoraul@gmail.com
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- Gemfile
|
39
|
+
- LICENSE
|
40
|
+
- README.md
|
41
|
+
- Rakefile
|
42
|
+
- lib/the_country_identity.rb
|
43
|
+
- lib/the_country_identity/version.rb
|
44
|
+
- the_country_identity.gemspec
|
45
|
+
homepage: https://github.com/p1nox/the_country_identity
|
46
|
+
licenses: []
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ! '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
requirements: []
|
64
|
+
rubyforge_project:
|
65
|
+
rubygems_version: 1.8.24
|
66
|
+
signing_key:
|
67
|
+
specification_version: 3
|
68
|
+
summary: CIA World Factbook Scrapper
|
69
|
+
test_files: []
|