Exemple #1
0
def get_phase_name(location: Optional[ephem.Observer] = None, wiggle_room: float = 1.5) -> str:
    """Return name of the phase of the moon."""
    if location:
        date = location.date
    else:
        date = ephem.now()
    if abs(ephem.next_first_quarter_moon(date) - date) < wiggle_room or \
            abs(ephem.previous_first_quarter_moon(date) - date) < wiggle_room:
        return 'first quarter moon'
    elif abs(ephem.next_full_moon(date) - date) < wiggle_room or \
            abs(ephem.previous_full_moon(date) - date) < wiggle_room:
        return 'full moon'
    elif abs(ephem.next_last_quarter_moon(date) - date) < wiggle_room or \
            abs(ephem.previous_last_quarter_moon(date) - date) < wiggle_room:
        return 'last quarter moon'
    elif abs(ephem.next_new_moon(date) - date) < wiggle_room or \
            abs(ephem.previous_new_moon(date) - date) < wiggle_room:
        return 'new moon'
    elif ephem.next_first_quarter_moon(date) - ephem.previous_new_moon(date) < 29:
        return 'waxing crescent'
    elif ephem.next_full_moon(date) - ephem.previous_first_quarter_moon(date) < 29:
        return 'waxing gibbous'
    elif ephem.next_last_quarter_moon(date) - ephem.previous_full_moon(date) < 29:
        return 'waning gibbous'
    elif ephem.next_new_moon(date) - ephem.previous_last_quarter_moon(date) < 29:
        return 'waning crescent'
    return ''
def get_moon_phase(observer):
    target_date_utc = observer.date
    target_date_local = ephem.localtime(target_date_utc).date()
    next_full = ephem.localtime(ephem.next_full_moon(target_date_utc)).date()
    next_new = ephem.localtime(ephem.next_new_moon(target_date_utc)).date()
    next_last_quarter = ephem.localtime(
        ephem.next_last_quarter_moon(target_date_utc)).date()
    next_first_quarter = ephem.localtime(
        ephem.next_first_quarter_moon(target_date_utc)).date()
    previous_full = ephem.localtime(
        ephem.previous_full_moon(target_date_utc)).date()
    previous_new = ephem.localtime(
        ephem.previous_new_moon(target_date_utc)).date()
    previous_last_quarter = ephem.localtime(
        ephem.previous_last_quarter_moon(target_date_utc)).date()
    previous_first_quarter = ephem.localtime(
        ephem.previous_first_quarter_moon(target_date_utc)).date()

    if target_date_local in (next_full, previous_full):
        return 'Full'
    elif target_date_local in (next_new, previous_new):
        return 'New'
    elif target_date_local in (next_first_quarter, previous_first_quarter):
        return 'First Quarter'
    elif target_date_local in (next_last_quarter, previous_last_quarter):
        return 'Last Quarter'
    elif previous_new < next_first_quarter < next_full < next_last_quarter < next_new:
        return 'Waxing Crescent'
    elif previous_first_quarter < next_full < next_last_quarter < next_new < next_first_quarter:
        return 'Waxing Gibbous'
    elif previous_full < next_last_quarter < next_new < next_first_quarter < next_full:
        return 'Waning Gibbous'
    elif previous_last_quarter < next_new < next_first_quarter < next_full < next_last_quarter:
        return 'Waning Crescent'
Exemple #3
0
 def __init__(self):
     self.__logger = logging.getLogger(self.__class__.__name__)
     #find current moon phase
     now = ephem.now()
     new_date = ephem.next_new_moon(now)
     first_quarter_date = ephem.next_first_quarter_moon(now)
     full_date = ephem.next_full_moon(now)
     last_quarter_date = ephem.next_last_quarter_moon(now)
     delta = float('inf')
     if new_date - now < delta:
         delta = new_date - now
         self.__current_phase = MoonUpdater.LAST_QUARTER_MOON
         self.__current_phase_date = ephem.previous_last_quarter_moon(
             now).datetime()
     if first_quarter_date - now < delta:
         delta = first_quarter_date - now
         self.__current_phase = MoonUpdater.NEW_MOON
         self.__current_phase_date = ephem.previous_new_moon(now).datetime()
     if full_date - now < delta:
         delta = full_date - now
         self.__current_phase = MoonUpdater.FIRST_QUARTER_MOON
         self.__current_phase_date = ephem.previous_first_quarter_moon(
             now).datetime()
     if last_quarter_date - now < delta:
         delta = last_quarter_date - now
         self.__current_phase = MoonUpdater.FULL_MOON
         self.__current_phase_date = ephem.previous_full_moon(
             now).datetime()
