Skip to content

Instantly share code, notes, and snippets.

@fjfish
Created June 6, 2013 11:49
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 fjfish/5720959 to your computer and use it in GitHub Desktop.
Save fjfish/5720959 to your computer and use it in GitHub Desktop.
Little script to take a file of quotes either as an argument or from a redirect and turn it into a CSV that hootsuite will load.
#! /usr/bin/ruby
require 'date'
require 'set'
quotes = $<.readlines.map { |line| line.strip }
tag = "#unicorns"
url = "https://leanpub.com/unicorns"
def used_timestamps
@used_timestamps ||= Set.new
end
def pick_random thing
thing[rand 0..(thing.size-1)]
end
def gen_timestamp
tomorrow = DateTime.now.to_date + 1
hour_range = (10..22).to_a
minute_range = (1..3).to_a.map { |min| min * 15 }
begin
day = tomorrow + (rand 0..30)
hour = pick_random hour_range
minute = pick_random minute_range
# US dates are the default, so leave it
timestamp = "#{day.strftime("%m/%d/%Y")} #{hour}:#{minute}"
end while ! used_timestamps.add?(timestamp)
timestamp
end
output = quotes.map do |quote|
next if quote.size == 0
"#{gen_timestamp},\"#{quote} #{tag}\",\"#{url}\""
end
puts (output ||[]).join "\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment