From ae94ce35c7b2612fce8b6ab0006e4349611ef2eb Mon Sep 17 00:00:00 2001
From: Marius Gavrilescu <marius@ieval.ro>
Date: Tue, 27 Nov 2012 12:28:49 -0800
Subject: [PATCH] Show next lunar / solar eclipse type
---
moon.py | 26 ++++++++++++++++++--------
1 file changed, 18 insertions(+), 8 deletions(-)
diff --git a/moon.py b/moon.py
index 4ab5840..850343c 100755
a
|
b
|
except ImportError: |
55 | 55 | |
56 | 56 | IMAGE_SIZE = 726 |
57 | 57 | HALF_SIZE = IMAGE_SIZE / 2 |
| 58 | ECLIPSE_TYPES = { |
| 59 | 'T' : _('Total'), |
| 60 | 'A' : _('Annular'), |
| 61 | 'H' : _('Hybrid'), |
| 62 | 'P' : _('Partial'), |
| 63 | 't' : _('Total'), |
| 64 | 'p' : _('Partial'), |
| 65 | 'n' : _('Penumbral') |
| 66 | } |
58 | 67 | |
59 | 68 | # TRANS: Date format for next full/new moon and next solar/lunar eclipse |
60 | 69 | LOCALE_DATE_FORMAT = _("%c") |
… |
… |
class MoonActivity(activity.Activity): |
289 | 298 | information_string = _(u"Selenographic Terminator Longitude:\n%(deg).1f\u00b0%(westOrEast)s (%(riseOrSet)s)\n\n") % {'deg':self.data_model.selenographic_deg, 'westOrEast':self.data_model.west_or_east, 'riseOrSet':self.data_model.rise_or_set} |
290 | 299 | information_string += _("Next Full Moon:\n%(date)s in %(days).0f days\n\n") % {'date':time.strftime(LOCALE_DATE_FORMAT, time.localtime(self.data_model.next_full_moon_date)), 'days':self.data_model.days_until_full_moon} |
291 | 300 | information_string += _("Next New Moon:\n%(date)s in %(days).0f days\n\n") % {'date':time.strftime(LOCALE_DATE_FORMAT, time.localtime(self.data_model.next_new_moon_date)), 'days':self.data_model.days_until_new_moon} |
292 | | information_string += _("Next Lunar eclipse:\n%(date)s in %(days).0f days\n\n") % {'date':time.strftime(LOCALE_DATE_FORMAT, time.localtime(self.data_model.next_lunar_eclipse_date)), 'days':self.data_model.days_until_lunar_eclipse} |
293 | | information_string += _("Next Solar eclipse:\n%(date)s in %(days).0f days\n\n")[:-2] % {'date':time.strftime(LOCALE_DATE_FORMAT, time.localtime(self.data_model.next_solar_eclipse_date)), 'days':self.data_model.days_until_solar_eclipse} |
| 301 | information_string += _("Next [ %(eclipse_type)s ] Lunar eclipse:\n%(date)s in %(days).0f days\n\n") % {'date':time.strftime(LOCALE_DATE_FORMAT, time.localtime(self.data_model.next_lunar_eclipse_date)), 'days':self.data_model.days_until_lunar_eclipse, 'eclipse_type':ECLIPSE_TYPES[self.data_model.next_lunar_eclipse_type]} |
| 302 | information_string += _("Next [ %(eclipse_type)s ] Solar eclipse:\n%(date)s in %(days).0f days\n\n")[:-2] % {'date':time.strftime(LOCALE_DATE_FORMAT, time.localtime(self.data_model.next_solar_eclipse_date)), 'days':self.data_model.days_until_solar_eclipse, 'eclipse_type':ECLIPSE_TYPES[self.data_model.next_solar_eclipse_type]} |
294 | 303 | self.info2.set_markup(information_string) |
295 | 304 | |
296 | 305 | # Calculate time to next minute cusp and set a new timer |
… |
… |
class DataModel(): |
532 | 541 | self.next_full_moon_date = the_date + next_full_moon_sec - self.correct_for_tz_and_dst(the_date + next_full_moon_sec) |
533 | 542 | |
534 | 543 | # Eclipse information |
535 | | self.next_lunar_eclipse_sec = self.next_lunar_eclipse_sec_at_time(the_date) |
536 | | self.next_solar_eclipse_sec = self.next_solar_eclipse_sec_at_time(the_date) |
537 | | self.last_lunar_eclipse_sec = self.last_lunar_eclipse_sec_at_time(the_date) |
| 544 | self.next_lunar_eclipse_sec, self.next_lunar_eclipse_type = self.next_lunar_eclipse_sec_at_time(the_date) |
| 545 | self.next_solar_eclipse_sec, self.next_solar_eclipse_type = self.next_solar_eclipse_sec_at_time(the_date) |
| 546 | self.last_lunar_eclipse_sec, self.last_lunar_eclipse_type = self.last_lunar_eclipse_sec_at_time(the_date) |
538 | 547 | self.days_until_lunar_eclipse = self.next_lunar_eclipse_sec / SECONDS_PER_DAY |
539 | 548 | self.next_lunar_eclipse_date = the_date + self.next_lunar_eclipse_sec - self.correct_for_tz_and_dst(the_date + self.next_lunar_eclipse_sec) |
540 | 549 | self.days_until_solar_eclipse = self.next_solar_eclipse_sec / SECONDS_PER_DAY |
… |
… |
class DataModel(): |
679 | 688 | if date_string[-1:] != "_": |
680 | 689 | next = time.mktime(time.strptime(date_string[:-1], self.date_format)) |
681 | 690 | if next >= now: |
682 | | return next - now |
| 691 | return next - now, date_string[-1:] |
683 | 692 | return -1 |
684 | 693 | |
685 | 694 | def last_lunar_eclipse_sec_at_time(self, now): |
… |
… |
class DataModel(): |
688 | 697 | last = -1 |
689 | 698 | for date_string in self.full_moon_array: |
690 | 699 | if date_string[-1:] != "_": |
| 700 | eclipse_type = date_string[-1:] |
691 | 701 | then = time.mktime(time.strptime(date_string[:-1], self.date_format)) |
692 | 702 | if then >= now: |
693 | 703 | break |
… |
… |
class DataModel(): |
695 | 705 | if last == -1: |
696 | 706 | return -1 |
697 | 707 | else: |
698 | | return now - last |
| 708 | return now - last, type |
699 | 709 | |
700 | 710 | def next_solar_eclipse_sec_at_time(self, now): |
701 | 711 | """Return (positive) seconds to the next Solar eclipe or -1. |
… |
… |
class DataModel(): |
704 | 714 | if date_string[-1:] != "_": |
705 | 715 | next = time.mktime(time.strptime(date_string[:-1], self.date_format)) |
706 | 716 | if next >= now: |
707 | | return next - now |
| 717 | return next - now, date_string[-1:] |
708 | 718 | return -1 |