def make_moon_stuff(outer_canv, inner_canv, begin_day, no_days, chart,
        obs):
    small_moon_rad = 0.12
    large_moon_rad = 0.16
    moon = ephem.Moon()
    moon2 = ephem.Moon()
    for doy in range(no_days) :
        obs.date = begin_day + doy
        mpc = obs.date + 0.5 # moon phase check
        moon_set = obs.next_setting(moon)
        moon2.compute(moon_set)
        X = moon2.moon_phase
        # Waxing moon (moonsets)
        x, y = to_chart_coord(moon_set, chart)
        if (fabs(ephem.next_full_moon(mpc) - mpc) < 0.5 or
            fabs(ephem.previous_full_moon(mpc) - mpc) < 0.5) :
            # full moon
            outer_canv.stroke(path.circle(x,y,large_moon_rad),[mooncolorlight,pyx.deco.filled([mooncolorlight])])
        elif ((X < 0.55 and X > 0.45) or 
              fabs(ephem.next_first_quarter_moon(mpc) - mpc) < 0.5 or
              fabs(ephem.previous_first_quarter_moon(mpc) - mpc) < 0.5) :
            # first quarter
            outer_canv.stroke(first_quarter_moon(large_moon_rad, x,y),[mooncolordark,pyx.deco.filled([mooncolordark])])
        elif (fabs(ephem.next_new_moon(mpc) - mpc) < 0.5 or
              fabs(ephem.previous_new_moon(mpc) - mpc) < 0.5):
            # new moon
            outer_canv.stroke(path.circle(x,y,large_moon_rad),[mooncolorlight,pyx.deco.filled([mooncolordark])])
        else :
            inner_canv.fill(waxing_moon(X, small_moon_rad, x, y),
                    [style.linejoin.bevel,mooncolordark])
        # Waning moon (moonrises)
        moon_rise = obs.next_rising(moon)
        moon2.compute(moon_rise)
        X = moon2.moon_phase
        x, y = to_chart_coord(moon_rise, chart)
        if (fabs(ephem.next_full_moon(mpc) - mpc) < 0.5 or
            fabs(ephem.previous_full_moon(mpc) - mpc) < 0.5) :
            # full moon
            outer_canv.stroke(path.circle(x,y,large_moon_rad),[mooncolorlight,pyx.deco.filled([mooncolorlight])])
        elif ((X < 0.55 and X > 0.45) or 
              fabs(ephem.next_last_quarter_moon(mpc) - mpc) < 0.5 or
              fabs(ephem.previous_last_quarter_moon(mpc) - mpc) < 0.5) :
            # last quarter
            outer_canv.stroke(last_quarter_moon(large_moon_rad, x,y),[mooncolorlight,pyx.deco.filled([mooncolorlight])])
        elif (fabs(ephem.next_new_moon(mpc) - mpc) < 0.5 or
              fabs(ephem.previous_new_moon(mpc) - mpc) < 0.5):
            # new moon
            outer_canv.stroke(path.circle(x,y,large_moon_rad),[mooncolorlight,pyx.deco.filled([mooncolordark])])
        else :
            inner_canv.fill(waning_moon(X, small_moon_rad, x, y),
                    [style.linejoin.bevel,mooncolorlight])
Exemple #5
0
def new_moon(bot, update):

    dfu = update.message.text

    moon = {
        "Предыдущий цикл": {
            "Последняя четверть луны": ephem.previous_last_quarter_moon(dfu),
            "Новолуние": ephem.previous_new_moon(dfu),
            "Первая четверть луны": ephem.previous_first_quarter_moon(dfu),
            "Полнолуние": ephem.previous_full_moon(dfu),
        },
        "Следующий цикл": {
            "Последняя четверть луны": ephem.next_last_quarter_moon(dfu),
            "Новолуние": ephem.next_new_moon(dfu),
            "Первая четверть луны": ephem.next_first_quarter_moon(dfu),
            "Полнолуние": ephem.next_full_moon(dfu),
        }
    }

    for key in moon:
        bot.sendMessage(update.message.chat_id, text=key)
        for row_key in moon[key]:
            bot.sendMessage(update.message.chat_id,
                            text=(row_key, ":", moon[key][row_key]))
