#!/usr/bin/python
# stars.cgi 2003-12-12
# Tiny cgi to be included in a page. Counts how many stars my light cone has
# covered, and what's about to be covered.
# Data from
# http://www.anzwers.org/free/universe/50lys.html
# More at
# http://interconnected.org/home/2003_12_07_archive.shtml#107124883755467946
# Apologies for my appalling python.
stars = {
'Sun': 0,
'Alpha Centauri': 4.39,
'Alpha Canis Majoris': 8.6,
'Epsilon Eridani': 10.5,
'Alpha Canis Minoris': 11.41,
'61 Cygni': 11.43,
'Epsilon Indi': 11.83,
'Tau Ceti': 11.9,
'Omicron-2 Eridani': 16.45,
'70 Ophiuchi': 16.59,
'Alpha Aquilae': 16.77,
'Sigma Draconis': 18.81,
'HR5568': 19.26,
'Eta Cassiopeiae': 19.42,
'36 Ophiuchi': 19.52,
'HR7703': 19.74,
'82 Eridani': 19.76,
'Delta Pavonis': 19.92,
'HR8832': 21.28,
'Xi Bootis': 21.85,
'HR753': 23.51,
'HR6426': 23.6,
'HR222': 24.33,
'107 Piscium': 24.36,
'Beta Hydri': 24.38,
'Mu Cassiopeiae': 24.63,
'HR8721': 24.91,
'Alpha Piscis Austrini': 25.07,
'Alpha Lyrae': 25.3,
'Pi-3 Orionis': 26.18,
'Chi Draconis': 26.28,
'p Eridani': 26.57,
'Xi Ursae Majoris': 27.2,
'Beta Canum Venaticorum': 27.3,
'Mu Herculis': 27.4,
'61 Virginis': 27.81,
'Zeta Tucanae': 28.03,
'Chi-1 Orionis': 28.26,
'HR6416': 28.66,
'HR1614': 28.75,
'HR7722': 28.78,
'Gamma Leporis': 29.25,
'Delta Eridani': 29.5,
'Beta Comae Berenices': 29.86,
'Kappa-1 Ceti': 29.87,
'Gamma Pavonis': 30.06,
'HR4523': 30.14,
'HR4458': 31.11,
'61 Ursae Majoris': 31.12,
'12 Ophiuchi': 31.89,
'HR511': 32.54,
'HR5256': 32.96,
'Alpha Mensae': 33.1,
'Beta Geminorum': 33.72,
'HR857': 33.86,
'Iota Persei': 34.36,
'HR9038': 35.19,
'Zeta Herculis': 35.21,
'Delta Trianguli': 35.38,
'Beta Virginis': 35.55,
'HR637': 35.6,
'Beta Leonis': 36.18,
'HR6806': 36.2,
'54 Piscium': 36.23,
'Gamma Serpentis': 36.27,
'11 Leonis Minoris': 36.46,
'Theta Persei': 36.63,
'Alpha Bootis': 36.71,
'Eta Bootis': 36.99,
'HR5553': 37.62,
'Zeta Doradus': 38,
'Iota Pegasi': 38.34,
'Delta Capricorni': 38.56,
'Gamma Virginis': 38.59,
'Zeta Reticuli': 39.46,
'Zeta Trianguli Australis': 39.48,
'HR3384': 39.7,
'HR1925': 39.93,
'Beta Trianguli Australis': 40.15,
'85 Pegasi': 40.45,
'Rho Cancri': 40.87,
'HR3259': 41.04,
'HR483': 41.24,
'HR683': 41.35,
'44 Bootis': 41.61,
'HR6518': 41.74,
'36 Ursae Majoris': 41.91,
'HR6094': 41.98,
'HR4587': 42.1,
'Alpha Aurigae': 42.2,
'HR6998': 42.35,
'58 Eridani': 43.43,
'Upsilon Andromedae': 43.93,
'Theta Ursae Majoris': 43.99,
'HR8501': 44.39,
'HR8': 44.69,
'Beta Aquilae': 44.71,
'10 Tauri': 44.75,
'Iota Piscium': 44.98,
'Gamma Cephei': 44.99,
'Tau-1 Eridani': 45.58,
'18 Scorpii': 45.74,
'47 Ursae Majoris': 45.91,
'26 Draconis': 45.95,
'Alpha Fornacis': 46.03,
'HR7578': 46.37,
'Pi-1 Ursae Majoris': 46.55,
'Alpha Ophiuchi': 46.7,
'Eta Cephei': 46.77,
'72 Herculis': 46.94,
'Nu-2 Lupi': 47.48,
'Theta Bootis': 47.52,
'Iota Ursae Majoris': 47.74,
'HR7898': 47.77,
'111 Tauri': 47.83,
'Psi Serpentis': 47.85,
'Alpha Corvi': 48.17,
'I Hydrae': 48.54,
'20 Leonis Minoris': 48.58,
'HR209': 48.74,
'Alpha Cephei': 48.8,
'HR7162': 48.86,
'Eta Leporis': 49.07,
'Nu Phoenicis': 49.1,
'19 Draconis': 49.21,
'31 Aquilae': 49.41,
'HR3018': 49.58,
'HR5864': 49.72,
'Mu Arae': 49.83
}
def ly_to_duration(ly):
seconds = ly * 365 * 24 * 60 * 60
if seconds / ((365 * 24 * 60 * 60) /12) > 1.5:
return str(int(round(seconds / ((365 * 24 * 60 * 60) /12)))) + " months"
elif seconds / ((365 * 24 * 60 * 60) /52) > 1.5:
return str(int(round(seconds / ((365 * 24 * 60 * 60) /52)))) + " weeks"
elif seconds / (24 * 60 * 60) > 1.5:
return str(int(round(seconds / (24 * 60 * 60)))) + " days"
elif seconds / (60 * 60) > 1.5:
return str(int(round(seconds / (60 * 60)))) + " hours"
else:
return "-"
import cgi
import calendar
import time
import sys
import re
print """Content-Type: text/xml
Light cone
http://interconnected.org/home/more/lightcone/
"In general relativity, the future light cone is the boundary of the causal future of a point and the past light cone is the boundary of its causal past." [wikipedia.org] This feed lists the stars in your personal light cone.
"""
fs = cgi.FieldStorage()
re_date = re.compile("^\d\d\d\d-\d\d-\d\d$")
if not (fs.has_key('d') and re_date.match(fs.getvalue('d'))):
print """-
Error
Date not understood.
"""
sys.exit(0)
t = time.strptime(fs.getvalue('d'), "%Y-%m-%d")
birthday = calendar.timegm(t)
ago = time.time() - birthday
years = ago/(365*24*60*60)
inside = [(years - ly, star) for (star, ly) in stars.items() if ly < years]
inside.sort()
passed = inside[-1]
outside = [(ly - years, star) for (star, ly) in stars.items() if ly >= years]
outside.sort()
coming = outside[0]
time_coming = ly_to_duration(outside[0][0])
if time_coming == "-":
copy = "about to be enveloped by"
time_coming = "right about now"
else:
copy = "only %s from" % time_coming
time_coming += " away"
print """-
Coming: %s (%s)
%s is %2.1f light years away and %s the outer surface of your light cone - your ever-growing sphere of potential causality - which began its expansion from Earth on %s.
""" % (outside[0][1], time_coming, outside[0][1], years + outside[0][0], copy, time.strftime("%B %d %Y" ,t))
count = len(inside)
time_ago = ly_to_duration(inside[0][0])
if time_ago == "-":
time_ago = "just now"
else:
time_ago += " ago"
print """-
%s. %s
%s is %2.1f light years from Earth. It was enveloped by your light cone %s.
""" % (count, inside[0][1], inside[0][1], years - inside[0][0], time_ago)
for (ly, star) in inside[1:]:
count -= 1
if star == "Sun":
print """-
%s. Sun
The Sun is right here.
""" % count
else:
print """-
%s. %s
%s is %2.1f light years away.
""" % (count, star, star, years - ly)
print """
"""