daily pastebin goal
50%
SHARE
TWEET

WU API Moonphase Conversion Example

arclance Aug 3rd, 2012 9 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def convertMoonPhase(percentIlluminated,moonState): # convert percentIlluminated to the moonPhase string (have to know if waxing or waning already. This is stored in moonState)
  2.         if percentIlluminated == 0:
  3.                 moonPhase = 'New Moon'
  4.                 moonState = False # set moonState to false (new moon)
  5.                 moonStateBackup = open(logDirectory + "/moonStateBackup.txt", "w") # open lastPullBackup.txt for writeing
  6.                 pickle.dump(moonState, moonStateBackup) # write the new last poll time to the log file
  7.                 moonStateBackup.close()
  8.         elif percentIlluminated == 100:
  9.                 moonPhase = 'Full Moon'
  10.                 moonState = True # set moonState to True (full moon)
  11.                 moonStateBackup = open(logDirectory + "/moonStateBackup.txt", "w") # open lastPullBackup.txt for writeing
  12.                 pickle.dump(moonState, moonStateBackup) # write the new last poll time to the log file
  13.                 moonStateBackup.close()
  14.         elif moonState == False:
  15.                 if percentIlluminated < 50:
  16.                         moonPhase = 'Waxing Crescent'
  17.                 elif percentIlluminated == 50:
  18.                         moonPhase = 'First Quarter'
  19.                 elif percentIlluminated < 100:
  20.                         moonPhase = 'Waxing Gibbous'
  21.                 #endif
  22.         elif moonState == True:
  23.                 if percentIlluminated < 50:
  24.                         moonPhase = 'Waning Crescent'
  25.                 elif percentIlluminated == 50:
  26.                         moonPhase = 'Last Quarter'
  27.                 elif percentIlluminated < 100:
  28.                         moonPhase = 'Waning Gibbous'
  29.                 #endif
  30.         else: # prevents crash if non-vaild data is given as input
  31.                 moonPhase = "N/A"
  32.         #endif
  33.         return [moonPhase, moonState]
  34. #enddef
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top