Moon condition

  • 2
  • Question
  • Updated 6 years ago
how to get Moon condition (like Waxing Gibbous ) its showing in site but how to get it in api
Photo of appdemo

appdemo

  • 15 Posts
  • 0 Reply Likes

Posted 6 years ago

  • 2
Photo of Brendan Hayes

Brendan Hayes, Official Rep

  • 962 Posts
  • 122 Reply Likes
We'll be adding moon phases in the next round of development.
Photo of arclance

arclance

  • 29 Posts
  • 0 Reply Likes
Any idea when that will be?
Photo of arclance

arclance

  • 29 Posts
  • 0 Reply Likes
I calculate the moon condition like this using python.

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
Photo of appdemo

appdemo

  • 15 Posts
  • 0 Reply Likes
how??
Photo of appdemo

appdemo

  • 15 Posts
  • 0 Reply Likes
and in script there is no initialization of moonPhase before checking the value of
percentIlluminated .
Photo of appdemo

appdemo

  • 15 Posts
  • 0 Reply Likes
and in the script the no code is for fetching the value of moonState from data base or from text file ??
Photo of arclance

arclance

  • 29 Posts
  • 0 Reply Likes
You have to initialize moonPhase in your script before you call the function.

I do that by reading the moonPhase value from a textfile I use to backup the variable everytime the script starts.

The convertMoonPhase function updates this textfile when it changes the value.

You should be able to add something to your script to do the same thing yourself.

I did not give you my whole script just the function that does the calculation of the moon phase string.

I can help you with what you don't understand in my example but I can't rewrite your script for you.
Photo of appdemo

appdemo

  • 15 Posts
  • 0 Reply Likes
ok ok thank you for all