

# get state names and abbreviations
states,stabs = [],[]
state_csv = 'O:/GeoData/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 = 'block_housing_change'
years = ['1990','2000','2010','2020']
colors = ['black','white']
# w = '120px'
# h = '90px'
zip_url = 'https://geoserver.silvis.forest.wisc.edu/geodata/block-change-2020/zip/'
map_url = 'https://geoserver.silvis.forest.wisc.edu/geodata/block-change-2020/maps/gifs/'



# http://silvis.forest.wisc.edu/GeoData/block_change_2020/maps/gifs/black/CONUS_Housing_change_1990_black.gif


out_csv = 'O:/GeoData/block-change-2020/BLOCK_CHANGE__2020_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.upper() + '_block20_change_1990_2020_PLA4_shp.zip'
	fgdbfile = zip_url + 'fgdb/' + stab.upper() + '_block20_change_1990_2020_PLA4_fgdb.zip'
	
	fout.write('<div id="wui-map-grid">\n')
	fout.write('<div id="state-name">' + state3 + '</div>\n')
	if stab == 'CONUS': 
		fout.write('<div id="gis-links"><a href="' + fgdbfile + '">FileGDB</a></div>\n')
	else:
		fout.write('<div id="gis-links"><a href="' + fgdbfile + '">FileGDB</a><br><a href="' + shpfile + '">Shapefile</a></div>\n')
		
	for color in colors:
		for year in years:
			fout.write('<div id="' + color + year + '">' + year + '<a href="' + map_url + color + '/' + stab.upper() + '_' + dataset + '_' + year + '_v4_' + color + '.gif"><img src="' + map_url + 'thumbs/' + color + '/' + stab.upper() + '_' + dataset + '_' + year + '_v4_' + color + '_120x90.gif" /></a></div>\n')
	fout.write('</div>\n')
	fout.write('<hr class="row-separator" />')
	
fout.close()

	
# <div id="wui-map-grid">
  # <div id="state-name">Alabama</div>
  # <div id="gis-links">FileGDB<br>Shapefile</div>
  # <div id="black1990">1990<a href="http://silvis.forest.wisc.edu/GeoData/WUI_cp12/maps/gifs/black/Alabama_WUI_cp12_black_1990.gif"><img src="http://silvis.forest.wisc.edu/GeoData/WUI_cp12/maps/gifs/black/Alabama_WUI_cp12_black_1990.gif" /></a></div>
  # <div id="black2000">2000<a href="http://silvis.forest.wisc.edu/GeoData/WUI_cp12/maps/gifs/black/Alabama_WUI_cp12_black_2000.gif"><img src="http://silvis.forest.wisc.edu/GeoData/WUI_cp12/maps/gifs/black/Alabama_WUI_cp12_black_2000.gif" /></a></div>
  # <div id="black2010">2010<a href="http://silvis.forest.wisc.edu/GeoData/WUI_cp12/maps/gifs/black/Alabama_WUI_cp12_black_2010.gif"><img src="http://silvis.forest.wisc.edu/GeoData/WUI_cp12/maps/gifs/black/Alabama_WUI_cp12_black_2010.gif" /></a></div>
  # <div id="white1990">1990<a href="http://silvis.forest.wisc.edu/GeoData/WUI_cp12/maps/gifs/white/Alabama_WUI_cp12_white_1990.gif"><img src="http://silvis.forest.wisc.edu/GeoData/WUI_cp12/maps/gifs/white/Alabama_WUI_cp12_white_1990.gif" /></a></div>
  # <div id="white2000">2000<a href="http://silvis.forest.wisc.edu/GeoData/WUI_cp12/maps/gifs/white/Alabama_WUI_cp12_white_2000.gif"><img src="http://silvis.forest.wisc.edu/GeoData/WUI_cp12/maps/gifs/white/Alabama_WUI_cp12_white_2000.gif" /></a></div>
  # <div id="white2010">2010<a href="http://silvis.forest.wisc.edu/GeoData/WUI_cp12/maps/gifs/white/Alabama_WUI_cp12_white_2010.gif"><img src="http://silvis.forest.wisc.edu/GeoData/WUI_cp12/maps/gifs/white/Alabama_WUI_cp12_white_2010.gif" /></a></div>
# </div>
	
	

exit(0)

