Skip to content

Commit

Permalink
Fixing the themes import script
Browse files Browse the repository at this point in the history
  • Loading branch information
geekygecko committed May 30, 2023
1 parent 2a66cbd commit 58c6f13
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 26 deletions.
2 changes: 1 addition & 1 deletion scripts/themes/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Download the google_credentials.json file from 1Password 'Android Themes script'.
Download the google_credentials.json file from our secret 'Pocket Casts - Android Themes Script'.
```
./run.sh
```
29 changes: 4 additions & 25 deletions scripts/themes/download_themes.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
require "google/apis/sheets_v4"
require "googleauth"
require "googleauth/stores/file_token_store"
require "fileutils"

OOB_URI = "urn:ietf:wg:oauth:2.0:oob".freeze
APPLICATION_NAME = "Google Sheets API Pocket Casts Themes".freeze
CREDENTIALS_PATH = "google_credentials.json".freeze
# The file token.yaml stores the user's access and refresh tokens, and is
# created automatically when the authorization flow completes for the first
# time.
TOKEN_PATH = "token.yaml".freeze
SCOPE = Google::Apis::SheetsV4::AUTH_SPREADSHEETS_READONLY

class String
Expand All @@ -18,24 +12,6 @@ def uncapitalize
end
end

def authorize()
client_id = Google::Auth::ClientId.from_file CREDENTIALS_PATH
token_store = Google::Auth::Stores::FileTokenStore.new file: TOKEN_PATH
authorizer = Google::Auth::UserAuthorizer.new client_id, SCOPE, token_store
user_id = "default"
credentials = authorizer.get_credentials user_id
if credentials.nil?
url = authorizer.get_authorization_url base_url: OOB_URI
puts "Open the following URL in the browser and enter the " \
"resulting code after authorization:\n" + url
code = gets
credentials = authorizer.get_and_store_credentials_from_code(
user_id: user_id, code: code, base_url: OOB_URI
)
end
credentials
end

def response_to_tokens_map(response)
tokens = []
response.values.each do |row|
Expand Down Expand Up @@ -108,7 +84,10 @@ def download_themes()
# Initialize the API
service = Google::Apis::SheetsV4::SheetsService.new
service.client_options.application_name = APPLICATION_NAME
service.authorization = authorize
service.authorization = Google::Auth::ServiceAccountCredentials.make_creds(
json_key_io: File.open(CREDENTIALS_PATH),
scope: Google::Apis::SheetsV4::AUTH_SPREADSHEETS_READONLY
)

# https://docs.google.com/spreadsheets/d/1BZWwQo8ZhTt9jRz5eX6iJqt4r9o6ekWeYi_t8AlNDCM/edit
spreadsheet_id = "1BZWwQo8ZhTt9jRz5eX6iJqt4r9o6ekWeYi_t8AlNDCM"
Expand Down

0 comments on commit 58c6f13

Please sign in to comment.