Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
require 'sinatra'
get '/' do
cities = ["San Francisco", "Los Angeles", "New York", "Boston", "Austin", "Philadelphia", "Seattle", "Sacramento", "Dallas", "Denver", "Houston", "Las Vegas"]
queries = ["chinese translator", "chinese translation", "chinese translate", "chinese translating"]
def generateXmlUrl(city, query)
generateHtmlUrl(city, query) + "&format=rss"
end
def generateHtmlUrl(city, query)
"http://" + city + ".craigslist.org/search/ggg?query=" + query + "&srchType=A&addThree=forpay"
end
def printOutline(text, title, xmlUrl, htmlUrl)
"\t\t\t" + '<outline text="' + title + '" title="' + title + '" type="rss" xmlUrl="' + xmlUrl + '" htmlUrl="' + htmlUrl + '" />'
end
# Start printing!
output = []
output << '<?xml version="1.0" encoding="UTF-8"?>'
output << '<opml version="1.0">'
output << "\t<head>"
output << "\t\t<title>Sharon subscriptions in Google Reader</title>\t\t"
output << "\t</head>"
output << "\t<body>"
output << "\t\t" + '<outline title="Chinese Translation" text="Chinese Translation">'
cities.each do |city|
queries.each do |query|
title = "Craigslist - " + city + " " + query
city_ = city.downcase.gsub(/\s+/, "") # lowercase and no spaces since this is subdomain
query_ = query.gsub(/\s+/, "+") # replace spaces with + since this is a query
printOutline(title, title, generateXmlUrl(city_, query_), generateHtmlUrl(city_, query_))
end
end
output << "\t\t</outline>"
output << "\t</body>"
output << "</opml>"
output.join("\n")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment