Created
December 5, 2013 02:09
-
-
Save mdawaffe/7799053 to your computer and use it in GitHub Desktop.
Express the Current Approximate Phase of the Moon as an Emoji Character in UTF-8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Approximates the phase of the moon using a known new-moon time and a fixed lunar phase of 2551443 seconds. | |
# Outputs the phase as an emoji in UTF-8 | |
CHARS=( | |
"\xf0\x9f\x8c\x91" # 0 - NEW | |
"\xf0\x9f\x8c\x91" # 1 - NEW | |
"\xf0\x9f\x8c\x92" # 2 - WAXING CRESCENT | |
"\xf0\x9f\x8c\x92" # 3 - WAXING CRESCENT | |
"\xf0\x9f\x8c\x92" # 4 - WAXING CRESCENT | |
"\xf0\x9f\x8c\x92" # 5 - WAXING CRESCENT | |
"\xf0\x9f\x8c\x93" # 6 - FIRST QUARTER | |
"\xf0\x9f\x8c\x93" # 7 - FIRST QUARTER | |
"\xf0\x9f\x8c\x93" # 8 - FIRST QUARTER | |
"\xf0\x9f\x8c\x93" # 9 - FIRST QUARTER | |
"\xf0\x9f\x8c\x94" # 10 - WAXING GIBBOUS | |
"\xf0\x9f\x8c\x94" # 11 - WAXING GIBBOUS | |
"\xf0\x9f\x8c\x94" # 12 - WAXING GIBBOUS | |
"\xf0\x9f\x8c\x94" # 13 - WAXING GIBBOUS | |
"\xf0\x9f\x8c\x95" # 14 - FULL | |
"\xf0\x9f\x8c\x95" # 15 - FULL | |
"\xf0\x9f\x8c\x95" # 16 - FULL | |
"\xf0\x9f\x8c\x96" # 17 - WANING GIBBOUS | |
"\xf0\x9f\x8c\x96" # 18 - WANING GIBBOUS | |
"\xf0\x9f\x8c\x96" # 19 - WANING GIBBOUS | |
"\xf0\x9f\x8c\x96" # 20 - WANING GIBBOUS | |
"\xf0\x9f\x8c\x97" # 21 - LAST QUARTER | |
"\xf0\x9f\x8c\x97" # 22 - LAST QUARTER | |
"\xf0\x9f\x8c\x97" # 23 - LAST QUARTER | |
"\xf0\x9f\x8c\x97" # 24 - LAST QUARTER | |
"\xf0\x9f\x8c\x98" # 25 - WANING CRESCENT | |
"\xf0\x9f\x8c\x98" # 26 - WANING CRESCENT | |
"\xf0\x9f\x8c\x98" # 27 - WANING CRESCENT | |
"\xf0\x9f\x8c\x98" # 28 - WANING CRESCENT | |
"\xf0\x9f\x8c\x91" # 29 - NEW | |
) | |
PHASE=$(( ( ( $( date -j -f '%M:%S' 00:00 +%s ) - 1386030360 ) % 2551443 ) / 86400 )) | |
echo -ne "${CHARS[$PHASE]}" | |
if [ -z "$NONEWLINE" ] | |
then | |
echo | |
fi |
Okay I see now this is Mac OS X 'date'. I believe that the Linux equivalent is "date --date='00:00' +%s".
I'm using this script to make a geeklet and the phase is off. I'm showing a last quarter and it should be waning crescent.
Here's a version that checks for Darwin or Linux and runs the correct date command depending:
#!/bin/bash
# Approximates the phase of the moon using a known new-moon time and a fixed lunar phase of 2551443 seconds.
# Outputs the phase as an emoji in UTF-8
CHARS=(
"\xf0\x9f\x8c\x91" # 0 - NEW
"\xf0\x9f\x8c\x91" # 1 - NEW
"\xf0\x9f\x8c\x92" # 2 - WAXING CRESCENT
"\xf0\x9f\x8c\x92" # 3 - WAXING CRESCENT
"\xf0\x9f\x8c\x92" # 4 - WAXING CRESCENT
"\xf0\x9f\x8c\x92" # 5 - WAXING CRESCENT
"\xf0\x9f\x8c\x93" # 6 - FIRST QUARTER
"\xf0\x9f\x8c\x93" # 7 - FIRST QUARTER
"\xf0\x9f\x8c\x93" # 8 - FIRST QUARTER
"\xf0\x9f\x8c\x93" # 9 - FIRST QUARTER
"\xf0\x9f\x8c\x94" # 10 - WAXING GIBBOUS
"\xf0\x9f\x8c\x94" # 11 - WAXING GIBBOUS
"\xf0\x9f\x8c\x94" # 12 - WAXING GIBBOUS
"\xf0\x9f\x8c\x94" # 13 - WAXING GIBBOUS
"\xf0\x9f\x8c\x95" # 14 - FULL
"\xf0\x9f\x8c\x95" # 15 - FULL
"\xf0\x9f\x8c\x95" # 16 - FULL
"\xf0\x9f\x8c\x96" # 17 - WANING GIBBOUS
"\xf0\x9f\x8c\x96" # 18 - WANING GIBBOUS
"\xf0\x9f\x8c\x96" # 19 - WANING GIBBOUS
"\xf0\x9f\x8c\x96" # 20 - WANING GIBBOUS
"\xf0\x9f\x8c\x97" # 21 - LAST QUARTER
"\xf0\x9f\x8c\x97" # 22 - LAST QUARTER
"\xf0\x9f\x8c\x97" # 23 - LAST QUARTER
"\xf0\x9f\x8c\x97" # 24 - LAST QUARTER
"\xf0\x9f\x8c\x98" # 25 - WANING CRESCENT
"\xf0\x9f\x8c\x98" # 26 - WANING CRESCENT
"\xf0\x9f\x8c\x98" # 27 - WANING CRESCENT
"\xf0\x9f\x8c\x98" # 28 - WANING CRESCENT
"\xf0\x9f\x8c\x91" # 29 - NEW
)
if [ "$(uname)" == "Darwin" ]; then
PHASE=$(( ( ( $( date -j -f '%M:%S' 00:00 +%s ) - 1386030360 ) % 2551443 ) / 86400 ))
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
PHASE=$(( ( ( $( date --date='00:00' +%s ) - 1386030360 ) % 2551443 ) / 86400 ))
fi
echo -ne "${CHARS[$PHASE]}"
if [ -z "$NONEWLINE" ]
then
echo
fi
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What 'date' command do you use in the script?
I have no such option keys like -j or -f in my 'date' utility.