Skip to content

Instantly share code, notes, and snippets.

@mm53bar
Last active November 29, 2018 15:28
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 mm53bar/311e6f050d9674d99e5dc8298c01b24c to your computer and use it in GitHub Desktop.
Save mm53bar/311e6f050d9674d99e5dc8298c01b24c to your computer and use it in GitHub Desktop.
Scrape ramp

First go to any team's home page on a ramp site i.e. http://raidershockey.ca/team/2090/0/0/33929. Grab the url of the home page and add it into sync.rb. Then run the script:

ruby sync.rb

The script will pull a json feed of games, practices, and events (events.json) and make it available by exposing an Event object for each element in the json array.

class Event
PRACTICE = 'Team Practice'
GAME = 'Team Game'
def initialize(json)
@json = json
end
def starts_at
DateTime.parse json['start']
end
def ends_at
DateTime.parse json['end']
end
def type
json['typeName']
end
def notes
json['notes']
end
def location
if type == PRACTICE
get_practice_location
else
json['location']
end
end
def title
case type
when PRACTICE
@title = get_practice_title
when GAME
teams = get_teams_from_title
@title = [teams[0].strip,teams[1].strip].join ' @ '
else
@title = json['title']
end
@title
end
def json
@json
end
private
def get_practice_title
json['title'].split('@')[0].strip
end
def get_practice_location
json['title'].split('@')[1].strip
end
def get_teams_from_title
json['title'].sub(location,"").split('@')
end
end
require_relative 'ramp_scraper'
require_relative 'event'
class Events
def self.scrape(url, scraper)
self.new(scraper.scrape(url))
end
def initialize(events_json)
@events_json = events_json
end
def [](item)
Event.new(json[item])
end
def size
json.size
end
def json
@events_json
end
private
def team_id
@team_id
end
def association_id
@association_id
end
end
require 'open-uri'
require 'json'
class RampScraper
def scrape(ramp_url)
open(ramp_url) do |x|
@html = x.read
end
links = @html.scan(/events:\s'https:\/\/www\.rampinteractive\.com\/api\/mastercalendar\/getteam\/(\d*)\/(\d*)'/ui)
association_id = links[0][0]
team_id = links[0][1]
open("https://www.rampinteractive.com/api/mastercalendar/getteam/#{association_id}/#{team_id}?start=2018-07-01&end=2019-12-31") do |x|
@json_text = x.read
end
JSON.parse(@json_text)
end
private
def ramp_url
@ramp_url
end
end
require_relative 'events'
url = 'http://raidershockey.ca/team/2090/0/0/33929'
#url = 'http://raidershockey.ca/team/2090/0/0/33927'
events = Events.scrape(url, RampScraper.new)
(0..events.size-1).each {|n| puts "#{events[n].title} on #{events[n].ends_at.strftime('%m/%d/%Y at %I:%M%p')}" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment