Skip to content

Instantly share code, notes, and snippets.

@atsmith813
Last active November 6, 2019 04:25
Show Gist options
  • Save atsmith813/43e342f5ee190012e946a484756acf40 to your computer and use it in GitHub Desktop.
Save atsmith813/43e342f5ee190012e946a484756acf40 to your computer and use it in GitHub Desktop.
Import birthdays from .ics file to Google Sheets
# Continuing with the birthdays object created above...
# Initiate and authenticate a Google Drive session
session = GoogleDrive::Session.from_service_account_key('client_secret.json')
# Open our birthday_bot spreadsheet
spreadsheet = session.spreadsheet_by_name('birthday_bot')
# Select the first worksheet in the spreadsheet
ws = spreadsheet.worksheets.first
# Grab the existing names in the worksheet
existing_names = ws.rows.map(&:first)
# Remove any existing birthdays, if there are any
birthdays.reject! { |birthday| existing_names.include? birthday[:name] } if existing_names.length > 0
# Append the newly found birthdays to the end of the Google Sheet
birthdays.each.with_index(ws.num_rows + 1) do |birthday, i|
ws[i, 1] = birthday[:name]
ws[i, 2] = birthday[:date].to_s
end
# Save the worksheet
ws.save
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment