Skip to content

Instantly share code, notes, and snippets.

@flemdizzle
Created December 16, 2014 14:53
Show Gist options
  • Save flemdizzle/733e857f6bda66925c16 to your computer and use it in GitHub Desktop.
Save flemdizzle/733e857f6bda66925c16 to your computer and use it in GitHub Desktop.
def self.available_bikes(distance, id)
doc = Nokogiri::XML(open("http://www.capitalbikeshare.com/data/stations/bikeStations.xml"))
# spits out the number of bikes at a given station
doc.xpath('//station').each do |node|
if node.children[0].text == "#{id}"
latitude = node.children[4].text
distance = distance.round(2)
longitude = node.children[5].text
bikes = node.children[12].text
docks = node.children[13].text
address = node.children[1].text
return Hash[distance: "#{distance}mi.", location: "#{latitude}, #{longitude}", bikes: "#{bikes}", docks: "#{docks}", address: "#{address}"]
end
end
end
def self.update_station_info
Station.delete_all
doc = Nokogiri::XML(open("http://www.capitalbikeshare.com/data/stations/bikeStations.xml"))
doc.xpath('//station').each do |node|
Station.create(station_id: node.children[0].text.to_i,
latitude: node.children[4].text.to_f,
longitude: node.children[5].text.to_f)
en
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment