-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
27 lines (20 loc) · 869 Bytes
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
task :update_itinerary do
require 'google/apis/sheets_v4'
require 'googleauth'
# Load credentials
credentials = Google::Auth::ServiceAccountCredentials.make_creds(
json_key_io: File.open('./sheets-api-key.json'),
scope: Google::Apis::SheetsV4::AUTH_SPREADSHEETS_READONLY
)
# Authorize the client
service = Google::Apis::SheetsV4::SheetsService.new
service.authorization = credentials
spreadsheet_id = '14q0flcNjGJRw7706Y-3hu571JBuPWIU4JsjUb488YZc'
range = 'EVERYDAY!A1:B400'
response = service.get_spreadsheet_values(spreadsheet_id, range)
data = response.values
markdown_table = '| ' + data[0].join(' | ') + " |\n" +
'| ' + ('---' * data[0].length) + " |\n" +
data[1..].map { |row| '| ' + row.join(' | ') + ' |' }.join("\n")
File.write('_includes/itinerary_sheet.md', markdown_table)
end