dougsko-apod 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.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 dougsko
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,22 @@
1
+ = apod
2
+
3
+ This is a library to work with NASA's astronomy pictures of the day.
4
+ It also includes the script, apod-download, which will download the
5
+ current picture of the day to your computer.
6
+
7
+ http://antwrp.gsfc.nasa.gov/apod
8
+
9
+ == Note on Patches/Pull Requests
10
+
11
+ * Fork the project.
12
+ * Make your feature addition or bug fix.
13
+ * Add tests for it. This is important so I don't break it in a
14
+ future version unintentionally.
15
+ * Commit, do not mess with rakefile, version, or history.
16
+ (if you want to have your own version, that is fine but
17
+ bump version in a commit by itself I can ignore when I pull)
18
+ * Send me a pull request. Bonus points for topic branches.
19
+
20
+ == Copyright
21
+
22
+ Copyright (c) 2009 dougsko. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,50 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "apod"
8
+ gem.summary = "A library to work with NASA's astronomy pictures of the day."
9
+ gem.description = "A library to work with NASA's astronomy pictures of the day."
10
+ gem.email = "dougtko@gmail.com"
11
+ gem.homepage = "http://github.com/dougsko/apod"
12
+ gem.authors = ["dougsko"]
13
+ gem.add_development_dependency "rspec"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ rescue LoadError
17
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
18
+ end
19
+
20
+ require 'spec/rake/spectask'
21
+ Spec::Rake::SpecTask.new(:spec) do |spec|
22
+ spec.libs << 'lib' << 'spec'
23
+ spec.spec_files = FileList['spec/**/*_spec.rb']
24
+ spec.spec_opts = ['--color']
25
+ end
26
+
27
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
28
+ spec.libs << 'lib' << 'spec'
29
+ spec.pattern = 'spec/**/*_spec.rb'
30
+ spec.rcov = true
31
+ spec.spec_opts = ['--color']
32
+ end
33
+
34
+ task :spec => :check_dependencies
35
+
36
+ task :default => :spec
37
+
38
+ require 'rake/rdoctask'
39
+ Rake::RDocTask.new do |rdoc|
40
+ if File.exist?('VERSION')
41
+ version = File.read('VERSION')
42
+ else
43
+ version = ""
44
+ end
45
+
46
+ rdoc.rdoc_dir = 'rdoc'
47
+ rdoc.title = "apod #{version}"
48
+ rdoc.rdoc_files.include('README*')
49
+ rdoc.rdoc_files.include('lib/**/*.rb')
50
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.2
data/apod.gemspec ADDED
@@ -0,0 +1,59 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{apod}
8
+ s.version = "0.0.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["dougsko"]
12
+ s.date = %q{2009-09-08}
13
+ s.default_executable = %q{apod-download}
14
+ s.description = %q{A library to work with NASA's astronomy pictures of the day.}
15
+ s.email = %q{dougtko@gmail.com}
16
+ s.executables = ["apod-download"]
17
+ s.extra_rdoc_files = [
18
+ "LICENSE",
19
+ "README.rdoc"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ ".gitignore",
24
+ "LICENSE",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "apod.gemspec",
29
+ "bin/apod-download",
30
+ "lib/apod.rb",
31
+ "lib/pic.rb",
32
+ "spec/apod_spec.rb",
33
+ "spec/pic_spec.rb",
34
+ "spec/spec_helper.rb"
35
+ ]
36
+ s.homepage = %q{http://github.com/dougsko/apod}
37
+ s.rdoc_options = ["--charset=UTF-8"]
38
+ s.require_paths = ["lib"]
39
+ s.rubygems_version = %q{1.3.5}
40
+ s.summary = %q{A library to work with NASA's astronomy pictures of the day.}
41
+ s.test_files = [
42
+ "spec/pic_spec.rb",
43
+ "spec/spec_helper.rb",
44
+ "spec/apod_spec.rb"
45
+ ]
46
+
47
+ if s.respond_to? :specification_version then
48
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
49
+ s.specification_version = 3
50
+
51
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
52
+ s.add_development_dependency(%q<rspec>, [">= 0"])
53
+ else
54
+ s.add_dependency(%q<rspec>, [">= 0"])
55
+ end
56
+ else
57
+ s.add_dependency(%q<rspec>, [">= 0"])
58
+ end
59
+ end
data/bin/apod-download ADDED
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Grabs NASA's Astronomy Picture of the Day
4
+ #
5
+
6
+ require 'rubygems'
7
+ require 'lib/apod'
8
+ require 'optparse'
9
+
10
+ options = {}
11
+ opts = OptionParser.new do |opts|
12
+ opts.banner = "\nDownload NASA's Astronomy Picture of the Day"
13
+
14
+ opts.separator ""
15
+ opts.separator "Options:"
16
+
17
+ opts.on("-o <output file>", String, "Filename to save picture as") do |output|
18
+ options["o"] = output
19
+ end
20
+
21
+ opts.on_tail("-h", "--help", "Show this message") do
22
+ puts opts
23
+ exit
24
+ end
25
+ end
26
+
27
+ opts.parse(ARGV)
28
+
29
+ save_path = options["o"]
30
+
31
+ apod = Apod.new
32
+ apod.download(0, save_path)
data/lib/apod.rb ADDED
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Get links to NASA's Astronomy Pictures of the Day
4
+ #
5
+
6
+ require 'rubygems'
7
+ require 'open-uri'
8
+ require 'hpricot'
9
+ require 'lib/pic'
10
+
11
+ class Apod
12
+ attr_reader(:pictures)
13
+ def initialize
14
+ @pictures = []
15
+
16
+ archive_doc = Hpricot(open("http://antwrp.gsfc.nasa.gov/apod/archivepix.html"))
17
+ archive_doc.search("/body/b/a").each do |elem|
18
+ @pictures << Pic.new(elem.innerHTML, "http://antwrp.gsfc.nasa.gov/apod/" + elem["href"])
19
+ end
20
+ end
21
+
22
+ def titles
23
+ @pictures.collect{ |pic| pic.title }
24
+ end
25
+
26
+ def download(index, save_path)
27
+ doc = Hpricot(open(@pictures[index].website))
28
+ link = "http://apod.nasa.gov/" + doc.at("//center/p[2]/a")["href"]
29
+
30
+ url = URI.parse(link)
31
+
32
+ url.open do |pic|
33
+ File.open(save_path, "w") do |file|
34
+ file << pic.read
35
+ end
36
+ end
37
+ end
38
+ end
data/lib/pic.rb ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # class to hold an entry's information
4
+ #
5
+
6
+ class Pic
7
+ attr_reader(:title, :website)
8
+
9
+ def initialize(title, website)
10
+ @title = title
11
+ @website = website
12
+ end
13
+ end
data/spec/apod_spec.rb ADDED
@@ -0,0 +1,22 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Apod" do
4
+ before do
5
+ @apod = Apod.new
6
+ end
7
+
8
+ it "starts things off" do
9
+ @apod.pictures[0].website.should match(/html/)
10
+ end
11
+
12
+ it "should return an array of titles" do
13
+ @apod.titles.class.to_s.should == "Array"
14
+ end
15
+
16
+ it "should download today's pic" do
17
+ @apod.download(0, "/tmp/apod.jpg")
18
+ `file /tmp/apod.jpg`.should match(/image data/)
19
+ `rm /tmp/apod.jpg`
20
+ end
21
+
22
+ end
data/spec/pic_spec.rb ADDED
@@ -0,0 +1,13 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Pic" do
4
+ it "makes sure Pic.title works right" do
5
+ pic = Pic.new("title", "link")
6
+ pic.title.should == "title"
7
+ end
8
+
9
+ it "makes sure Pic.website works right" do
10
+ pic = Pic.new("title", "link")
11
+ pic.website.should == "link"
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'apod'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dougsko-apod
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - dougsko
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-09-08 00:00:00 -07:00
13
+ default_executable: apod-download
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description: A library to work with NASA's astronomy pictures of the day.
26
+ email: dougtko@gmail.com
27
+ executables:
28
+ - apod-download
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README.rdoc
34
+ files:
35
+ - .document
36
+ - .gitignore
37
+ - LICENSE
38
+ - README.rdoc
39
+ - Rakefile
40
+ - VERSION
41
+ - apod.gemspec
42
+ - bin/apod-download
43
+ - lib/apod.rb
44
+ - lib/pic.rb
45
+ - spec/apod_spec.rb
46
+ - spec/pic_spec.rb
47
+ - spec/spec_helper.rb
48
+ has_rdoc: false
49
+ homepage: http://github.com/dougsko/apod
50
+ licenses:
51
+ post_install_message:
52
+ rdoc_options:
53
+ - --charset=UTF-8
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: "0"
61
+ version:
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: "0"
67
+ version:
68
+ requirements: []
69
+
70
+ rubyforge_project:
71
+ rubygems_version: 1.3.5
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: A library to work with NASA's astronomy pictures of the day.
75
+ test_files:
76
+ - spec/pic_spec.rb
77
+ - spec/spec_helper.rb
78
+ - spec/apod_spec.rb