Exemplo n.º 1
0
def Main():
	city, year, loop = content()			# Returns forms values
							# City => 3 or 4 digit station code
							# year => 4 digit string for year
							# loop => an interger count variable

	style.header("Historical Iowa WX Data", "white")	# Set up HTML page for apache

	city_name = functs.convert_station(city)	# Convert code into string name of city

	im = []						# Needs an array to set up all the picts

	dirname = tempfile.mktemp()			# Create a directory name via tempfile module
	dirname = dirname[-5:-2] + dirname[-1:]		# I only want intergers in the name

	while (os.path.isdir(base_fref+dirname) ):
		dirname = tempfile.mktemp()                     # Create a directory name via tempfile module
	        dirname = dirname[-5:-2] + dirname[-1:]      

	os.mkdir(base_fref+dirname, 0777)		# Create a directory over in HTML side

	for i in range(int(loop)):			# Create int(loop) number of gif images

		im.append(image(city_name, year))	# Create an image instance to be modified

		results = query_station(city, year)	# Query database system for results
		if len(results) == 0:			# If no results are found, quit the loop
			break				

		highs, lows = parse_data(results)	# Parse out the results into two tuples

		red = im[i].colorAllocate((255,0,0))	# Allocate needed colors for lines on graph
		blue = im[i].colorAllocate((0,0,255))	

		im[i].lines(highs, red)			# High values put on graph in red
		im[i].lines(lows, blue)			# Low values put on graph in blue


		im[i].writeGif(base_fref+dirname+"/const"+str(i)+".gif")	# Create gif graph

		year = str(int(year)+ 1)		# increment year value by one

	
	if loop > 0:					# If a loop was needed, then we need to animate it
		gif_file = make_animate(dirname)	# based on the assumption that all gifs are in one dir
	else:
		gif_file = base_href+dirname+"/const0.gif"	# Otherwise only one gif exists so that is where
								# It is at
	html_gif(gif_file)				# Create the HTML neccessary to view the finished product

	style.std_bot()					# Finish and exit...
Exemplo n.º 2
0
def Main():
	city, year, loop = content()

	print 'Content-type: text/html \n\n'
	city_name = functs.convert_station(city)	# Convert code into string name


	im = []

	dirname = tempfile.mktemp()
	dirname = dirname[-5:-2] + dirname[-1:]

	os.mkdir("/home/httpd/html/archivewx/iowawx/graphs/"+dirname, 0777)

	for i in range(int(loop)):
		temp = image(city_name, year)
		im.append(temp)
		results = query_station(city, year)

		highs, lows = parse_data(results)

		red = im[i].colorAllocate((255,0,0))
		blue = im[i].colorAllocate((0,0,255))

		im[i].lines(highs, red)
		im[i].lines(lows, blue)

		this_i = str(i)

#		gif_file.append(filename)

		im[i].writeGif("/home/httpd/html/archivewx/iowawx/graphs/"+dirname+"/const"+this_i+".gif")

		year = str(int(year)+ 1)
	
	if loop > 0:
		gif_file = make_animate(dirname)
	else:
		gif_file = "/home/httpd/html/archivewx/iowawx/graphs/"+dirname+"/const0.gif"

	html_gif(gif_file)
Exemplo n.º 3
0
def Main():
    style.header("Download Dataset from IowaWx Archive", "white")
    print "<H2>Instructions for downloading from the PALS server</H2>"

    query_option = functs.get_content("query_option")
    city = functs.get_content("city")
    year = functs.get_content("year")
    month = functs.get_content("month")
    day = functs.get_content("day")

    if month == "None":
        str_month = "None"
    else:
        str_month = functs.convert_month("0" + month)

    if city == "None":
        str_city = "None"
    else:
        str_city = functs.convert_station(city)

    print "<HR><H3>1. Review Search Parameters....</H3>"
    print "<TABLE NOBORDER>"
    print '<TR><TH colspan="4">Search Paramenters:</TH><TH colspan="6"><font color="red">Time Constraints:</red></TH></TR>'
    print '<TR><TH bgcolor="#EEEEE">Query Option:</TH><TD>' + query_option + "</TD>"
    print '<TH bgcolor="#EEEEE">Station Option:</TH><TD>' + str_city + "</TD>"
    print '<TH bgcolor="#EEEEE"><font color="red">Year:</font></TH><TD>' + year + "</TD>"
    print '<TH bgcolor="#EEEEE"><font color="red">Month:</font></TH><TD>' + str_month + "</TD>"
    print '<TH bgcolor="#EEEEE"><font color="red">Day:</font></TH><TD>' + day + "</TD>"
    print "</TR></TABLE>"
    print "<HR>"

    print "<H3>2. Instructions for downloading this data.</H3>"
    print "Below a link with appear and you need to hold the shift key down and click on the link.<BR>"
    print "This should allow you to save the text file locally, so then you can do what ever you want with it.<BR>"
    print "<HR>"

    url = "/archivewx/iowawx/tmp/" + filename + ".txt"

    print "<H3>3. Creating data file... (May take a few seconds.)</H3>"

    results = engine.search(query_option, city, year, month, day)

    for i in range(len(results)):
        city = results[i][0]
        year = results[i][1]
        month = results[i][2]
        day = results[i][3]
        climoweek = results[i][4]
        high = results[i][5]
        low = results[i][6]
        rain = results[i][7]
        snow = results[i][8]
        file.write(city + "\t" + year + "\t" + month + "\t" + day + "\t" + climoweek + "\t" + high + "\t")
        file.write(low + "\t" + rain + "\t" + snow + "\n")
    file.close()

    print "<BR>File created successfully!! <BR><HR>"

    print "<H3>4. Download file</H3>"
    print '<a href="' + url + '">Shift-Click Here, to download file</a><BR>'

    style.std_bot()