def main():

    sun = ephem.Sun()
    moon = ephem.Moon()

    # define observer
    home = ephem.Observer()
    home.date = ephem.date(datetime.utcnow())
    home.lat, home.lon = '50.46', '9.61'

    sun.compute(home)
    sunrise, sunset = (home.next_rising(sun),
                       home.next_setting(sun))
    moon.compute(home)
    moonrise, moonset = (home.next_rising(moon),
                       home.next_setting(moon))
    home.horizon = '-6'
    m6_start, m6_end = (home.next_rising(sun, use_center=True),
                        home.next_setting(sun, use_center=True))
    home.horizon = '-12'
    m12_start, m12_end = (home.next_rising(sun, use_center=True),
                          home.next_setting(sun, use_center=True))
    home.horizon = '-18'
    m18_start, m18_end = (home.next_rising(sun, use_center=True),
                          home.next_setting(sun, use_center=True))

    print home.date

    e = {}
    e[sunrise] =   " Sunrise:                      "
    e[sunset] =    " Sunset:                       "
    e[moonrise] =  " Moonrise:                     "
    e[moonset] =   " Moonset:                      "
    e[m6_start] =  " Civil twilight starts:        "
    e[m6_end] =    " Civil twilight ends:          "
    e[m12_start] = " Nautical twilight starts:     "
    e[m12_end] =   " Nautical twilight ends:       "
    e[m18_start] = " Astronomical twilight starts: "
    e[m18_end] =   " Astronomical twilight ends:   "

    for time in sorted(e.keys()):
        print e[time], ephem.localtime(time).ctime()

    # Here start the moon specific data

    print " ---"
    print " Moon phase: %d%% " % moon.phase

    e = {}
    e1 = ephem.previous_new_moon(home.date)
    e[e1] = " Previous new moon:            "
    e1 = ephem.previous_first_quarter_moon(home.date)
    e[e1] = " Previous first quarter moon:  "
    e1 = ephem.previous_full_moon(home.date)
    e[e1] = " Previous full moon:           "
    e1 = ephem.previous_last_quarter_moon(home.date)
    e[e1] = " Previous last quarter moon:   "

    e1 = ephem.next_new_moon(home.date)
    e[e1] = " Next new moon:                "
    e1 = ephem.next_first_quarter_moon(home.date)
    e[e1] = " Next first quarter moon:      "
    e1 = ephem.next_full_moon(home.date)
    e[e1] = " Next full moon:               "
    e1 = ephem.next_last_quarter_moon(home.date)
    e[e1] = " Next last quarter moon:       "

    for time in sorted(e.keys()):
        print e[time], ephem.localtime(time).ctime()
Exemple #7
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from datetime import datetime
import ephem

now = datetime.now()

#Past Moon phases
d5 = ephem.previous_new_moon(now)
d6 = ephem.previous_first_quarter_moon(now)
d7 = ephem.previous_full_moon(now)
d8 = ephem.previous_last_quarter_moon(now)
print
print (d5), "	| Previous new Moon"
print (d6), "	| Previous quarter Moon"
print (d7), "	| Previous full Moon"
print (d8), "	| Previous last quarter Moon"
print

#Next Moon phases
d1 = ephem.next_full_moon(now)
d2 = ephem.next_new_moon(now)
d3 = ephem.next_first_quarter_moon(now)
d4 = ephem.next_last_quarter_moon(now)
print (d2), "	| Next new Moon"
print (d3), "	| Next quarter Moon"
print (d1), "	| Next full Moon"
print (d4), "	| Next last quarter Moon"
print

m=ephem.Moon(now)
data['sun']['altitude'] = sun.alt
data['sun']['azimuth'] = sun.az

