apod 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -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.
@@ -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.
@@ -0,0 +1,57 @@
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.add_dependency "hpricot"
15
+ gem.add_dependency "httpclient"
16
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
17
+ end
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
20
+ end
21
+
22
+ require 'spec/rake/spectask'
23
+ Spec::Rake::SpecTask.new(:spec) do |spec|
24
+ spec.libs << 'lib' << 'spec'
25
+ spec.spec_files = FileList['spec/**/*_spec.rb']
26
+ spec.spec_opts = ['--color']
27
+ end
28
+
29
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
30
+ spec.libs << 'lib' << 'spec'
31
+ spec.pattern = 'spec/**/*_spec.rb'
32
+ spec.rcov = true
33
+ spec.spec_opts = ['--color']
34
+ end
35
+
36
+ #task :spec => :check_dependencies
37
+
38
+ task :default => :spec
39
+
40
+ require 'rake/rdoctask'
41
+ #require 'darkfish-rdoc'
42
+ Rake::RDocTask.new do |rdoc|
43
+ if File.exist?('VERSION')
44
+ version = File.read('VERSION')
45
+ else
46
+ version = ""
47
+ end
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "apod #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ #rdoc.options += [
54
+ # '-N',
55
+ # '-f', 'darkfish',
56
+ #]
57
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.3
@@ -0,0 +1,65 @@
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.1.3"
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-09}
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
+ s.add_runtime_dependency(%q<hpricot>, [">= 0"])
54
+ s.add_runtime_dependency(%q<httpclient>, [">= 0"])
55
+ else
56
+ s.add_dependency(%q<rspec>, [">= 0"])
57
+ s.add_dependency(%q<hpricot>, [">= 0"])
58
+ s.add_dependency(%q<httpclient>, [">= 0"])
59
+ end
60
+ else
61
+ s.add_dependency(%q<rspec>, [">= 0"])
62
+ s.add_dependency(%q<hpricot>, [">= 0"])
63
+ s.add_dependency(%q<httpclient>, [">= 0"])
64
+ end
65
+ end
@@ -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 '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.pictures.first.download(save_path)
@@ -0,0 +1,44 @@
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 'httpclient'
9
+ require 'hpricot'
10
+ require 'pic'
11
+
12
+ class Apod
13
+ attr_reader(:pictures)
14
+ def initialize
15
+ @pictures = []
16
+
17
+ archive_doc = Hpricot(open("http://antwrp.gsfc.nasa.gov/apod/archivepix.html"))
18
+ archive_doc.search("/body/b/a").each do |elem|
19
+ @pictures << Pic.new(elem.innerHTML, "http://antwrp.gsfc.nasa.gov/apod/" + elem["href"])
20
+ end
21
+ end
22
+
23
+ def titles
24
+ @pictures.collect{ |pic| pic.title }
25
+ end
26
+
27
+ def search(query)
28
+ if query.size > 60
29
+ return "ERROR: Query must be less than 60 characters"
30
+ end
31
+ @pictures = []
32
+ clnt = HTTPClient.new("http://antwrp.gsfc.nasa.gov/cgi-bin/apod/apod_search")
33
+ results = clnt.post('http://antwrp.gsfc.nasa.gov/cgi-bin/apod/apod_search', {'tquery' => query}).content
34
+ doc = Hpricot(results)
35
+ doc.search("//p").each do |para|
36
+ title = para.at("a[2]")
37
+ link = para.at("a")
38
+ if title != nil and link != nil
39
+ @pictures << Pic.new(title.innerHTML, link["href"])
40
+ end
41
+ end
42
+ @pictures.pop
43
+ end
44
+ end
@@ -0,0 +1,28 @@
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
+ # Takes two strings, the title of the picture and the URL to its
10
+ # website.
11
+ def initialize(title, website)
12
+ @title = title
13
+ @website = website
14
+ end
15
+
16
+ # Download a picture to a file
17
+ def download(save_path)
18
+ doc = Hpricot(open(self.website))
19
+ link = "http://apod.nasa.gov/" + doc.at("//center/p[2]/a")["href"]
20
+ url = URI.parse(link)
21
+
22
+ url.open do |pic|
23
+ File.open(save_path, "w") do |file|
24
+ file << pic.read
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,32 @@
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 "searches for a picture" do
17
+ results = @apod.search("earth")
18
+ results.class.to_s.should match(/Pic/)
19
+ end
20
+
21
+ it "download the first picture" do
22
+ @apod.pictures.first.download("/tmp/apod.jpg")
23
+ `file /tmp/apod.jpg`.should match(/image data/)
24
+ `rm /tmp/apod.jpg`
25
+ end
26
+
27
+ it "tries to search with a query that is too big" do
28
+ @apod.search("A"*61).should match(/ERROR/)
29
+ end
30
+
31
+
32
+ end
@@ -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,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: apod
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - dougsko
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-09-09 00:00:00 -04: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
+ - !ruby/object:Gem::Dependency
26
+ name: hpricot
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: httpclient
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ version:
45
+ description: A library to work with NASA's astronomy pictures of the day.
46
+ email: dougtko@gmail.com
47
+ executables:
48
+ - apod-download
49
+ extensions: []
50
+
51
+ extra_rdoc_files:
52
+ - LICENSE
53
+ - README.rdoc
54
+ files:
55
+ - .document
56
+ - .gitignore
57
+ - LICENSE
58
+ - README.rdoc
59
+ - Rakefile
60
+ - VERSION
61
+ - apod.gemspec
62
+ - bin/apod-download
63
+ - lib/apod.rb
64
+ - lib/pic.rb
65
+ - spec/apod_spec.rb
66
+ - spec/pic_spec.rb
67
+ - spec/spec_helper.rb
68
+ has_rdoc: true
69
+ homepage: http://github.com/dougsko/apod
70
+ licenses: []
71
+
72
+ post_install_message:
73
+ rdoc_options:
74
+ - --charset=UTF-8
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: "0"
82
+ version:
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: "0"
88
+ version:
89
+ requirements: []
90
+
91
+ rubyforge_project:
92
+ rubygems_version: 1.3.5
93
+ signing_key:
94
+ specification_version: 3
95
+ summary: A library to work with NASA's astronomy pictures of the day.
96
+ test_files:
97
+ - spec/pic_spec.rb
98
+ - spec/spec_helper.rb
99
+ - spec/apod_spec.rb