Skip to content

Instantly share code, notes, and snippets.

@mapmeld
Created April 30, 2012 22:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mapmeld/2563397 to your computer and use it in GitHub Desktop.
Save mapmeld/2563397 to your computer and use it in GitHub Desktop.
CalGOLD Search for Santa Cruz
get '/calgold' do
if params["kywd"] == "search"
return "<!DOCTYPE html>\n<html>\n<head>\n<link href='/bootstrap-mini.css' rel='stylesheet' type='text/css'/></head>\n<body>\n<div class='well'><h3>What is your business type?</h3>\n<form action='/calgold' method='get'><input name='kywd' value='' placeholder='Category'/><input type='submit' class='btn btn-info' value='Search' style='vertical-align:top;'/></form><br/><h4>Examples</h4><i>shoe store</i><br/><i>restaurant</i><br/><i>bowling alley</i><br/>or try <i>general business information</i><br/><a href='http://calgold.ca.gov/Default.asp?VW=OUT&TOP=N&KYWD=' target='_blank'>All Business Types</a></div>\n</body>\n</html>"
end
postparams = {"kywd" => params["kywd"], "VW" => "OUT"}
catquest = Net::HTTP.post_form(URI.parse('http://www.calgold.ca.gov/Default.asp?VW=OUT'), postparams)
categories = catquest.body.split("<input type='CHECKBOX'")
index = 0
linkout = ""
categories.each do |category|
if index == 0
index = 1
else
categoryname = category.slice( category.index("'content'>") + 10, category.index("</span>") - 1 )
categorycode = category.slice( category.index("value=") + 6, category.index(categoryname) )
categorycode = categorycode.slice( 0, categorycode.index(" ") )
linkout = linkout + "<br/><a href='/calcontacts?TYPE=" + categorycode + "&CNTY=44&CITY=377'>" + categoryname + "</a>"
end
end
return "<!DOCTYPE html>\n<html>\n<head>\n<link href='/bootstrap-mini.css' rel='stylesheet' type='text/css'/></head>\n<body>\n<div class='well'><form action='/calgold' method='get'><input name='kywd' value='" + params["kywd"].gsub("'","") + "'/><input type='submit' class='btn btn-info' value='Search' style='vertical-align:top;'/></form>\n<h3>Pick a category matching your business:</h3>" + linkout + "\n<br/>Or search general business information</div>\n</body>\n</html>"
end
get '/calcontacts' do
# http://www.calgold.ca.gov/Results1.asp
url = 'http://www.calgold.ca.gov/Results1.asp?TYPE=' + params['TYPE'] + '&CNTY=44&CITY=377'
url = URI.parse(url)
res = Net::HTTP.start(url.host, url.port) {|http|
http.get("/Results1.asp?TYPE=" + params["TYPE"] + "&CNTY=44&CITY=377")
}
outsidecontacts = "<A NAME=County>" + res.body.split('<A NAME=County>')[1]
outsidecontacts = outsidecontacts.slice( 0 , outsidecontacts.index('</table>') )
# remove jump links
outsidecontacts = outsidecontacts.gsub("<p class='content'><b>Go directly to <a href='#City'>City</a>, <a href='#County'>County</a>, <a href='#State'>State</a>, <a href='#Federal'>Federal</a>, or <a href='#Other'>Other</a> permit sections</p>","")
outsidecontacts = outsidecontacts.gsub("<a href='#PageTop' alt=' Top of Page ' WIDTH=74 HEIGHT=19><img src='images/btn_top.gif' ALIGN=right WIDTH=74 HEIGHT=19 BORDER=0></a>&nbsp;", "")
# add a line break before notes
outsidecontacts = outsidecontacts.gsub("<small","<br/><hr/><small")
# CSS styling of headers
outsidecontacts = outsidecontacts.gsub("bgcolor=#cccccc","style='background-color:#444;color:#fff;'")
return "<!DOCTYPE html>\n<html>\n<head>\n<link href='http://twitter.github.com/bootstrap/assets/css/bootstrap.css' type='text/css' rel='stylesheet'/>\n</head>\n<body class='well'>\n<table>\n" + outsidecontacts + "\n</table>\n</body>\n</html>"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment