Last active
February 27, 2019 11:45
-
-
Save vperezb/2964b0bbcac543b62fe376a1cec259de to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def text_replace(old: str, new: str, presentation_id: str, pages: list = []): | |
| slides_service = get_service( | |
| secrets_path, | |
| 'https://www.googleapis.com/auth/presentations', | |
| 'presentations', | |
| 'v1' | |
| ) | |
| service.presentations().batchUpdate( | |
| body={ | |
| "requests": [ | |
| { | |
| "replaceAllText": { | |
| "containsText": { | |
| "text": old | |
| }, | |
| "replaceText": new, | |
| "pageObjectIds": pages, | |
| } | |
| } | |
| ] | |
| }, | |
| presentationId=presentation_id | |
| ).execute() | |
| def batch_text_replace(text_mapping: dict, presentation_id: str, pages: list = list()): | |
| """Given a list of tuples with replacement pairs this function replace it all""" | |
| requests = [] | |
| for placeholder_text, new_value in text_mapping.items(): | |
| if type(new_value) is str: | |
| requests += [ | |
| { | |
| "replaceAllText": { | |
| "containsText": { | |
| "text": '{{' + placeholder_text + '}}' | |
| }, | |
| "replaceText": new_value, | |
| "pageObjectIds": pages | |
| } | |
| } | |
| ] | |
| else: | |
| raise Exception('The text from key {} is not a string'.format(placeholder_text)) | |
| return execute_batch_update(requests, presentation_id) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment