Skip to content

Instantly share code, notes, and snippets.

@153957
Last active August 13, 2017 08:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 153957/13895729937598daa796 to your computer and use it in GitHub Desktop.
Save 153957/13895729937598daa796 to your computer and use it in GitHub Desktop.
Aurora alert

Aurora alert

This script was written during a holiday in Rovaniemi. On one of the nights the immediate aurora forecast was not good, but fearing to miss anything while sleeping I quickly wrote this script. The script keeps an eye on the forecast Kp value (Aurora activity) and will play a sound if it looks good. Unfortunately the alarm did not go off, because there was no aurora activity. Luckily the following evening the alarm was not needed because we got an amazing show, see the time-lapse.

import urllib2
import os
from numpy import genfromtxt
import StringIO
import time
SOUND = 'afplay /System/Library/Sounds/Sosumi.aiff'
URL = 'http://services.swpc.noaa.gov/text/wing-kp.txt'
HALF_HOUR = 1800
FIFTEEN_MINUTES = 900
A_SECOND = 1
def check_kp():
while True:
kp_url = urllib2.urlopen(URL)
kp_csv = kp_url.read()
kp_file = StringIO.StringIO(kp_csv)
kp_data = genfromtxt(kp_file, skip_header=10)
if kp_data[-1][9] > 3.4:
print '!!! Predicted value over 1 hour: %.2f !!!' % kp_data[-1][9]
# Earlier alert if value before was also good.
if kp_data[-2][9] > 3.3:
print 'Waiting a bit longer before waking, 45 minute forecast less great'
time.sleep(FIFTEEN_MINUTES)
time.sleep(FIFTEEN_MINUTES)
while True:
os.system(SOUND)
os.system(SOUND)
time.sleep(2 * A_SECOND)
else:
print 'Predicted value over 1 hour: %.2f' % kp_data[-1][9]
time.sleep(FIFTEEN_MINUTES)
def keep_alive():
try:
check_kp()
except KeyboardInterrupt:
raise
except:
print 'Restarting checks'
keep_alive()
if __name__ == '__main__':
keep_alive()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment