apod 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 18a7a4692a95e8d55d193db5ed2f4b7e4cef1efd
4
+ data.tar.gz: 248a53fa1679a96d11886adc13cdc4d961777e77
5
+ SHA512:
6
+ metadata.gz: 2f075a907051f53258a0400c4c1aa7f9e8892108345bef5c256b0dc2caa8f595b026dc348bd5133da54dbe79626b7b07d6d4707e1f4635914d355bbd3df01941
7
+ data.tar.gz: b88a6bd6b58600ae223e760872c6e1e9756862c1a9fe1cb449fa3611d52dcdd9b205cc34907c7103dbcadc5a603e491804a638a31e2e61dd721da11d224b8591
data/.gitignore CHANGED
@@ -1,5 +1,17 @@
1
+ <<<<<<< HEAD
2
+ /.bundle/
3
+ /.yardoc
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
11
+ =======
1
12
  *.sw?
2
13
  .DS_Store
3
14
  coverage
4
15
  rdoc
5
16
  pkg
17
+ >>>>>>> 7cb01caa087c8e6d3c4c1f81531fa922e27caef2
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in apod.gemspec
4
+ gemspec
5
+
6
+ gem 'nokogiri'
7
+ gem 'httpclient'
8
+
9
+ group :test, :development do
10
+ gem 'rspec'
11
+ end
@@ -0,0 +1,42 @@
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
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'apod'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install apod
22
+
23
+ ## Usage
24
+
25
+ This library comes with an executable, apod-download, which can be used
26
+ to download the current picture of the day. For usage, run:
27
+
28
+ ```apod-download -h```
29
+
30
+ ## Development
31
+
32
+ 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. Run `bundle exec apod` to use the code located in this directory, ignoring other installed copies of this gem.
33
+
34
+ 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).
35
+
36
+ ## Contributing
37
+
38
+ 1. Fork it ( https://github.com/[my-github-username]/apod/fork )
39
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
40
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
41
+ 4. Push to the branch (`git push origin my-new-feature`)
42
+ 5. Create a new Pull Request
data/Rakefile CHANGED
@@ -1,57 +1,6 @@
1
- require 'rubygems'
2
- require 'rake'
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
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
4
+ RSpec::Core::RakeTask.new(:spec)
37
5
 
38
6
  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
@@ -1,65 +1,24 @@
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 -*-
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'apod/version'
5
5
 
6
- Gem::Specification.new do |s|
7
- s.name = %q{apod}
8
- s.version = "0.1.3"
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "apod"
8
+ spec.version = Apod::VERSION
9
+ spec.authors = ["Doug Prostko"]
10
+ spec.email = ["dougtko@gmail.com"]
9
11
 
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
- ]
12
+ spec.summary = %q{A library to work with NASA's astronomy pictures of the day.}
13
+ spec.description = %q{A library to work with NASA's astronomy pictures of the day.}
14
+ spec.homepage = "https://github.com/dougsko/apod"
46
15
 
47
- if s.respond_to? :specification_version then
48
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
49
- s.specification_version = 3
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"]
50
20
 
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
21
+ spec.add_development_dependency "bundler", "~> 1.9"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec"
65
24
  end
@@ -4,7 +4,7 @@
4
4
  #
5
5
 
6
6
  require 'rubygems'
7
- require 'apod'
7
+ require 'lib/apod'
8
8
  require 'optparse'
9
9
 
10
10
  options = {}
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "apod"
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
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Grabs NASA's Astronomy Picture of the Day
4
+ #
5
+
6
+ require_relative 'apod'
7
+ require 'optparse'
8
+
9
+ options = {}
10
+ opts = OptionParser.new do |opts|
11
+ opts.banner = "\nDownload NASA's Astronomy Picture of the Day"
12
+
13
+ opts.separator ""
14
+ opts.separator "Options:"
15
+
16
+ opts.on("-o <output file>", String, "Filename to save picture as") do |output|
17
+ options["o"] = output
18
+ end
19
+
20
+ opts.on_tail("-h", "--help", "Show this message") do
21
+ puts opts
22
+ exit
23
+ end
24
+ end
25
+
26
+ opts.parse(ARGV)
27
+
28
+ save_path = options["o"]
29
+
30
+ apod = Apod.new
31
+ apod.pictures.first.download(save_path)
@@ -1,22 +1,18 @@
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'
1
+ require "apod/version"
2
+ require_relative 'pic'
3
+ require 'nokogiri'
8
4
  require 'httpclient'
9
- require 'hpricot'
10
- require 'pic'
11
5
 
12
6
  class Apod
13
7
  attr_reader(:pictures)
8
+
14
9
  def initialize
15
10
  @pictures = []
16
11
 
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"])
12
+ page = Nokogiri::HTML(open("http://apod.nasa.gov/apod/archivepix.html"))
13
+ pics = page.css('b a')
14
+ pics.each do |pic|
15
+ @pictures << Pic.new(pic.text, "http://apod.nasa.gov/apod/" + pic["href"])
20
16
  end
21
17
  end
22
18
 
@@ -25,20 +21,18 @@ class Apod
25
21
  end
26
22
 
27
23
  def search(query)
24
+ @pictures = []
25
+
28
26
  if query.size > 60
29
27
  return "ERROR: Query must be less than 60 characters"
30
28
  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
29
+
30
+ clnt = HTTPClient.new("http://apod.nasa.gov/cgi-bin/apod/apod_search")
31
+ res = clnt.post('http://apod.nasa.gov/cgi-bin/apod/apod_search', {'tquery' => query}).content
32
+ page = Nokogiri::HTML(res)
33
+ page.css('body > p > a:nth-child(2)').each do |elem|
34
+ @pictures << Pic.new(elem.text, elem["href"])
41
35
  end
42
- @pictures.pop
36
+ @pictures
43
37
  end
44
38
  end
@@ -0,0 +1,3 @@
1
+ class Apod
2
+ VERSION = "0.2.0"
3
+ end
data/lib/pic.rb CHANGED
@@ -15,10 +15,9 @@ class Pic
15
15
 
16
16
  # Download a picture to a file
17
17
  def download(save_path)
18
- doc = Hpricot(open(self.website))
19
- link = "http://apod.nasa.gov/" + doc.at("//center/p[2]/a")["href"]
18
+ page = Nokogiri::HTML(open(self.website))
19
+ link = "http://apod.nasa.gov/" + page.css('body > center:nth-child(1) > p:nth-child(3) > a')[0]['href']
20
20
  url = URI.parse(link)
21
-
22
21
  url.open do |pic|
23
22
  File.open(save_path, "w") do |file|
24
23
  file << pic.read
metadata CHANGED
@@ -1,99 +1,102 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: apod
3
- version: !ruby/object:Gem::Version
4
- version: 0.1.3
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
5
  platform: ruby
6
- authors:
7
- - dougsko
6
+ authors:
7
+ - Doug Prostko
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: exe
10
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
11
+ date: 2015-09-10 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'
17
20
  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:
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: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
31
45
  - - ">="
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:
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
41
52
  - - ">="
42
- - !ruby/object:Gem::Version
43
- version: "0"
44
- version:
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
45
55
  description: A library to work with NASA's astronomy pictures of the day.
46
- email: dougtko@gmail.com
47
- executables:
56
+ email:
57
+ - dougtko@gmail.com
58
+ executables:
48
59
  - apod-download
49
60
  extensions: []
50
-
51
- extra_rdoc_files:
52
- - LICENSE
53
- - README.rdoc
54
- files:
55
- - .document
56
- - .gitignore
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".document"
64
+ - ".gitignore"
65
+ - ".rspec"
66
+ - ".travis.yml"
67
+ - Gemfile
57
68
  - LICENSE
58
- - README.rdoc
69
+ - README.md
59
70
  - Rakefile
60
- - VERSION
61
71
  - apod.gemspec
62
72
  - bin/apod-download
73
+ - bin/console
74
+ - bin/setup
75
+ - exe/apod-download
63
76
  - lib/apod.rb
77
+ - lib/apod/version.rb
64
78
  - 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
79
+ homepage: https://github.com/dougsko/apod
70
80
  licenses: []
71
-
81
+ metadata: {}
72
82
  post_install_message:
73
- rdoc_options:
74
- - --charset=UTF-8
75
- require_paths:
83
+ rdoc_options: []
84
+ require_paths:
76
85
  - lib
77
- required_ruby_version: !ruby/object:Gem::Requirement
78
- requirements:
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
79
88
  - - ">="
80
- - !ruby/object:Gem::Version
81
- version: "0"
82
- version:
83
- required_rubygems_version: !ruby/object:Gem::Requirement
84
- requirements:
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
85
93
  - - ">="
86
- - !ruby/object:Gem::Version
87
- version: "0"
88
- version:
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
89
96
  requirements: []
90
-
91
97
  rubyforge_project:
92
- rubygems_version: 1.3.5
98
+ rubygems_version: 2.4.6
93
99
  signing_key:
94
- specification_version: 3
100
+ specification_version: 4
95
101
  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
102
+ test_files: []
@@ -1,22 +0,0 @@
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/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.1.3
@@ -1,32 +0,0 @@
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
@@ -1,13 +0,0 @@
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
@@ -1,9 +0,0 @@
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