-
Notifications
You must be signed in to change notification settings - Fork 21
/
build.py
executable file
·36 lines (33 loc) · 1.8 KB
/
build.py
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
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python3
#
# Copyright this project and it's contributors
# SPDX-License-Identifier: Apache-2.0
#
# encoding=utf8
from __future__ import print_function
import os.path
import requests
# The ID of a sample document.
documents = [
{'id':'1Zk3REYGnE6mYIXl52QxzNbVW7XM2NPs_1w7YxscRXrk','mimeType':'application/pdf','filename':'Open Mainframe Project - Overview.pdf'},
{'id':'1Zk3REYGnE6mYIXl52QxzNbVW7XM2NPs_1w7YxscRXrk','mimeType':'application/vnd.openxmlformats-officedocument.presentationml.presentation','filename':'Open Mainframe Project - Overview.pptx'},
{'id':'18l_SwTF3LOEzoYyi0fMX-Wve2GIZb1cLQswJCZEjN9M','mimeType':'application/pdf','filename':'Open Mainframe Project - TAC Overview.pdf'},
{'id':'1x8f47QPzhuIP9LM9QthYih8VoJhJvPAAXoy6nW0uF6c','mimeType':'application/pdf','filename':'Open Mainframe Project - Governing Board Overview.pdf'},
{'id':'1SW-JbXTQgwb_OczGeyo5jqc6GmK5CLmBTzg0pb0vMXs','mimeType':'application/pdf','filename':'Open Mainframe Project - Membership Overview.pdf'},
]
# Retrieve the documents contents from the Docs service.
for document in documents:
print("Getting file {}...".format(document['filename']))
try:
match document['mimeType']:
case 'application/pdf':
exportFormat = 'pdf'
case 'application/vnd.openxmlformats-officedocument.presentationml.presentation':
exportFormat = 'pptx'
case _:
continue
contents = requests.get('https://docs.google.com/feeds/download/presentations/Export?id={docid}&exportFormat={exportFormat}'.format(docid=document['id'],exportFormat=exportFormat),stream=False)
with open(document['filename'], 'wb') as f:
f.write(contents.content)
except HttpError as err:
print(err.content)