#!/usr/bin/env python import sys import datetime import urllib2 import signal class HeavensAbove: """Scrapes data about the ISS from http://heavens-above.com""" lat = 0 lon = 0 alt = 0 tz = "GMT" # These defaults are useful for debuging if you're impatient next_pass = datetime.datetime.today() + datetime.timedelta(0,5) seconds_to_next_pass = 5 pass_length = 7 def __init__(self, lat, lon, alt, tz): """Set the postion and altitude information to values""" self.lat = lat self.lon = lon self.alt = alt self.tz = tz def get_passes(self): """This gets a web page with predictable output from www.heavens-above.com and parses it for all upcoming ISS passes""" def remove_chars(s, chars): """Useful utility, send it a drity string and a string of characters to strip from the dirty string""" for c in chars: s = s.replace(c,"") return s today = datetime.datetime.today() year = today.year passes_dict = [] # Get the html page from www.heavens-above.com url = "http://www.heavens-above.com/AllPass1Sat.asp?satid=25544&lat=%f&lng=%f&alt=%0.0f&tz=%s" % (self.lat, self.lon, self.alt, self.tz) ### http://www.heavens-above.com/PassSummary.aspx?satid=25544&lat=51.900254&lng=-2.120078&loc=Cheltenham&alt=100&tz=UCT #url = "http://www.heavens-above.com/PassSummary.aspx?satid=25544&lat=%f&lng=%f&alt=%0.0f&tz=%s" % (self.lat, self.lon, self.alt, self.tz) print url req = urllib2.Request(url) response = urllib2.urlopen(req) data = response.read() #print data # Strip out tabs, new lines, and other white space data = remove_chars(data, '\t\n\r') # Get just the