Skip to content

Instantly share code, notes, and snippets.

@seven1m
Created February 4, 2018 19:03
Show Gist options
  • Save seven1m/de1c36361a3d576aa7c544dde7184aa1 to your computer and use it in GitHub Desktop.
Save seven1m/de1c36361a3d576aa7c544dde7184aa1 to your computer and use it in GitHub Desktop.
# export a list from Planning Center People to CSV
#
# setup:
# 1. gem install pco_api
# 2. create a personal access token at https://api.planningcenteronline.com/oauth/applications
# 3. edit the app id and secret below
#
# usage:
# ruby people_list_to_csv.rb listid filename.csv
#
# example:
# ruby people_list_to_csv.rb 1234 people.csv
#
require 'pco_api' # gem install pco_api
require 'csv'
PERSONAL_ACCESS_TOKEN_APP_ID = 'your app id here'
PERSONAL_ACCESS_TOKEN_SECRET = 'your secret here'
(LIST_ID, FILENAME) = ARGV
if LIST_ID.nil? || FILENAME.nil?
puts 'Usage: ruby people_list_to_csv.rb listid filename.csv'
puts 'Example: ruby people_list_to_csv.rb 1234 people.csv'
exit 1
end
API = PCO::API.new(basic_auth_token: PERSONAL_ACCESS_TOKEN_APP_ID, basic_auth_secret: PERSONAL_ACCESS_TOKEN_SECRET)
def fetch(offset = 0)
response = API.people.v2.lists[LIST_ID].people.get(offset: offset)
response['data'] + (response['meta']['next'] ? fetch(response['meta']['next']['offset']) : [])
end
CSV.open(FILENAME, 'w') do |csv|
csv << ['first name', 'last name']
fetch.each do |record|
csv << [
record['attributes']['first_name'],
record['attributes']['last_name']
]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment