cowa 0.1.0
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 +9 -0
- data/.project +17 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/README.md +53 -0
- data/Rakefile +1 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/cowa.gemspec +27 -0
- data/example/cowa.rb +13 -0
- data/lib/cowa.rb +3 -0
- data/lib/cowa/open_weatherMap.rb +48 -0
- data/lib/cowa/version.rb +3 -0
- data/lib/cowa/weather_hacks.rb +81 -0
- metadata +127 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7221473f7e42737b6fa859fd5166b264ae1a8433
|
4
|
+
data.tar.gz: 69376f4ec6eb2aab52ffce0c38e49428a70c35c6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c9dfdd96de9352959d9e4a775e371cfaa1c9227d33edb8a18da59b9e3f6f6529cf20fa2b52524ee07c98077b289dd4f5a79b511c002eebd6b72c890151265f03
|
7
|
+
data.tar.gz: 21ab63906fb61de7bc5a49cd4aa8948fd4061caa2e37670ca9e600a6d2dcc84c4fa45dd34970b2d684cf4936a5e3ba26297d9329f8117d3429120c1e885643e6
|
data/.gitignore
ADDED
data/.project
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<projectDescription>
|
3
|
+
<name>cowa</name>
|
4
|
+
<comment></comment>
|
5
|
+
<projects>
|
6
|
+
</projects>
|
7
|
+
<buildSpec>
|
8
|
+
<buildCommand>
|
9
|
+
<name>org.eclipse.dltk.core.scriptbuilder</name>
|
10
|
+
<arguments>
|
11
|
+
</arguments>
|
12
|
+
</buildCommand>
|
13
|
+
</buildSpec>
|
14
|
+
<natures>
|
15
|
+
<nature>org.eclipse.dltk.ruby.core.nature</nature>
|
16
|
+
</natures>
|
17
|
+
</projectDescription>
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# Cowa
|
2
|
+
|
3
|
+
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/cowa`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
rubyで書かれた天気APIの複合ライブラリです。
|
6
|
+
このライブラリはOpenWeatherMapAPIとWeather HacksAPIに対応しています。
|
7
|
+
詳しくは
|
8
|
+
[OpenWeatherMap](http://openweathermap.org/)
|
9
|
+
[Weather Hacks](http://weather.livedoor.com/weather_hacks/)
|
10
|
+
|
11
|
+
質問等ありましたらTwitter:[@flum_](https://twitter.com/flum_)までお願いします。
|
12
|
+
|
13
|
+
|
14
|
+
## Installation
|
15
|
+
|
16
|
+
Add this line to your application's Gemfile:
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
gem 'cowa'
|
20
|
+
```
|
21
|
+
|
22
|
+
And then execute:
|
23
|
+
|
24
|
+
$ bundle
|
25
|
+
|
26
|
+
Or install it yourself as:
|
27
|
+
|
28
|
+
$ gem install cowa
|
29
|
+
|
30
|
+
## Usage
|
31
|
+
|
32
|
+
requireしてから
|
33
|
+
|
34
|
+
```
|
35
|
+
info = Cowa::OpenWeatherMap.new
|
36
|
+
puts info.get_information_place("東京")
|
37
|
+
```
|
38
|
+
の様な感じで使用してください。
|
39
|
+
Weather Hacksを使用する場合は内部でYapiライブラリの一部を参照しているためnewするときに引数としてyahooのapi_keyを投げてください。
|
40
|
+
|
41
|
+
## Development
|
42
|
+
|
43
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, 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` to 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
|
+
1. Fork it ( https://github.com/[my-github-username]/cowa/fork )
|
50
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
51
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
52
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
53
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "cowa"
|
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
|
data/bin/setup
ADDED
data/cowa.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 'cowa/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "cowa"
|
8
|
+
spec.version = Cowa::VERSION
|
9
|
+
spec.authors = ["flum1025"]
|
10
|
+
spec.email = ["flum.1025@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{composite library for weather api}
|
13
|
+
spec.description = spec.summary
|
14
|
+
spec.homepage = "https://github.com/flum1025/cowa"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.9"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
|
24
|
+
spec.add_dependency 'json'
|
25
|
+
spec.add_dependency 'yapi'
|
26
|
+
spec.add_dependency 'activesupport'
|
27
|
+
end
|
data/example/cowa.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Coding: UTF-8
|
2
|
+
lib = File.expand_path('../../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'cowa'
|
5
|
+
|
6
|
+
open_weathermap_api_key = ""
|
7
|
+
info = Cowa::OpenWeatherMap.new(open_weathermap_api_key)
|
8
|
+
puts info.get_information_place("千葉")
|
9
|
+
puts info.get_information_latlon(35,140)
|
10
|
+
|
11
|
+
yahoo_api_key = ""
|
12
|
+
fore = Cowa::WeatherHacks.new(yahoo_api_key)
|
13
|
+
puts fore.forecast("千代田区")
|
data/lib/cowa.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Cowa
|
5
|
+
class OpenWeatherMap
|
6
|
+
attr_accessor :api_key
|
7
|
+
|
8
|
+
def initialize(api_key)
|
9
|
+
@api_key = api_key
|
10
|
+
end
|
11
|
+
|
12
|
+
def client url
|
13
|
+
return open(URI.encode(url)).read
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_icon icon
|
17
|
+
return open("http://openweathermap.org/img/w/#{icon}.png")
|
18
|
+
end
|
19
|
+
|
20
|
+
def get_information_place location
|
21
|
+
req_url = "http://api.openweathermap.org/data/2.5/weather?q=#{location}&APPID=#{@api_key}"
|
22
|
+
return JSON.parse(client(req_url), symbolize_names: true)
|
23
|
+
end
|
24
|
+
|
25
|
+
def get_information_latlon lat, lon
|
26
|
+
req_url = "http://api.openweathermap.org/data/2.5/weather?lat=#{lat}&lon=#{lon}&APPID=#{@api_key}"
|
27
|
+
return JSON.parse(client(req_url), symbolize_names: true)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
=begin
|
33
|
+
temp 気温
|
34
|
+
temp_min 最低気温
|
35
|
+
temp_max 最高気温
|
36
|
+
icon 天気アイコン
|
37
|
+
main 天気
|
38
|
+
lat 緯度
|
39
|
+
lon 経度
|
40
|
+
pressure 気圧
|
41
|
+
sea_level 海面
|
42
|
+
humidity 湿度
|
43
|
+
speed 風速
|
44
|
+
name 都市名
|
45
|
+
country 国名
|
46
|
+
sunrise 日の出時間
|
47
|
+
sunset 日没時間
|
48
|
+
=end
|
data/lib/cowa/version.rb
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'json'
|
3
|
+
require 'active_support'
|
4
|
+
require 'active_support/core_ext'
|
5
|
+
require 'yapi'
|
6
|
+
|
7
|
+
module Cowa
|
8
|
+
class WeatherHacks
|
9
|
+
attr_accessor :rss
|
10
|
+
|
11
|
+
def initialize(api_key)
|
12
|
+
@contentsgeocoder = Yapi::OpenLocalPlatform::ContentsGeoCoder.new(api_key)
|
13
|
+
self.rss = xml_to_json(open(URI.encode("http://weather.livedoor.com/forecast/rss/primary_area.xml")).read)[:rss][:channel][:source][:pref]
|
14
|
+
end
|
15
|
+
|
16
|
+
def xml_to_json xml
|
17
|
+
doc = Hash.from_xml xml
|
18
|
+
return JSON.parse(doc.to_json, symbolize_names: true)
|
19
|
+
end
|
20
|
+
|
21
|
+
def locationToRss location
|
22
|
+
pref = get_pref location
|
23
|
+
return nil if pref.nil?
|
24
|
+
if pref[0][:Name] == "北海道"
|
25
|
+
if location == "北海道"
|
26
|
+
return self.rss[3][:city][0][:id]
|
27
|
+
end
|
28
|
+
for i in 0..4
|
29
|
+
self.rss[i][:city].each do |c|
|
30
|
+
return c[:id] if pref[1][:Name].include?(c[:title])
|
31
|
+
end
|
32
|
+
end
|
33
|
+
return nil
|
34
|
+
end
|
35
|
+
unless pref.nil?
|
36
|
+
city = get_city pref[0][:Name]
|
37
|
+
else
|
38
|
+
city = get_city location
|
39
|
+
end
|
40
|
+
id = get_id(city, location)
|
41
|
+
return id
|
42
|
+
end
|
43
|
+
|
44
|
+
def get_pref location
|
45
|
+
json = @contentsgeocoder.contentsGeoCoder(location)
|
46
|
+
return nil if json[:YDF][:ResultInfo][:Count] == "0"
|
47
|
+
return json[:YDF][:Feature][:Property][:AddressElement]
|
48
|
+
end
|
49
|
+
|
50
|
+
def get_city pref
|
51
|
+
self.rss().each do |t|
|
52
|
+
if t[:title] == pref
|
53
|
+
return t[:city]
|
54
|
+
end
|
55
|
+
end
|
56
|
+
return nil
|
57
|
+
end
|
58
|
+
|
59
|
+
def get_id(city, location)
|
60
|
+
unless city.nil?
|
61
|
+
city.each do |c|
|
62
|
+
return c[:id] if c[:title] == location
|
63
|
+
end
|
64
|
+
return city[0][:id]
|
65
|
+
else
|
66
|
+
return nil
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def client url
|
71
|
+
return open(URI.encode(url)).read
|
72
|
+
end
|
73
|
+
|
74
|
+
def forecast location
|
75
|
+
rss = locationToRss(location)
|
76
|
+
return nil if rss.nil?
|
77
|
+
req_url = "http://weather.livedoor.com/forecast/webservice/json/v1?city=#{rss}"
|
78
|
+
return JSON.parse(client(req_url), symbolize_names: true)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cowa
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- flum1025
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-03-17 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: json
|
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: yapi
|
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
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: activesupport
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: composite library for weather api
|
84
|
+
email:
|
85
|
+
- flum.1025@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- .gitignore
|
91
|
+
- .project
|
92
|
+
- .travis.yml
|
93
|
+
- Gemfile
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- bin/console
|
97
|
+
- bin/setup
|
98
|
+
- cowa.gemspec
|
99
|
+
- example/cowa.rb
|
100
|
+
- lib/cowa.rb
|
101
|
+
- lib/cowa/open_weatherMap.rb
|
102
|
+
- lib/cowa/version.rb
|
103
|
+
- lib/cowa/weather_hacks.rb
|
104
|
+
homepage: https://github.com/flum1025/cowa
|
105
|
+
licenses: []
|
106
|
+
metadata: {}
|
107
|
+
post_install_message:
|
108
|
+
rdoc_options: []
|
109
|
+
require_paths:
|
110
|
+
- lib
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - '>='
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - '>='
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
requirements: []
|
122
|
+
rubyforge_project:
|
123
|
+
rubygems_version: 2.5.2
|
124
|
+
signing_key:
|
125
|
+
specification_version: 4
|
126
|
+
summary: composite library for weather api
|
127
|
+
test_files: []
|