Exemplo n.º 4
0
def Main():

	form = FormContent()

	query_option = form["query_option"][0]			# Determine which option is desired

	city = "None"			# Code for 
	city_name = "None"
	if form.has_key("city"):
		city = form["city"][0]
		city_name = functs.convert_station(city)

	year = "None"
	if form.has_key("year"):
		year = form["year"][0]

	month = "None"
	str_month = "None"
	if form.has_key("month"):
		month = form["month"][0]
		str_month = functs.convert_month("0"+month)

	day = "None"
	if form.has_key("day"):
		day = form["day"][0]

	if year == "none" or year == "None":
		style.SendError("You need to specify a search date.")

	style.header("Historical Iowa Weather Data Search Engine","white")	# Standard Setup HTML Document
	style.std_top("Query Results in Iowa Weather Data")			# Standard Header Information

	print '<TABLE NOBORDER>'
	print '<TR><TH colspan="4">Search Paramenters:</TH><TH colspan="6"><font color="red">Time Constraints:</red></TH></TR>'
	print '<TR><TH bgcolor="#EEEEE">Query Option:</TH><TD>'+query_option+'</TD>'
	print '<TH bgcolor="#EEEEE">Station Option:</TH><TD>'+city_name+'</TD>'
	print '<TH bgcolor="#EEEEE"><font color="red">Year:</font></TH><TD>'+year+'</TD>'
	print '<TH bgcolor="#EEEEE"><font color="red">Month:</font></TH><TD>'+str_month+'</TD>'
	print '<TH bgcolor="#EEEEE"><font color="red">Day:</font></TH><TD>'+day+'</TD>'
	print '</TR></TABLE>'

	if city == "None":
		print '<H2 align="center"><font color="blue"><U>Please Enter a city!!</U></font></H2>'
		style.std_bot()
		sys.exit()

	results = engine.search(query_option, city, year, month, day)

	print '<HR>'

	junk_string = 'query_option='+query_option+'&city='+city+'&year='+year+'&month='+month+'&day='+day
	print '<a href="download.py?'+junk_string+'"><B>Click to download this data set</B></a>'

	print '<HR>'

	if len(results) == 0:
		print '<P>This Query did not find any results in the Database system.<BR>'
		print '<P>Please review your query above and try again.<BR>'

	else:
		print '<H2 align="center"><font color="blue"><U>Weather Data for '+city_name+', Iowa</U></font></H2>'
		table_header()
		for i in range(len(results)):
			city = results[i][0]
	                day = results[i][1]
	                climoweek = results[i][2]
	                high  = results[i][3]
	                low = results[i][4]
	                rain = results[i][5]
	                snow = results[i][6]

			result_row(city, day, str(high), str(low), str(rain), str(snow) )
		table_footer()	

	style.std_bot()
Exemplo n.º 5
0
def Main():
	form = FormContent()
	if form.has_key("city"):
		city = form["city"][0]
	else:
		style.SendError("Please Enter a City")
	if form.has_key("year"):
		year = str(form["year"][0])
	else:
		style.SendError("Please Enter a Valid Year")


	print 'Content-type: text/html \n\n'
	
	im = gd.image((800,500))        # Set up image object

	# Allocate Colors and Fonts
	red = im.colorAllocate((255,0,0))
	green = im.colorAllocate((0,255,0))
	blue = im.colorAllocate((0,0,255))
	black = im.colorAllocate((0,0,0))
	white = im.colorAllocate((255,255,255))
	lgreen = im.colorAllocate((127,125,85))
	test = im.colorAllocate((12,15,185))

	label = gd.gdFontMediumBold
	title = gd.gdFontGiant

	city_name = functs.convert_station(city)	

	results = mydb.query("SELECT high,low from "+city+" WHERE yeer = '"+year+"'")
	results = results.getresult()

	im.fill((10,10), black)

	im.string(title, (10, 5), "Temperature Mins / Maxs for "+city_name+" during "+year , white) 
	im.string(title, (350, 400), "Consecutive Days", white)
	im.stringUp(title, (0, 250), "Temperature ", white)

	highs = []
	lows = []

	im.origin((20,0),2,3)

	im.line((0,20),(380,20), lgreen)		# 100 degree line
	im.line((0,88),(380,88), lgreen)		# 32 degree line
	im.line((0,120),(380,120), lgreen)		# 0 degree line

	im.string(label, (0, 16), "100 F", lgreen)
	im.string(label, (0, 84), "32 F", lgreen)
	im.string(label, (0, 116), "0 F", lgreen)


	im.origin((50,0),2,3)

	im.line((90,83),(90,93), white)		# April degree line
	im.line((181,83),(181,93), white)	# July degree line
	im.line((273,83),(273,93), white)	# October degree line


	for i in range(len(results)):
		highdata = i+1, 120 - int(results[i][0])
		lowdata =  i+1, 120  - int(results[i][1])
		highs.append(highdata)
		lows.append(lowdata)

	highs = tuple(highs)
	lows = tuple(lows)

	im.lines(highs, red)
	im.lines(lows, blue)

	filename = tempfile.mktemp()
	filename = filename[-5:-2] + filename[-1:]


	im.writeGif("/home/httpd/html/archivewx/iowawx/graphs/"+filename+".gif")

	print '<HTML>'
	print '<img src="/archivewx/iowawx/graphs/'+filename+'.gif">'

	print '<H3>Options:</H3>'
	print '<P><a href="/archivewx/iowawx/graphs/'+filename+'.gif">Shift-Click to download this graph</a>'
	print '<P><a href="index.py?opt=graph_yearly">Try another query</a>'