Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def convertMoonPhase(percentIlluminated,moonState): # convert percentIlluminated to the moonPhase string (have to know if waxing or waning already. This is stored in moonState)
- if percentIlluminated == 0:
- moonPhase = 'New Moon'
- moonState = False # set moonState to false (new moon)
- moonStateBackup = open(logDirectory + "/moonStateBackup.txt", "w") # open lastPullBackup.txt for writeing
- pickle.dump(moonState, moonStateBackup) # write the new last poll time to the log file
- moonStateBackup.close()
- elif percentIlluminated == 100:
- moonPhase = 'Full Moon'
- moonState = True # set moonState to True (full moon)
- moonStateBackup = open(logDirectory + "/moonStateBackup.txt", "w") # open lastPullBackup.txt for writeing
- pickle.dump(moonState, moonStateBackup) # write the new last poll time to the log file
- moonStateBackup.close()
- elif moonState == False:
- if percentIlluminated < 50:
- moonPhase = 'Waxing Crescent'
- elif percentIlluminated == 50:
- moonPhase = 'First Quarter'
- elif percentIlluminated < 100:
- moonPhase = 'Waxing Gibbous'
- #endif
- elif moonState == True:
- if percentIlluminated < 50:
- moonPhase = 'Waning Crescent'
- elif percentIlluminated == 50:
- moonPhase = 'Last Quarter'
- elif percentIlluminated < 100:
- moonPhase = 'Waning Gibbous'
- #endif
- else: # prevents crash if non-vaild data is given as input
- moonPhase = "N/A"
- #endif
- return [moonPhase, moonState]
- #enddef
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement