

# get state names and abbreviations
states,stabs = [],[]
state_csv = 'x:/state_abbreviations.csv'
f = open(state_csv, 'r')
f.readline()
for L in f:
	L = L.strip('\n')
	l = L.split(',')
	states.append(l[0])
	if l[1] != "CONUS":
		stabs.append(l[1].lower())
	else:
		stabs.append(l[1])

# variables
dataset = 'Housing_PBG_project'
years = range(1940, 2060, 10)
# years = ['1990','2000','2010']
colors = ['black','white']
# w = '120px'
# h = '90px'
zip_url = 'http://silvis.forest.wisc.edu/GeoData/Housing_data/PBG_change/zip/'
map_url = 'http://silvis.forest.wisc.edu/GeoData/Housing_data/PBG_change/maps2/gifs_mask/'


out_csv = 'x:/Housing_data/PBG_change/PBG_CHANGE_download_HTML_wordpress.html'
fout = open(out_csv,'w')


for state in states:
	print state

	stab = stabs[states.index(state)]
	state2 = state.strip(' ')
	state2 = state2.replace(' ','_')
	state3 = state2.replace('_','<br>')
	if stab == 'CONUS': 
		state2 = 'CONUS'
		state3 = 'Conterminous<br>United States'
	if stab == 'dc':
		state3 = 'District of<br>Columbia'
	
	shpfile = zip_url + 'shp/' + stab + '_pbg00_proj_1940_2050_shp.zip'
	fgdbfile = zip_url + 'fgdb/' + stab + '_pbg00_proj_1940_2050_fgdb.zip'
	
	fout.write('<div id="pbg-map-grid">\n')
	fout.write('<div id="state-name">' + state3 + '</div>\n')
	if stab == 'CONUS': 
		fout.write('<div id="pbg-links"><a href="' + fgdbfile + '">FileGDB</a></div>\n')
	else:
		fout.write('<div id="pbg-links"><a href="' + fgdbfile + '">FileGDB</a><br><a href="' + shpfile + '">Shapefile</a></div>\n')
		
	for color in colors:
		for yr in years:
			year = str(yr)
			fout.write('<div id="' + color + year + '">' + year + '<a href="' + map_url + color + '/' + state2 + '_' + dataset + '_' + year + '_' + color + '.gif"><img src="' + map_url + color + '/' + state2 + '_' + dataset + '_' + year + '_' + color + '.gif" /></a></div>\n')
	fout.write('</div>\n')
	fout.write('<hr class="row-separator" />')
	
fout.close()	

exit(0)