# MOON DATA
moonrise = observer.previous_rising(ephem.Moon())
moonnoon    = observer.next_transit   (ephem.Moon())
moonset  = observer.next_setting   (ephem.Moon())
data['moon']['rise'] = calendar.timegm(moonrise.datetime().utctimetuple())
data['moon']['noon']    = calendar.timegm(moonnoon.datetime().utctimetuple())
data['moon']['set']  = calendar.timegm(moonset.datetime().utctimetuple())
data['moon']['radius'] = ephem.moon_radius

previous_new_moon = ephem.previous_new_moon(time)
next_new_moon = ephem.next_new_moon(time)
previous_first_quarter_moon = ephem.previous_first_quarter_moon(time)
next_first_quarter_moon = ephem.next_first_quarter_moon(time)
previous_full_moon = ephem.previous_full_moon(time)
next_full_moon = ephem.next_full_moon(time)
previous_last_quarter_moon = ephem.previous_last_quarter_moon(time)
next_last_quarter_moon = ephem.next_last_quarter_moon(time)

data['moon']['previous_new_moon'] = calendar.timegm(previous_new_moon.datetime().utctimetuple())
data['moon']['next_new_moon'] = calendar.timegm(next_new_moon.datetime().utctimetuple())
data['moon']['previous_first_quarter_moon'] = calendar.timegm(previous_first_quarter_moon.datetime().utctimetuple())
data['moon']['next_first_quarter_moon'] = calendar.timegm(next_first_quarter_moon.datetime().utctimetuple())
data['moon']['previous_full_moon'] = calendar.timegm(previous_full_moon.datetime().utctimetuple())
data['moon']['next_full_moon'] = calendar.timegm(next_full_moon.datetime().utctimetuple())
data['moon']['previous_last_quarter_moon'] = calendar.timegm(previous_last_quarter_moon.datetime().utctimetuple())
data['moon']['next_last_quarter_moon'] = calendar.timegm(next_last_quarter_moon.datetime().utctimetuple())
    def onHeartbeat(self):
        Domoticz.Debug("onHeartbeat")
        self.__runAgain -= 1
        if self.__runAgain <= 0:
            self.__runAgain = self.__HEARTBEATS2MIN * self.__MINUTES
            #
            utc_now = datetime.datetime.utcnow()
            target_date = datetime.datetime.now().date()
            #
            self.__observer.date = utc_now
            self.__sun.compute(self.__observer)
            #
            ################################################################################
            # Sun data
            ################################################################################
            #
            # -------------------------------------------------------------------------------
            # Sun altitude
            # -------------------------------------------------------------------------------
            value = round(deg(self.__sun.alt), 2)
            UpdateDevice(unit.SUN_ALT, int(value), str(value))
            #
            # -------------------------------------------------------------------------------
            # Sun azimuth
            # -------------------------------------------------------------------------------
            value = round(deg(self.__sun.az), 2)
            UpdateDevice(unit.SUN_AZ, int(value), str(value))
            #
            # -------------------------------------------------------------------------------
            # Sun distance
            # -------------------------------------------------------------------------------
            value = round(self.__sun.earth_distance * ephem.meters_per_au / 1000)
            UpdateDevice(unit.SUN_DIST, int(value), str(value))
            #
            # -------------------------------------------------------------------------------
            # Sun transit
            # -------------------------------------------------------------------------------
            value = (
                ephem.localtime(self.__observer.next_transit(self.__sun)) + self.__SEC30
            )
            UpdateDevice(
                unit.SUN_TRANSIT, 0, "{}".format(value.strftime(self.__DT_FORMAT))
            )
            #
            # -------------------------------------------------------------------------------
            # Sun rise & set today
            # -------------------------------------------------------------------------------
            self.__observer.date = target_date
            self.__sun.compute(self.__observer)
            i = 0
            for t in self.__TWILIGHTS:
                # Zero the horizon
                self.__observer.horizon = t[0]
                try:
                    next_rising = (
                        ephem.localtime(
                            self.__observer.next_rising(self.__sun, use_center=t[1])
                        )
                        + self.__SEC30
                    )
                    UpdateDevice(
                        unit.SUN_RISE + i,
                        0,
                        "{}".format(next_rising.strftime(self.__DT_FORMAT)),
                    )
                except:
                    UpdateDevice(
                        unit.SUN_RISE + i,
                        0,
                        "{}".format("No time available"),
                    )
                try:
                    next_setting = (
                        ephem.localtime(
                            self.__observer.next_setting(self.__sun, use_center=t[1])
                        )
                        + self.__SEC30
                    )
                    UpdateDevice(
                        unit.SUN_SET + i,
                        0,
                        "{}".format(next_setting.strftime(self.__DT_FORMAT)),
                    )
                except:
                    UpdateDevice(
                        unit.SUN_RISE + i,
                        0,
                        "{}".format("No time available"),
                    )
                if i == 0:
                    value = (next_setting - next_rising).total_seconds()
                    hh = divmod(value, 3600)
                    mm = divmod(hh[1], 60)
                    min = int(divmod(value, 60)[0])
                    UpdateDevice(
                        unit.DAY_LENGTH_M,
                        min,
                        "{}".format(min),
                    )
                    UpdateDevice(
                        unit.DAY_LENGTH_T,
                        0,
                        "{:02}:{:02}".format(int(hh[0]), int(mm[0])),
                    )

                i += 1
            #
            # Reset horizon for further calculations
            self.__observer.horizon = "0"
            #
            ################################################################################
            # Moon data
            ################################################################################
            #
            self.__observer.date = utc_now
            self.__moon.compute(self.__observer)
            #
            # -------------------------------------------------------------------------------
            # Moon rise
            # -------------------------------------------------------------------------------
            value = (
                ephem.localtime(self.__observer.next_rising(self.__moon)) + self.__SEC30
            )
            UpdateDevice(
                unit.MOON_RISE, 0, "{}".format(value.strftime(self.__DT_FORMAT))
            )
            #
            # -------------------------------------------------------------------------------
            # Moon set
            # -------------------------------------------------------------------------------
            value = (
                ephem.localtime(self.__observer.next_setting(self.__moon))
                + self.__SEC30
            )
            UpdateDevice(
                unit.MOON_SET, 0, "{}".format(value.strftime(self.__DT_FORMAT))
            )
            #
            # -------------------------------------------------------------------------------
            # Moon altitude
            # -------------------------------------------------------------------------------
            self.__moon.compute(self.__observer)
            #
            value = round(deg(self.__moon.alt), 2)
            UpdateDevice(unit.MOON_ALT, int(value), str(value))
            #
            # -------------------------------------------------------------------------------
            # Moon azimuth
            # -------------------------------------------------------------------------------
            value = round(deg(self.__moon.az), 2)
            UpdateDevice(unit.MOON_AZ, int(value), str(value))
            #
            # -------------------------------------------------------------------------------
            # Moon distance
            # -------------------------------------------------------------------------------
            value = round(self.__moon.earth_distance * ephem.meters_per_au / 1000)
            UpdateDevice(unit.MOON_DIST, int(value), str(value))
            #
            # -------------------------------------------------------------------------------
            # Next new moon
            # -------------------------------------------------------------------------------
            next_new = ephem.localtime(ephem.next_new_moon(utc_now))
            value = next_new + self.__SEC30
            UpdateDevice(
                unit.MOON_NEXT_NEW, 0, "{}".format(value.strftime(self.__DT_FORMAT))
            )
            #
            # -------------------------------------------------------------------------------
            # Next first quarter
            # -------------------------------------------------------------------------------
            next_first_quarter = ephem.localtime(ephem.next_first_quarter_moon(utc_now))
            value = next_first_quarter + self.__SEC30
            UpdateDevice(
                unit.MOON_NEXT_FIRST_QUARTER,
                0,
                "{}".format(value.strftime(self.__DT_FORMAT)),
            )
            #
            # -------------------------------------------------------------------------------
            # Next full moon
            # -------------------------------------------------------------------------------
            next_full = ephem.localtime(ephem.next_full_moon(utc_now))
            value = next_full + self.__SEC30
            UpdateDevice(
                unit.MOON_NEXT_FULL,
                0,
                "{}".format(value.strftime(self.__DT_FORMAT)),
            )
            #
            # -------------------------------------------------------------------------------
            # Next last quarter
            # -------------------------------------------------------------------------------
            next_last_quarter = ephem.localtime(ephem.next_last_quarter_moon(utc_now))
            value = next_last_quarter + self.__SEC30
            UpdateDevice(
                unit.MOON_NEXT_LAST_QUARTER,
                0,
                "{}".format(value.strftime(self.__DT_FORMAT)),
            )
            #
            # -------------------------------------------------------------------------------
            # Moon phase
            # -------------------------------------------------------------------------------
            next_full = next_full.date()
            next_new = next_new.date()
            next_last_quarter = next_last_quarter.date()
            next_first_quarter = next_first_quarter.date()
            previous_full = ephem.localtime(ephem.previous_full_moon(utc_now)).date()
            previous_new = ephem.localtime(ephem.previous_new_moon(utc_now)).date()
            previous_last_quarter = ephem.localtime(
                ephem.previous_last_quarter_moon(utc_now)
            ).date()
            previous_first_quarter = ephem.localtime(
                ephem.previous_first_quarter_moon(utc_now)
            ).date()
            #
            # Domoticz.Debug("target_date: {}".format(target_date))
            # Domoticz.Debug("next_full: {}".format(next_full))
            # Domoticz.Debug("next_new: {}".format(next_new))
            # Domoticz.Debug("next_last_quarter: {}".format(next_last_quarter))
            # Domoticz.Debug("next_first_quarter: {}".format(next_first_quarter))
            # Domoticz.Debug("previous_full: {}".format(previous_full))
            # Domoticz.Debug("previous_new: {}".format(previous_new))
            # Domoticz.Debug("previous_last_quarter: {}".format(previous_last_quarter))
            # Domoticz.Debug("previous_first_quarter: {}".format(previous_first_quarter))

            if target_date in (next_new, previous_new):
                phase = 0
            elif target_date in (next_first_quarter, previous_first_quarter):
                phase = 2
            elif target_date in (next_full, previous_full):
                phase = 4
            elif target_date in (next_last_quarter, previous_last_quarter):
                phase = 6
            elif (
                previous_new
                < next_first_quarter
                < next_full
                < next_last_quarter
                < next_new
            ):
                phase = 1
            elif (
                previous_first_quarter
                < next_full
                < next_last_quarter
                < next_new
                < next_first_quarter
            ):
                phase = 3
            elif (
                previous_full
                < next_last_quarter
                < next_new
                < next_first_quarter
                < next_full
            ):
                phase = 5
            elif (
                previous_last_quarter
                < next_new
                < next_first_quarter
                < next_full
                < next_last_quarter
            ):
                phase = 7
            else:
                phase = 4
            UpdateDevice(unit.MOON_PHASE, 0, self.__MOON_PHASE_DESCRIPTIONS[phase])
            UpdateDeviceImage(
                unit.MOON_PHASE, images.PREFIX_IMAGE + images.PREFIX_PHASE + str(phase)
            )
            #
            self.__moon.compute(self.__observer)
            #
            # -------------------------------------------------------------------------------
            # Moon illumination
            # -------------------------------------------------------------------------------
            value = round(deg(self.__moon.moon_phase), 2)
            UpdateDevice(unit.MOON_ILLUMINATION, int(value), str(value))
            UpdateDeviceImage(
                unit.MOON_ILLUMINATION,
                images.PREFIX_IMAGE + images.PREFIX_PHASE + str(phase),
            )
            #
        else:
            Domoticz.Debug(
                "onHeartbeat called, run again in {} heartbeats.".format(
                    self.__runAgain
                )
            )
