Created
May 8, 2012 04:06
-
-
Save stevenklise/2632472 to your computer and use it in GitHub Desktop.
Save a csv of presentation times names and urls to Hubot's Redis brain
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'csv' | |
| require 'json' | |
| require 'redis' | |
| require 'uri' | |
| # Open the csv as a csv. | |
| csv = CSV.read('./thesis.csv') | |
| # Outputs as a 2D array but I want a hash to turn in to JSON. | |
| thesisweek = { | |
| 'year' => 2012, | |
| 'month' => 5, | |
| 'dates' => { | |
| 'start' => 7, | |
| 'end' => 11 | |
| }, | |
| 'url' => 'http://itp.nyu.edu/shows/thesis2012/', | |
| 'schedule' => {} | |
| } | |
| schedule = thesisweek['schedule'] | |
| # Add all of the thesis projects | |
| csv[1..csv.length].each do |presentation| | |
| # [Day, M/D/YR, HH:MM, First Last, url] | |
| if presentation[3] != 'break' | |
| # Get or create a hash for the day. | |
| day = presentation[0].downcase | |
| schedule[day] ||= {} | |
| time = presentation[2].split(':') | |
| # Convert hours to 24hour time, sorting will be nicer later. | |
| time[0] = time[0].to_i+12 if time[0].to_i < 12 | |
| assembled_time = "#{time[0]}#{time[1]}" | |
| schedule[day][assembled_time] = { | |
| 'name' => presentation[3], | |
| 'url' => presentation[4] | |
| } | |
| end | |
| end | |
| uri = URI.parse(ENV['REDISURL']) | |
| @redis = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password) | |
| brain = JSON.parse(@redis.get('hubot:storage')) | |
| brain['thesisweek'] = {'2012' => thesisweek} | |
| @redis.set('hubot:storage', brain.to_json) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment