weather-underground 1.0.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.
data/History.txt ADDED
@@ -0,0 +1,5 @@
1
+ === 1.0.0 2010-03-13
2
+
3
+ * 1 major enhancement:
4
+ * Initial release - supports uploading data to weather undergound
5
+ personal weather station service
data/Manifest.txt ADDED
@@ -0,0 +1,14 @@
1
+ History.txt
2
+ Manifest.txt
3
+ PostInstall.txt
4
+ README.rdoc
5
+ Rakefile
6
+ lib/weather-underground.rb
7
+ lib/weather-underground/uploader.rb
8
+ script/console
9
+ script/destroy
10
+ script/generate
11
+ script/txt2html
12
+ test/test_helper.rb
13
+ test/test_uploader.rb
14
+ test/test_weather-underground.rb
data/PostInstall.txt ADDED
@@ -0,0 +1,7 @@
1
+
2
+ For more information on weather-underground, see http://weather-underground.rubyforge.org
3
+
4
+ NOTE: Change this information in PostInstall.txt
5
+ You can also delete it if you don't want it.
6
+
7
+
data/README.rdoc ADDED
@@ -0,0 +1,50 @@
1
+ = weather-underground
2
+
3
+ * http://github.com/sdague/weather-underground.rb
4
+
5
+ == DESCRIPTION:
6
+
7
+ Modules for interacting with Weather Underground website. Right now
8
+ the focus is on the data upload for their personal weather station
9
+ reporting interface.
10
+
11
+ == FEATURES/PROBLEMS:
12
+
13
+ This currently uses the standard upload interface, it doesn't yet use
14
+ the real time interface.
15
+
16
+ == SYNOPSIS:
17
+
18
+ w = WeatherUndergound::Uploader(station_id, password)
19
+ w.update(:tempf => 72.1, :humidity => 40, :dewptf => 46.67)
20
+
21
+ == REQUIREMENTS:
22
+
23
+ == INSTALL:
24
+
25
+ sudo gem install weather-underground
26
+
27
+ == LICENSE:
28
+
29
+ (The MIT License)
30
+
31
+ Copyright (c) 2010 Sean Dague
32
+
33
+ Permission is hereby granted, free of charge, to any person obtaining
34
+ a copy of this software and associated documentation files (the
35
+ 'Software'), to deal in the Software without restriction, including
36
+ without limitation the rights to use, copy, modify, merge, publish,
37
+ distribute, sublicense, and/or sell copies of the Software, and to
38
+ permit persons to whom the Software is furnished to do so, subject to
39
+ the following conditions:
40
+
41
+ The above copyright notice and this permission notice shall be
42
+ included in all copies or substantial portions of the Software.
43
+
44
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
45
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
46
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
47
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
48
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
49
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
50
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,28 @@
1
+ require 'rubygems'
2
+ gem 'hoe', '>= 2.1.0'
3
+ require 'hoe'
4
+ require 'fileutils'
5
+ require './lib/weather-underground'
6
+
7
+ ENV['VERSION'] = WeatherUnderground::VERSION
8
+
9
+ Hoe.plugin :newgem
10
+ Hoe.plugin :website
11
+ # Hoe.plugin :cucumberfeatures
12
+
13
+ # Generate all the Rake tasks
14
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
15
+ $hoe = Hoe.spec 'weather-underground' do
16
+ self.developer 'Sean Dague', 'sean@dague.net'
17
+ self.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
18
+ self.rubyforge_name = 'sdaguegems' # self.name # TODO this is default value
19
+ # self.extra_deps = [['activesupport','>= 2.0.2']]
20
+
21
+ end
22
+
23
+ require 'newgem/tasks'
24
+ Dir['tasks/**/*.rake'].each { |t| load t }
25
+
26
+ # TODO - want other tests/tasks run by default? Add them to the list
27
+ # remove_task :default
28
+ # task :default => [:spec, :features]
@@ -0,0 +1,32 @@
1
+ module WeatherUnderground
2
+
3
+ class Uploader
4
+ require "uri"
5
+ require "open-uri"
6
+
7
+ BaseURL = "http://weatherstation.wunderground.com/weatherstation/updateweatherstation.php"
8
+
9
+ def initialize(station, passwd)
10
+ @station = station
11
+ @passwd = passwd
12
+ end
13
+
14
+ def url(params = {})
15
+ base = "#{BaseURL}?ID=#{@station}&PASSWORD=#{@passwd}"
16
+ base += "&dateutc=#{URI.escape(Time.now.utc.strftime("%Y-%m-%d %H:%M:%S"))}"
17
+ base += "&action=updateraw"
18
+ # we sort them just so we get predictable order for tests
19
+ params.sort {|a, b| a.to_s <=> b.to_s}.each do |k, v|
20
+ base += "&#{k}=#{URI.escape(v.to_s)}"
21
+ end
22
+ return base
23
+ end
24
+
25
+ def update(data = {})
26
+ open(url(data)) do |f|
27
+ # we should really do something with the response
28
+
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,8 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ require "weather-underground/uploader"
5
+
6
+ module WeatherUnderground
7
+ VERSION = '1.0.0'
8
+ end
data/script/console ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/weather-underground.rb'}"
9
+ puts "Loading weather-underground gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
data/script/destroy ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
data/script/generate ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
data/script/txt2html ADDED
@@ -0,0 +1,71 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ load File.dirname(__FILE__) + "/../Rakefile"
4
+ require 'rubyforge'
5
+ require 'redcloth'
6
+ require 'syntax/convertors/html'
7
+ require 'erb'
8
+
9
+ download = "http://rubyforge.org/projects/#{$hoe.rubyforge_name}"
10
+ version = $hoe.version
11
+
12
+ def rubyforge_project_id
13
+ RubyForge.new.configure.autoconfig["group_ids"][$hoe.rubyforge_name]
14
+ end
15
+
16
+ class Fixnum
17
+ def ordinal
18
+ # teens
19
+ return 'th' if (10..19).include?(self % 100)
20
+ # others
21
+ case self % 10
22
+ when 1: return 'st'
23
+ when 2: return 'nd'
24
+ when 3: return 'rd'
25
+ else return 'th'
26
+ end
27
+ end
28
+ end
29
+
30
+ class Time
31
+ def pretty
32
+ return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
33
+ end
34
+ end
35
+
36
+ def convert_syntax(syntax, source)
37
+ return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
38
+ end
39
+
40
+ if ARGV.length >= 1
41
+ src, template = ARGV
42
+ template ||= File.join(File.dirname(__FILE__), '/../website/template.html.erb')
43
+ else
44
+ puts("Usage: #{File.split($0).last} source.txt [template.html.erb] > output.html")
45
+ exit!
46
+ end
47
+
48
+ template = ERB.new(File.open(template).read)
49
+
50
+ title = nil
51
+ body = nil
52
+ File.open(src) do |fsrc|
53
+ title_text = fsrc.readline
54
+ body_text_template = fsrc.read
55
+ body_text = ERB.new(body_text_template).result(binding)
56
+ syntax_items = []
57
+ body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</\1>!m){
58
+ ident = syntax_items.length
59
+ element, syntax, source = $1, $2, $3
60
+ syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
61
+ "syntax-temp-#{ident}"
62
+ }
63
+ title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
64
+ body = RedCloth.new(body_text).to_html
65
+ body.gsub!(%r!(?:<pre><code>)?syntax-temp-(\d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
66
+ end
67
+ stat = File.stat(src)
68
+ created = stat.ctime
69
+ modified = stat.mtime
70
+
71
+ $stdout << template.result(binding)
@@ -0,0 +1,3 @@
1
+ require 'stringio'
2
+ require 'test/unit'
3
+ require File.dirname(__FILE__) + '/../lib/weather-underground'
@@ -0,0 +1,30 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestUploader < Test::Unit::TestCase
4
+
5
+ def test_uris
6
+ u = WeatherUnderground::Uploader.new("foo","pass")
7
+
8
+ assert_equal(
9
+ "http://weatherstation.wunderground.com/weatherstation/updateweatherstation.php?ID=foo&PASSWORD=pass&dateutc=#{URI.escape(Time.now.utc.strftime("%Y-%m-%d %H:%M:%S"))}&action=updateraw",
10
+ u.url
11
+ )
12
+
13
+ assert_equal(
14
+ "http://weatherstation.wunderground.com/weatherstation/updateweatherstation.php?ID=foo&PASSWORD=pass&dateutc=#{URI.escape(Time.now.utc.strftime("%Y-%m-%d %H:%M:%S"))}&action=updateraw&tempf=69.1",
15
+ u.url(:tempf => 69.1)
16
+ )
17
+
18
+ assert_equal(
19
+ "http://weatherstation.wunderground.com/weatherstation/updateweatherstation.php?ID=foo&PASSWORD=pass&dateutc=#{URI.escape(Time.now.utc.strftime("%Y-%m-%d %H:%M:%S"))}&action=updateraw&dewptf=54.326&humidity=50&tempf=69.1",
20
+ u.url(:tempf => 69.1, :humidity => 50, :dewptf => 54.326)
21
+ )
22
+
23
+ assert_equal(
24
+ "http://weatherstation.wunderground.com/weatherstation/updateweatherstation.php?ID=foo&PASSWORD=pass&dateutc=#{URI.escape(Time.now.utc.strftime("%Y-%m-%d %H:%M:%S"))}&action=updateraw&dewptf=54.326&humidity=50&tempf=69.1",
25
+ u.url(:humidity => 50, :tempf => 69.1, :dewptf => 54.326)
26
+ )
27
+
28
+ end
29
+
30
+ end
@@ -0,0 +1,11 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestWeatherUnderground < Test::Unit::TestCase
4
+
5
+ def setup
6
+ end
7
+
8
+ def test_truth
9
+ assert true
10
+ end
11
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: weather-underground
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Sean Dague
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-03-13 23:00:00 -05:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rubyforge
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.0.3
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: gemcutter
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.3.0
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: hoe
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 2.5.0
44
+ version:
45
+ description: |-
46
+ Modules for interacting with Weather Underground website. Right now
47
+ the focus is on the data upload for their personal weather station
48
+ reporting interface.
49
+ email:
50
+ - sean@dague.net
51
+ executables: []
52
+
53
+ extensions: []
54
+
55
+ extra_rdoc_files:
56
+ - History.txt
57
+ - Manifest.txt
58
+ - PostInstall.txt
59
+ files:
60
+ - History.txt
61
+ - Manifest.txt
62
+ - PostInstall.txt
63
+ - README.rdoc
64
+ - Rakefile
65
+ - lib/weather-underground.rb
66
+ - lib/weather-underground/uploader.rb
67
+ - script/console
68
+ - script/destroy
69
+ - script/generate
70
+ - script/txt2html
71
+ - test/test_helper.rb
72
+ - test/test_uploader.rb
73
+ - test/test_weather-underground.rb
74
+ has_rdoc: true
75
+ homepage: http://github.com/sdague/weather-underground.rb
76
+ licenses: []
77
+
78
+ post_install_message: PostInstall.txt
79
+ rdoc_options:
80
+ - --main
81
+ - README.rdoc
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: "0"
89
+ version:
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: "0"
95
+ version:
96
+ requirements: []
97
+
98
+ rubyforge_project: sdaguegems
99
+ rubygems_version: 1.3.5
100
+ signing_key:
101
+ specification_version: 3
102
+ summary: Modules for interacting with Weather Underground website
103
+ test_files:
104
+ - test/test_uploader.rb
105
+ - test/test_weather-underground.rb
106
+ - test/test_helper.rb