weather-random 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 +7 -0
- data/.gitignore +17 -0
- data/.travis.yml +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +40 -0
- data/Rakefile +9 -0
- data/lib/version.rb +3 -0
- data/lib/weather_random.rb +50 -0
- data/test/data_sf.json +93 -0
- data/test/tc_weather_random.rb +53 -0
- data/weather-random.gemspec +25 -0
- metadata +115 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9f0e11cdb410038da84d90e66754853b6e4ed908
|
4
|
+
data.tar.gz: 89b2ab37a5ecfbab4e78242e82b167a6689b158f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f72e689a3a147f0d240832b0c44cf5aab9c051220721a62830f806ed40ee45f67eef4784e3531662588f07fc1b143bffde57d8a55a53fb7f7b517bd3aa65d2ca
|
7
|
+
data.tar.gz: 2f8aaddf139bfc0d5803ff96532ba4f0d50f598812bc2afe0324fbf32689ae4efc63579afa1cf4253a4ea54e3eff6a0d789adb8d1a37864a175956dc3d24edda
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Sameer Siruguri
|
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,40 @@
|
|
1
|
+
# Weather::Random
|
2
|
+
|
3
|
+
This gem provides a class WeatherRandom that uses the WeatherUnderground API to generate a seed for a "T"RNG.
|
4
|
+
|
5
|
+
## Installation/Use
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'weather_random'
|
10
|
+
|
11
|
+
Or add this to your `.rb` file:
|
12
|
+
|
13
|
+
require 'weather_random'
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install weather-random
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
Create an object instance of `WeatherRandom::WeatherApi`, and initalize it with a Wunderground URL for now - future versions will let you set up your own entropy generator. Note that the URL has to have the string `#key` where your key will go, else you'll get the `WeatherRandom::ImproperApiURL` exception.
|
26
|
+
|
27
|
+
# You can pick any city you like.
|
28
|
+
entropy_object = WeatherRandom::WeatherApi.new('http://api.wunderground.com/api/#key/conditions/q/CA/San_Francisco.json', <key_value>)
|
29
|
+
entropy_object.fetch_uri
|
30
|
+
|
31
|
+
r=Random.new(entropy_object.make_seed)
|
32
|
+
r.rand
|
33
|
+
|
34
|
+
## Contributing
|
35
|
+
|
36
|
+
1. Fork it
|
37
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
38
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
39
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
40
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/version.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module WeatherRandom
|
5
|
+
class ImproperApiURL < Exception
|
6
|
+
end
|
7
|
+
|
8
|
+
class WeatherApi
|
9
|
+
def initialize(url, key)
|
10
|
+
raise(ImproperApiURL) if !(/\#key/.match url)
|
11
|
+
|
12
|
+
@uri=url
|
13
|
+
@key=key
|
14
|
+
|
15
|
+
|
16
|
+
@uri = @uri.gsub(/\#key/, @key)
|
17
|
+
end
|
18
|
+
|
19
|
+
attr_accessor :uri, :key
|
20
|
+
|
21
|
+
def fetch_uri
|
22
|
+
data = open @uri
|
23
|
+
@json_data = JSON.parse (data.readlines.join "")
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
def set_data inp_str
|
28
|
+
# Parse a JSON string
|
29
|
+
@json_data = JSON.parse inp_str
|
30
|
+
end
|
31
|
+
|
32
|
+
def make_seed
|
33
|
+
# Returns a string that can be used as the seed for Rand
|
34
|
+
|
35
|
+
# Concatenate a pre-selected list of keys from the feed. This is specific to Wunderground - it needs to be configurable
|
36
|
+
string = (['temp_f', 'pressure_mb', 'pressure_in', 'wind_degrees', 'wind_mph', 'wind_gust_mph'].map do |key|
|
37
|
+
@json_data['current_observation'][key]
|
38
|
+
end).join("")
|
39
|
+
|
40
|
+
seed = (string.split("").map do |char|
|
41
|
+
char.unpack('C')[0].to_s
|
42
|
+
end).join ""
|
43
|
+
|
44
|
+
seed.to_i
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
end
|
50
|
+
|
data/test/data_sf.json
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
|
2
|
+
{
|
3
|
+
"response": {
|
4
|
+
"version":"0.1",
|
5
|
+
"termsofService":"http://www.wunderground.com/weather/api/d/terms.html",
|
6
|
+
"features": {
|
7
|
+
"conditions": 1
|
8
|
+
}
|
9
|
+
}
|
10
|
+
, "current_observation": {
|
11
|
+
"image": {
|
12
|
+
"url":"http://icons-ak.wxug.com/graphics/wu2/logo_130x80.png",
|
13
|
+
"title":"Weather Underground",
|
14
|
+
"link":"http://www.wunderground.com"
|
15
|
+
},
|
16
|
+
"display_location": {
|
17
|
+
"full":"San Francisco, CA",
|
18
|
+
"city":"San Francisco",
|
19
|
+
"state":"CA",
|
20
|
+
"state_name":"California",
|
21
|
+
"country":"US",
|
22
|
+
"country_iso3166":"US",
|
23
|
+
"zip":"94101",
|
24
|
+
"magic":"1",
|
25
|
+
"wmo":"99999",
|
26
|
+
"latitude":"37.77500916",
|
27
|
+
"longitude":"-122.41825867",
|
28
|
+
"elevation":"47.00000000"
|
29
|
+
},
|
30
|
+
"observation_location": {
|
31
|
+
"full":"SOMA - Near Van Ness, San Francisco, California",
|
32
|
+
"city":"SOMA - Near Van Ness, San Francisco",
|
33
|
+
"state":"California",
|
34
|
+
"country":"US",
|
35
|
+
"country_iso3166":"US",
|
36
|
+
"latitude":"37.773285",
|
37
|
+
"longitude":"-122.417725",
|
38
|
+
"elevation":"49 ft"
|
39
|
+
},
|
40
|
+
"estimated": {
|
41
|
+
},
|
42
|
+
"station_id":"KCASANFR58",
|
43
|
+
"observation_time":"Last Updated on November 25, 11:07 PM PST",
|
44
|
+
"observation_time_rfc822":"Mon, 25 Nov 2013 23:07:54 -0800",
|
45
|
+
"observation_epoch":"1385449674",
|
46
|
+
"local_time_rfc822":"Mon, 25 Nov 2013 23:07:59 -0800",
|
47
|
+
"local_epoch":"1385449679",
|
48
|
+
"local_tz_short":"PST",
|
49
|
+
"local_tz_long":"America/Los_Angeles",
|
50
|
+
"local_tz_offset":"-0800",
|
51
|
+
"weather":"Partly Cloudy",
|
52
|
+
"temperature_string":"54.7 F (12.6 C)",
|
53
|
+
"temp_f":54.7,
|
54
|
+
"temp_c":12.6,
|
55
|
+
"relative_humidity":"74%",
|
56
|
+
"wind_string":"Calm",
|
57
|
+
"wind_dir":"NNE",
|
58
|
+
"wind_degrees":23,
|
59
|
+
"wind_mph":0.0,
|
60
|
+
"wind_gust_mph":0,
|
61
|
+
"wind_kph":0,
|
62
|
+
"wind_gust_kph":0,
|
63
|
+
"pressure_mb":"1025",
|
64
|
+
"pressure_in":"30.27",
|
65
|
+
"pressure_trend":"-",
|
66
|
+
"dewpoint_string":"47 F (8 C)",
|
67
|
+
"dewpoint_f":47,
|
68
|
+
"dewpoint_c":8,
|
69
|
+
"heat_index_string":"NA",
|
70
|
+
"heat_index_f":"NA",
|
71
|
+
"heat_index_c":"NA",
|
72
|
+
"windchill_string":"NA",
|
73
|
+
"windchill_f":"NA",
|
74
|
+
"windchill_c":"NA",
|
75
|
+
"feelslike_string":"54.7 F (12.6 C)",
|
76
|
+
"feelslike_f":"54.7",
|
77
|
+
"feelslike_c":"12.6",
|
78
|
+
"visibility_mi":"10.0",
|
79
|
+
"visibility_km":"16.1",
|
80
|
+
"solarradiation":"0",
|
81
|
+
"UV":"0","precip_1hr_string":"0.00 in ( 0 mm)",
|
82
|
+
"precip_1hr_in":"0.00",
|
83
|
+
"precip_1hr_metric":" 0",
|
84
|
+
"precip_today_string":"0.00 in (0 mm)",
|
85
|
+
"precip_today_in":"0.00",
|
86
|
+
"precip_today_metric":"0",
|
87
|
+
"icon":"partlycloudy",
|
88
|
+
"icon_url":"http://icons-ak.wxug.com/i/c/k/nt_partlycloudy.gif",
|
89
|
+
"forecast_url":"http://www.wunderground.com/US/CA/San_Francisco.html",
|
90
|
+
"history_url":"http://www.wunderground.com/weatherstation/WXDailyHistory.asp?ID=KCASANFR58",
|
91
|
+
"ob_url":"http://www.wunderground.com/cgi-bin/findweather/getForecast?query=37.773285,-122.417725"
|
92
|
+
}
|
93
|
+
}
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
gem 'minitest'
|
3
|
+
|
4
|
+
require_relative "../lib/weather_random"
|
5
|
+
require "minitest/autorun"
|
6
|
+
|
7
|
+
describe WeatherRandom do
|
8
|
+
|
9
|
+
before do
|
10
|
+
@key='mykeyvalue'
|
11
|
+
@url='http://api.wunderground.com/api/#key/conditions/q/CA/San_Francisco.json'
|
12
|
+
@api=WeatherRandom::WeatherApi.new(@url, @key)
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "when an object is created" do
|
16
|
+
it "must have a URL" do
|
17
|
+
@api.uri.must_equal "http://api.wunderground.com/api/#{@key}/conditions/q/CA/San_Francisco.json"
|
18
|
+
end
|
19
|
+
|
20
|
+
it "must have a key" do
|
21
|
+
@api.key.must_equal @key
|
22
|
+
end
|
23
|
+
|
24
|
+
it "wont let the URL not have a key placeholder" do
|
25
|
+
proc { WeatherRandom::WeatherApi.new('http://api.wunderground.com/api/#/key/conditions/q/CA/San_Francisco.json', @key) }.must_raise WeatherRandom::ImproperApiURL
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "for a valid object" do
|
31
|
+
before do
|
32
|
+
@json_resp = @api.set_data((File.open 'test/data_sf.json').readlines.join "")
|
33
|
+
end
|
34
|
+
|
35
|
+
it "can retrieve data" do
|
36
|
+
@json_resp.wont_equal nil
|
37
|
+
@json_resp['response'].wont_equal nil
|
38
|
+
@json_resp['response']['version'].must_equal '0.1'
|
39
|
+
|
40
|
+
|
41
|
+
['temp_f', 'pressure_mb', 'pressure_in', 'wind_degrees', 'wind_mph', 'wind_gust_mph'].each do |key|
|
42
|
+
@json_resp['current_observation'][key].wont_equal nil
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
it "returns a seed" do
|
47
|
+
expected_seed = ('54.7102530.27230.00'.split("").map do |char|
|
48
|
+
char.unpack('C')[0].to_s
|
49
|
+
end).join ""
|
50
|
+
@api.make_seed.must_equal expected_seed.to_i
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'version.rb'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "weather-random"
|
8
|
+
spec.version = WeatherRandom::VERSION
|
9
|
+
spec.authors = ["Sameer Siruguri"]
|
10
|
+
spec.email = ["siruguri@gmail.com"]
|
11
|
+
spec.description = %q{This gem provides a class WeatherRandom that uses the WeatherUnderground API to generate a seed for a "T"RNG.}
|
12
|
+
spec.summary = %q{The gem requires you to have a Wunderground API key, which you have to supply to it in the initializations}
|
13
|
+
spec.homepage = "https://github.com/siruguri/weather-random"
|
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_runtime_dependency 'json'
|
24
|
+
spec.add_development_dependency 'minitest'
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: weather-random
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sameer Siruguri
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-11-27 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: 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: minitest
|
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: This gem provides a class WeatherRandom that uses the WeatherUnderground
|
70
|
+
API to generate a seed for a "T"RNG.
|
71
|
+
email:
|
72
|
+
- siruguri@gmail.com
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- .gitignore
|
78
|
+
- .travis.yml
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- lib/version.rb
|
84
|
+
- lib/weather_random.rb
|
85
|
+
- test/data_sf.json
|
86
|
+
- test/tc_weather_random.rb
|
87
|
+
- weather-random.gemspec
|
88
|
+
homepage: https://github.com/siruguri/weather-random
|
89
|
+
licenses:
|
90
|
+
- MIT
|
91
|
+
metadata: {}
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - '>='
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - '>='
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
requirements: []
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 2.1.11
|
109
|
+
signing_key:
|
110
|
+
specification_version: 4
|
111
|
+
summary: The gem requires you to have a Wunderground API key, which you have to supply
|
112
|
+
to it in the initializations
|
113
|
+
test_files:
|
114
|
+
- test/data_sf.json
|
115
|
+
- test/tc_weather_random.rb
|