Skip to content

Instantly share code, notes, and snippets.

@nikolajbaer
Created September 25, 2009 21:08
Show Gist options
  • Save nikolajbaer/193847 to your computer and use it in GitHub Desktop.
Save nikolajbaer/193847 to your computer and use it in GitHub Desktop.
San Diego Surf Report script for Android Scripting
"""Display the (scraped) surf report for San Diego from the noaa in a notification."""
__author__ = 'Nikolaj Baer <nkolaj.baer@gmail.com>'
__copyright__ = 'Copyright (c) 2009'
__license__ = 'MIT License'
import urllib,re
LOCATION="San Diego"
AREA="SGX"
REPORT_URL="http://newweb.wrh.noaa.gov/sgx/print_version.php?sid=%s&pil=SRF&version=0"%AREA
def get_report():
rp={}
x=urllib.urlopen(REPORT_URL).read()
report=x[x.find("<pre>")+5:]
report=report[:report.find("</pre>")].replace("<br>","\n").replace("<hr>","\n")
msg=report[report.find("SURF HEIGHT"):report.find("**")].rstrip()
# Wacky parsing
rep={"location":LOCATION}
for l in msg.split('\n'):
n=l.strip().rstrip(".")
if n.startswith("SURF HEIGHT"):
rep["height"]=n[n.rfind(".")+1:]
rep["heights"]=[int(x) for x in re.findall("\d+",rep["height"])]
elif n.startswith("WATER TEMPERATURE"):
rep["temp"]=n[n.rfind(".")+1:]
rep["temps"]=[int(x) for x in re.findall("\d+",rep["temp"])]
elif n.startswith("OUTLOOK"):
rep["nxt"]=n[n.rfind(".")+1:]
rep["tomorrow"]=[int(x) for x in re.findall("\d+",rep["nxt"])]
return rep
if __name__=="__main__":
rep=get_report()
msg="""Today: %(height)s, %(temp)s\nTomorrow: %(nxt)s"""
try:
import android
droid=android.Android()
droid.notify(msg%rep,"%s Surf Conditions"%LOCATION,msg%rep)
droid.exit()
except ImportError:
print msg%rep
print rep
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment