Skip to content

Instantly share code, notes, and snippets.

@ternbusty
Last active February 19, 2018 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ternbusty/48e87a2a210a8888b230a0c13eca4e18 to your computer and use it in GitHub Desktop.
Save ternbusty/48e87a2a210a8888b230a0c13eca4e18 to your computer and use it in GitHub Desktop.
天気と占いをそれぞれAPIを叩いて取得しランダムな時間にメールするスクリプト
#!/bin/bash
ExamDate=`date -j -f "%Y-%m-%d %H:%M:%S" "2017-05-29 23:59:59" "+%s"`
NowDate=`date +"%s"`
DateNumber=`expr \( ${ExamDate} - ${NowDate} \) / 60 / 60 / 24`
hiduke=`date -v+1d "+%Y/%m/%d"`
echo "生理学試験まであと${DateNumber}日です。" > 'Physiology.txt'
echo " " >> Physiology.txt
echo "---明日の天気と占い---" >> Physiology.txt
weatherTranslate() {
case "$1" in
"Thunderstorm" ) echo "雷雨" ;;
"Drizzle" ) echo "霧雨" ;;
"Rain" ) echo "雨" ;;
"Snow" ) echo "雪" ;;
"Atmosphere" ) echo "霧" ;;
"Clear" ) echo "快晴" ;;
"Clouds" ) echo "曇り" ;;
* ) echo "謎" ;;
esac
}
wget -q 'http://api.openweathermap.org/data/2.5/forecast/daily?q=Kyoto&mode=json&units=metric&cnt=2&appid=HOGEFUGA' -O tenki.json
tempMin=`cat tenki.json | jq '.list[1].temp.min'`
tempMax=`cat tenki.json | jq '.list[1].temp.max'`
weather=`cat tenki.json | jq '.list[1].weather[].main' -r`
weatherJp=`weatherTranslate ${weather}`
needUmbrella=False
if [ "$weather" = "Rain" -o "$weather" = "Snow" -o "$weather" = "Thunderstorm" ]; then
$needUmbrella=true
fi
weatherWord="京都の天気は${weatherJp}、最高気温は${tempMax}度、最低気温は${tempMin}度です。"
umbrellaWord="傘を持っていくのを忘れずにね!"
if [ $needUmbrella = true ]; then
echo ${weatherWord} ${umbrellaWord} >> Physiology.txt
else
echo ${weatherWord} >> Physiology.txt
fi
wget -q http://api.jugemkey.jp/api/horoscope/free/${hiduke} -O Uranai.json
Content=`cat Uranai.json | jq .horoscope.\"${hiduke}\"[2].content -r`
Item=`cat Uranai.json | jq .horoscope.\"${hiduke}\"[2].item -r`
Money=`cat Uranai.json | jq .horoscope.\"${hiduke}\"[2].money`
Total=`cat Uranai.json | jq .horoscope.\"${hiduke}\"[2].total`
Job=`cat Uranai.json | jq .horoscope.\"${hiduke}\"[2].job`
Color=`cat Uranai.json | jq .horoscope.\"${hiduke}\"[2].color -r`
Love=`cat Uranai.json | jq .horoscope.\"${hiduke}\"[2].love`
Rank=`cat Uranai.json | jq .horoscope.\"${hiduke}\"[2].rank`
echo "双子座は${Rank}位。運勢は全体運:${Total}、仕事運:${Job}、金運:${Money}、恋愛運:${Love}です。${Content}" >> Physiology.txt
echo "ラッキーカラーは${Color}、ラッキーアイテムは${Item}です。" >> Physiology.txt
cat Physiology.txt | mail -s Physiology hugahuga@i.softbank.jp
ransuu=$(($(od -vAn -N1 -tu4 < /dev/random)%59))
ransuu2=$((ransuu + 1))
if [ $((DataNumber)) -ne 1 ]; then
hiduke2=`date -v+1d "+%m/%d/%Y"`
hiduke3=`date -v+1d "+%d.%m.%y"`
echo '#!/bin/bash' > 'SetTime.sh'
echo 'cd $HOME' >> SetTime.sh
SetMainTime="at -f Physiology.sh \"21:${ransuu2} ${hiduke3}\""
SetPmsetTime="sudo pmset schedule wake \"${hiduke2} 21:${ransuu}:00\""
echo ${SetPmsetTime} >> SetTime.sh
echo ${SetMainTime} >> SetTime.sh
bash SetTime.sh
fi
osascript -e 'tell application "Finder" to sleep'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment