#!/usr/local/epd-7.2-2-rh5-x86_64/bin/python #SPCRPTS.PY ########################################################### #The purpose of this script is to save time parsing SPC #storm reports into the format required for creating #markers in Google Maps. The script will read a comma- #delimited list of storm reports and write the necessary #Javascript/HTML hybrid for making the markers. # #You may also wish to expand upon this script to have it #write out your entire Google maps Javascript. That's what #I did and it's what I recommend for you. Of course, you can #always just type in the storm reports by hand if you have #nothing better to do with your time... # #Please see the comments throughout this script. # #Christopher M. Godfrey 12 July 2010 #Modified 5 May 2011 ########################################################### #Import a bunch of stuff that you may or may not need import sys,urllib2,os,cgi,time,glob,math,string,re import datetime #If you decide to make this script interact with a Web browser, uncomment the next lines #import cgitb; cgitb.enable() #Gives nicely-formatted error messages #print "Content-type: text/html\n" #Required first line to send to client for debugging #This is the file that you want to read: reports='110427_rpts.csv' ########################################################### #YOUR TURN (1 of 3): #It's possible to have this script write out your entire Javascript code! #Then you can include that script as an external file by placing the #following in your HTML section, along with any other HTML in #that section: # # # #-------------------------------------------------- #SPECIAL NOTE FOR THE LATEST MAPS API REQUIREMENTS: #The Google documentation says that you need to include something like the #following in your HTML head section as well: # # # #I discovered some quirks here. If you put this after your own JavaScript reference, your map will probably work, #but you will see an error in the Developer Tools console in your browser. That's OK, but not great. To remove the #error, place the reference to the Google script with your key BEFORE the reference to your own JavaScript file. #This actually gives another error and breaks the map! The best option for removing the error is to remove the #callback reference, which points to initMap rather than initialize as in my examples. But you call the 'initialize()' #function in the tag anyway, so this is moot. Your section would then look like this: # # # # # # #This will work if you are using HTML5, which is the default these days, so you probably don't need to worry about it #anyway. If you specify a different HTML version in your DOCTYPE (a declaration that is optional, but recommended) as #in my HTML examples in your first task, then you may find that "async defer" produces an error in the W3C Markup #Validation Service. It's OK to remove "async defer" on older Web pages to remove all the errors. #C. Godfrey 2 June 2020 #-------------------------------------------------- #Open your external Javascript file for writing java=open("your_javascript.js","w") #Write the first part of your Javascript here. Enclose #everything in triple quotes. java.write('''function initialize() //...blabla //...blablabla ''') ########################################################### #Open and read the SPC comma-delimited storm reports file file=open(reports,'r') lines=file.readlines() #Initialize type of report type="None" #Initialize marker variables tor="" wind="" hail="" #Loop through the reports and parse the data for line in lines: cols=line.split(',') #Leave out the headers and determine type of report (always tor, wind, hail in order) if cols[0]=="Time": if type=="None": type="tor" elif type=="tor": type="wind" elif type=="wind": type="hail" continue #Go to the top of the loop and skip the rest time=cols[0] mag=cols[1] loc=cols[2] county=cols[3] state=cols[4] lat=cols[5] lon=cols[6] comment=cols[7].strip() #Must remove carriage return #Fix abbreviations if mag=="UNK": mag="Unknown" ########################################################### #YOUR TURN AGAIN (2 of 3): #Now we can write the necessary code for our markers! (Copy and modify this for tor, wind, & hail) #You may need to change this to match your version of your Google maps Javascript code, but this #works with mine. if type=="tor": tor=tor+'''['''+lat+''', '''+lon+''', "Time: '''+time+''' UTC
F-Scale '''+mag+'''
Location: '''+loc+'''
County: '''+county+'''
State: '''+state+'''
Comments:","'''+comment+'''","red"],''' ########################################################### #Write the storm reports to the Javascript java.write(''' var tor= ['''+tor+''']; var wind= ['''+wind+''']; var hail= ['''+hail+''']; ''') ########################################################### #YOUR TURN ONE MORE TIME (3 of 3): #Close out the Javascript; put the rest of your Javascript here! java.write(''' ''') ########################################################### java.close() print "Wrote the Javascript file. Now write your HTML file and view your map on the Web!"