Exemple #10
0
sunset  = observer.next_setting   (ephem.Sun()) #Sunset

data['sunrise'] = str(ephem.localtime(sunrise))
data['noon']    = str(ephem.localtime(noon))
data['sunset']  = str(ephem.localtime(sunset))

# observer.horizon = '-6' # civil twilight
# civilian_twilight_start = observer.previous_rising(ephem.Sun())
# civilian_twilight_end = observer.next_setting(ephem.Sun())

# observer.horizon = '-12' # nautical twilight
# nautical_twilight_start = observer.previous_rising(ephem.Sun())
# nautical_twilight_end = observer.next_setting(ephem.Sun())

# observer.horizon = '-18' # astronomical twilight
# astronomical_twilight_start = observer.previous_rising(ephem.Sun())
# astronomical_twilight_end = observer.next_setting(ephem.Sun())

data['moon'] = {}
data['moon']['radius'] = ephem.moon_radius
data['moon']['previous_new_moon'] = str(ephem.localtime(ephem.previous_new_moon(time)))
data['moon']['next_new_moon'] = str(ephem.localtime(ephem.next_new_moon(time)))
data['moon']['previous_first_quarter_moon'] = str(ephem.localtime(ephem.previous_first_quarter_moon(time)))
data['moon']['next_first_quarter_moon'] = str(ephem.localtime(ephem.next_first_quarter_moon(time)))
data['moon']['previous_full_moon'] = str(ephem.localtime(ephem.previous_full_moon(time)))
data['moon']['next_full_moon'] = str(ephem.localtime(ephem.next_full_moon(time)))
data['moon']['previous_last_quarter_moon'] = str(ephem.localtime(ephem.previous_last_quarter_moon(time)))
data['moon']['next_last_quarter_moon'] = str(ephem.localtime(ephem.next_last_quarter_moon(time)))

print json.dumps(data)
print "\n*** Lunar Phase information: ***"
prev_new = ephem.previous_new_moon(now)
next_new = ephem.next_new_moon(now)
next_first = ephem.next_first_quarter_moon(now)
next_full = ephem.next_full_moon(now)
next_last = ephem.next_last_quarter_moon(now)

phase = m.moon_phase
lunation = (now-prev_new)/(next_new-prev_new)
# Elaborate on most recent lunar phase

print "Current lunar illumination is {:0.1f}%, lunation is {:0.4f}".format(phase*100,lunation)
if lunation < 0.25:
    print "Was just New Moon at {} UT".format(fmt_date(ephem.previous_new_moon(now)))
elif lunation < 0.5:
    print "Was just First Quarter at {} UT".format(fmt_date(ephem.previous_first_quarter_moon(now)))
elif lunation < 0.75:
    print "Was just Full Moon at {} UT".format(fmt_date(ephem.previous_full_moon(now)))
else:
    print "Was just Last Quarter at {} UT".format(fmt_date(ephem.previous_last_quarter_moon(now)))

print "New Moon     : {} UT ({} Local time)".format(
    fmt_date(next_new),fmt_fulldatetime(ephem.localtime(next_new)))
print "First Quarter: {} UT ({} Local time)".format(
    fmt_date(next_first),fmt_fulldatetime(ephem.localtime(next_first)))
