github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

lojic / sample_code

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 2
    • 1
  • Source
  • Commits
  • Network (1)
  • Issues (0)
  • Downloads (0)
  • Wiki (1)
  • Graphs
  • Tree: 7b41e88

click here to add a description

click here to add a homepage

  • Branches (1)
    • master
  • Tags (0)
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

Sample code — Read more

  cancel

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

added Emacs invocation sample & other comments 
lojic (author)
Tue Mar 10 21:06:14 -0700 2009
commit  7b41e88adefd84154a54c97de86924f8517dca2c
tree    2ded0d28796768fd28ad69c3b45e0e0debcc5b99
parent  5bce26d83c308358cb2fe8e0608115fb01053020
sample_code / ruby / sunrise_http_post.rb ruby/sunrise_http_post.rb
100644 53 lines (47 sloc) 2.141 kb
edit raw blame history
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/local/bin/ruby
#
# An example of using HTTP POST to retrieve sunrise/set data
#
# Author : Brian Adkins
# Site : http://lojic.com
# License: Just leave copyright notice :)
# Copyright 2009 Brian Adkins, all rights reserved
#
# Reference: http://aa.usno.navy.mil/data/docs/RS_OneDay.php
#
# "If you plan to write your own form to access the cgi script for
# sunrise/sunset calculations (not recommended), please use the above
# line in your form but substitute in the value field an identifier of
# your own choosing, up to 8 characters. For example, <input
# type="hidden" name="ID", value="UCLA"> . If you are setting this up
# for an institution, please e-mail us (at ) and let us know what
# identifier you are using and who you are. Thanks... this allows us to
# keep track of all our users, even those who bypass our normal web
# usage log, and helps us justify our work on the web. (Nothing in this
# note should be construed as encouragement to set up your own form, as
# we do not guarantee that either our form or the program called by the
# cgi script will not change.)"
 
# Here's a simple Emacs function to invoke this Ruby script if it's
# executable and available in the path
# (defun bja-sunrise ()
# "Display sunrise/sunset information."
# (interactive)
# (shell-command "sunrise_http_post.rb"))
 
require 'net/http'
 
YOUR_ID = '' # A unique ID per comment above
YOUR_CITY = '' # The name of your city
YOUR_STATE = '' # Two letter state abbreviation
 
now = Time.now
month = now.month
day = now.day + 1 # Tomorrow
year = now.year
 
Net::HTTP.start('aa.usno.navy.mil') do |query|
  response = query.post('/cgi-bin/aa_pap.pl', "FFX=1&ID=#{YOUR_ID}&xxy=#{year}&xxm=#{month}&xxd=#{day}&st=#{YOUR_STATE}&place=#{YOUR_CITY}&ZZZ=END")
  if response.body =~ /Begin civil twilight[^0-9]*(\d+:\d{2} [ap].m.).*Sunrise[^0-9]*(\d+:\d{2} [ap].m.).*Sunset[^0-9]*(\d+:\d{2} [ap].m.).*End civil twilight[^0-9]*(\d+:\d{2} [ap].m.)/m
    puts "#{month}/#{day}/#{year}"
    puts "Begin Twilight: #{$1}"
    puts "Sunrise : #{$2}"
    puts "Sunset : #{$3}"
    puts "End Twilight : #{$4}"
  end
end
 
Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server