')[3:]
84 |
85 | # Go through each row
86 | for i, apass in enumerate(passes):
87 | # split the row into cells
88 | details = apass.split('| ')
89 |
90 | # parse the data out into variables
91 | date = details[1][-15:-9].strip()
92 | begin_time = details[2][0:8].strip()
93 | begin_alt = details[3][0:2].strip()
94 | begin_az = details[4][0:3].strip()
95 | max_time = details[5][0:8].strip()
96 | max_alt = details[6][0:2].strip()
97 | max_az = details[7][0:3].strip()
98 | end_time = details[8][0:8].strip()
99 | end_alt = details[9][0:2].strip()
100 | end_az = details[10][0:3].strip()
101 |
102 | # further parse the date
103 | day = date[0:2]
104 | month = date[3:]
105 |
106 | #debug
107 | #print i, date, month, day, begin_time, begin_alt, begin_az, max_time, max_alt, max_az, end_time, end_alt, end_az
108 |
109 | # Find the begining and ending dates and turn them into datetime objects
110 | begin_datetime = datetime.datetime.strptime("%d-%s-%s %s" % (year, month, day, begin_time), "%Y-%b-%d %H:%M:%S")
111 | end_datetime = datetime.datetime.strptime("%d-%s-%s %s" % (year, month, day, end_time), "%Y-%b-%d %H:%M:%S")
112 |
113 | #debug
114 | #print i, begin_datetime, end_datetime
115 |
116 | # Store the data in a list
117 | passes_dict.append({"begin_time": begin_datetime, "end_time": end_datetime})
118 |
119 | # Return all the data
120 | return passes_dict
121 |
122 | def get_next_pass(self):
123 | """This will try and get all the upcoming passes from www.heavens-above.com and store the data for upcoming one"""
124 |
125 | now = datetime.datetime.today()
126 |
127 | try:
128 | # Get all passes
129 | passes = self.get_passes()
130 |
131 | # Loop through the passes and find the first upcoming one
132 | for apass in passes:
133 | next_pass = apass["begin_time"]
134 | timedelta = next_pass - now
135 | past = timedelta.days
136 | if past >= 0:
137 | alarm_sleep_time = timedelta.seconds
138 | break
139 |
140 | # How long will this pass last?
141 | duration = apass["end_time"] - next_pass
142 |
143 | self.next_pass = next_pass
144 | self.seconds_to_next_pass = alarm_sleep_time
145 | self.pass_length = duration.seconds
146 | except:
147 | # I don't know what to do here
148 | print "Time lookup failed!!"
149 |
150 | class PyApplet():
151 | """A gnome-panel applet that alerts a user if the International Space Station is overhead"""
152 |
153 | alarm = {}
154 | ha = HeavensAbove(45.47361, -122.64931, 100, "PST")
155 | lamp = lamp()
156 | iss_blank = gtk.image_new_from_file("/usr/share/pixmaps/iss_blank.png")
157 | iss_pass = gtk.image_new_from_file("/usr/share/pixmaps/iss_pass.png")
158 |
159 | def __init__(self, applet):
160 | self.applet=applet
161 |
162 | # Button
163 | self.button = gtk.Button()
164 | self.button.set_image(self.iss_blank)
165 | self.button.connect('button-press-event', self.showMenu, self.applet)
166 | self.button.set_relief(gtk.RELIEF_NONE)
167 | self.applet.add(self.button)
168 |
169 | # Background
170 | self.applet.set_background_widget(self.applet)
171 |
172 | # We've now packed the UI, so show it
173 | self.applet.show_all()
174 |
175 | # Get the next pass
176 | self.ha.get_next_pass()
177 |
178 | # Next event
179 | self.alarm = gobject.timeout_add_seconds(self.ha.seconds_to_next_pass, self.pass_begin_alarm)
180 |
181 | def pass_begin_alarm(self):
182 | """Triggered when the begin pass alarm goes off"""
183 | # Turn on lights
184 | print "begin pass"
185 | self.begin_pass()
186 |
187 | # Next Event
188 | gobject.source_remove(self.alarm)
189 | self.alarm = gobject.timeout_add_seconds(self.ha.pass_length, self.pass_end_alarm)
190 | return True
191 |
192 | def pass_end_alarm(self):
193 | """Triggered when the end pass alarm goes off"""
194 | # Turn lights off
195 | print "end pass"
196 | self.end_pass()
197 |
198 | # Get the next pass
199 | self.ha.get_next_pass()
200 |
201 | gobject.source_remove(self.alarm)
202 | self.alarm = gobject.timeout_add_seconds(self.ha.seconds_to_next_pass, self.pass_begin_alarm)
203 | return True
204 |
205 | def begin_pass(self):
206 | self.button.set_image(self.iss_pass)
207 | self.lamp.lights_on()
208 |
209 | def end_pass(self):
210 | self.button.set_image(self.iss_blank)
211 | self.lamp.lights_off()
212 |
213 | def showMenu(self, button, event, applet):
214 | if event.type == gtk.gdk.BUTTON_PRESS and event.button == 3:
215 | button.emit_stop_by_name("button_press_event")
216 | self.create_menu(applet)
217 |
218 | def create_menu(self, applet):
219 | next_pass_string = self.ha.next_pass.strftime("%a %H:%M:%S")
220 | time_to_pass = self.ha.next_pass - datetime.datetime.today()
221 | time_to_pass_days = time_to_pass.days
222 | time_to_pass_minutes = int(time_to_pass.seconds / 60.0)
223 |
224 | if time_to_pass_days < 0:
225 | next_pass_string = "Not sure"
226 | else:
227 | next_pass_string = next_pass_string + " - %d days, %d minutes" % (time_to_pass_days, time_to_pass_minutes)
228 |
229 | propxml="""
230 |
231 |
232 |
233 |
234 |
235 | """ % (next_pass_string)
236 |
237 | verbs = [("next_pass", self.showAboutDialog), ("update", self.update_pass_data), ("test_lamp", self.test_lamp), ("about", self.showAboutDialog)]
238 |
239 | applet.setup_menu(propxml, verbs, None)
240 |
241 | def test_lamp(self, widget, menuname):
242 | self.lamp.lights_on()
243 | # short delay
244 | for i in range(1000):
245 | k = i + 1
246 | self.lamp.lights_off()
247 |
248 | def update_pass_data(self, widget, menuname):
249 | self.ha.get_next_pass()
250 | signal.alarm(0)
251 | signal.signal(signal.SIGALRM, self.pass_begin_alarm)
252 | signal.alarm(self.ha.seconds_to_next_pass)
253 |
254 | def showAboutDialog(self, widget, menuname):
255 | #print menuname
256 | pass
257 |
258 | def class_factory(applet, iid):
259 | PyApplet(applet)
260 | return True
261 |
262 | if len(sys.argv) == 2 and sys.argv[1] == "-debug":
263 | print "running in window"
264 | main_window = gtk.Window(gtk.WINDOW_TOPLEVEL)
265 | main_window.set_title("Python Applet")
266 | main_window.connect("destroy", gtk.main_quit)
267 | app = gnomeapplet.Applet()
268 | class_factory(app, None)
269 | app.reparent(main_window)
270 | main_window.show_all()
271 | gtk.main()
272 | sys.exit()
273 |
274 | gnomeapplet.bonobo_factory("OAFIID:ISS_Gnome_Panel_Factory",
275 | gnomeapplet.Applet.__gtype__,
276 | "hello", "0", class_factory)
277 |
--------------------------------------------------------------------------------
/pixmaps/iss_pass.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
258 |
--------------------------------------------------------------------------------
/pixmaps/iss_blank.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
270 |
--------------------------------------------------------------------------------
/pixmaps/iss_logo.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
306 |
--------------------------------------------------------------------------------
|