print "Full Moon    : {} UT ({} Local time)".format(
    fmt_date(next_full),fmt_fulldatetime(ephem.localtime(next_full)))
print "Last Quarter : {} UT ({} Local time)".format(
    fmt_date(next_last),fmt_fulldatetime(ephem.localtime(next_last)))

print "\n*** Planets ***"
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 13 14:07:43 2020
https://rhodesmill.org/pyephem/quick.html#phases-of-the-moon
@author: PC
"""

import ephem

d1 = ephem.next_full_moon('1984')
print(d1)
d2 = ephem.next_new_moon(d1)
print(d2)

print(ephem.previous_new_moon('2020'))
print(ephem.next_new_moon('2020'))

print(ephem.previous_first_quarter_moon('2020'))
print(ephem.next_first_quarter_moon('2020'))

print(ephem.previous_full_moon('2020'))
print(ephem.next_full_moon('2020'))

print(ephem.previous_last_quarter_moon('2020'))
print(ephem.next_last_quarter_moon('2020'))
import ephem

while True:
    user_answer = (input("date: ").lower())

    moon = {
        "Предыдущий цикл": {
            "Последняя четверть луны":
            ephem.previous_last_quarter_moon(user_answer),
            "Новолуние":
            ephem.previous_new_moon(user_answer),
            "Первая четверть луны":
            ephem.previous_first_quarter_moon(user_answer),
            "Полнолуние":
            ephem.previous_full_moon(user_answer),
        },
        "Следующий цикл": {
            "Последняя четверть луны":
            ephem.next_last_quarter_moon(user_answer),
            "Новолуние": ephem.next_new_moon(user_answer),
            "Первая четверть луны": ephem.next_first_quarter_moon(user_answer),
            "Полнолуние": ephem.next_full_moon(user_answer),
        }
    }

    for key in moon:
        print(key)
        for row_key in moon[key]:
            print(row_key, ":", moon[key][row_key])

    if user_answer == "exit":