@@ -4,7 +4,7 @@ Currently supports Python 2.7 :snake::snake::snake:
4
4
5
5
## Installation
6
6
``` bash
7
- $ pip install google-objects
7
+ $ pip install google-objects
8
8
```
9
9
10
10
## Usage
@@ -15,143 +15,140 @@ Requires a valid Google API Credentials object from Google's excellent oauth2lib
15
15
- [x] Retrieve drive 'About' information:
16
16
17
17
``` python
18
- from google_objects import DriveAPI
18
+ from google_objects import DriveAPI
19
19
20
- gdrive = DriveAPI(OAUTH2LIB_CREDS )
21
- about = gdrive.get_about()
20
+ gdrive = DriveAPI(OAUTH2LIB_CREDS )
21
+ about = gdrive.get_about()
22
22
23
- print about.email
24
- print about.name
23
+ print about.email
24
+ print about.name
25
25
26
- # prints link to profile photo
27
- print about.photo
26
+ # prints link to profile photo
27
+ print about.photo
28
28
29
- # ...
29
+ # ...
30
30
```
31
31
32
32
- [x] List files in drive by type:
33
33
34
34
``` python
35
- files_by_type = {
36
- ' slides' : gdrive.list_files(' presentation' ),
37
- ' folders' : gdrive.list_files(' folder' ),
38
- ' spreadsheets' : gdrive.list_files(' spreadsheets' ),
39
- }
35
+ files_by_type = {
36
+ ' slides' : gdrive.list_files(' presentation' ),
37
+ ' folders' : gdrive.list_files(' folder' ),
38
+ ' spreadsheets' : gdrive.list_files(' spreadsheets' ),
39
+ }
40
40
41
- for file in files_by_type[' folders' ]:
42
- print file .id
43
- print file .name
41
+ for file in files_by_type[' folders' ]:
42
+ print file .id
43
+ print file .name
44
44
45
- for file in files_by_type[' spreadsheets' ]:
46
- # prints list of parent folder IDs
47
- print file .parents
45
+ for file in files_by_type[' spreadsheets' ]:
46
+ # prints list of parent folder IDs
47
+ print file .parents
48
48
49
- # ...
49
+ # ...
50
50
```
51
51
52
52
- [x] Copy and share file:
53
53
54
54
``` python
55
- file = gdrive.get_file(' FILE_ID' )
56
- new_file = file .copy(' NEW_FILE_NAME' , [' PARENT_FOLDER_1' , ' PARENT_FOLDER_2' ])
57
-
58
- # allow myfriend@hotmail.com to view
59
- permission = new_file.add_permission(' myfriend@hotmail.com' )
60
-
61
- # print newly created permission information
62
- print permission.role, permission.type, permission.email
55
+ file = gdrive.get_file(' FILE_ID' )
56
+ new_file = file .copy(' NEW_FILE_NAME' , [' PARENT_FOLDER_1' , ' PARENT_FOLDER_2' ])
57
+
58
+ # allow myfriend@hotmail.com to view
59
+ permission = new_file.add_permission(' myfriend@hotmail.com' )
60
+
61
+ # print newly created permission information
62
+ print permission.role, permission.type, permission.email
63
63
```
64
64
65
65
### Google Slides v1
66
66
67
67
- [x] Retrieve presentation and loop through elements:
68
68
69
69
``` python
70
- from google_objects import SlidesAPI
70
+ from google_objects import SlidesAPI
71
71
72
- gslides = SlidesAPI(OAUTHLIB_CREDS )
73
- presentation = gslides.get_presentation(' PRESENTATION_ID' )
72
+ gslides = SlidesAPI(OAUTHLIB_CREDS )
73
+ presentation = gslides.get_presentation(' PRESENTATION_ID' )
74
74
75
- # print slides attributes
76
- for slide in presentation:
77
- print slide.id
75
+ # print slides attributes
76
+ for slide in presentation:
77
+ print slide.id
78
78
79
- for element in slide: # equivalent to 'for element in presentation.elements()'
80
- print element.type
81
- # Shape, Table, etc
82
-
79
+ for element in slide: # equivalent to 'for element in presentation.elements()'
80
+ print element.type
81
+ # Shape, Table, etc
83
82
```
84
83
85
84
- [x] Check text in shape:
86
85
87
86
``` python
88
- shape = presentation.get_element_by_id(' SHAPE_ID' )
89
- for segment in shape.text:
90
- print segment.text
91
-
87
+ shape = presentation.get_element_by_id(' SHAPE_ID' )
88
+ for segment in shape.text:
89
+ print segment.text
92
90
```
93
91
94
92
- [x] Batch update every cell in table:
95
93
96
94
``` python
97
- # use with to perform batch updates in block
98
- with presentation as pres:
99
- table = pres.get_element_by_id(' TABLE_ID' )
100
- for cell in table:
101
- print cell.location # tuple containing cell location
102
- for segment in cell.text:
103
- # update cell
104
- segment.text = ' UPDATED_VALUE'
105
-
95
+ # use with to perform batch updates in block
96
+ with presentation as pres:
97
+ table = pres.get_element_by_id(' TABLE_ID' )
98
+ for cell in table:
99
+ print cell.location # tuple containing cell location
100
+ for segment in cell.text:
101
+ # update cell
102
+ segment.text = ' UPDATED_VALUE'
106
103
```
107
104
108
105
### Google Sheets v4
109
106
110
107
- [x] Retrieve spreadsheet and loop through sheets:
111
108
112
109
``` python
113
- from google_objects import SheetsAPI
110
+ from google_objects import SheetsAPI
114
111
115
- gsheets = SheetsAPI(OAUTHLIB_CREDS )
116
- spreadsheet = gsheets.get_spreadsheet(' SPREADSHEET_ID' )
112
+ gsheets = SheetsAPI(OAUTHLIB_CREDS )
113
+ spreadsheet = gsheets.get_spreadsheet(' SPREADSHEET_ID' )
117
114
118
- for sheet in spreadsheet:
119
- print sheet.id, sheet.title
115
+ for sheet in spreadsheet:
116
+ print sheet.id, sheet.title
120
117
```
121
118
122
119
- [x] Get sheet by name and return its full block of values:
123
120
124
121
``` python
125
- sheet = spreadsheet[' Sheet 1' ]
126
- values = sheet.values()
122
+ sheet = spreadsheet[' Sheet 1' ]
123
+ values = sheet.values()
127
124
```
128
125
129
126
- [x] Get named range value block:
130
127
131
128
``` python
132
- named_ranges = spreadsheet.named_ranges(' SHEET_NAME!A:C' )
133
- for rng in named_range:
134
- values = named_range.get_block()
129
+ named_ranges = spreadsheet.named_ranges(' SHEET_NAME!A:C' )
130
+ for rng in named_range:
131
+ values = named_range.get_block()
135
132
```
136
133
137
134
- [x] Update values block:
138
135
139
136
``` python
140
- values = spreadsheet.get_range(' SHEET_NAME!A:C' )
141
- # loop through rows
142
- for i, row in enumerate (values):
143
- values[i] = [1 , 2 , 3 ]
144
- print row
145
- values.update()
146
-
147
- # you can also use the slice syntax for updating..
148
- values[2 :5 ] = [[1 ,2 ,4 ], [4 , 5 , 6 ], [6 , 7 , 8 ]]
149
- values.update()
137
+ values = spreadsheet.get_range(' SHEET_NAME!A:C' )
138
+ # loop through rows
139
+ for i, row in enumerate (values):
140
+ values[i] = [1 , 2 , 3 ]
141
+ print row
142
+ values.update()
143
+
144
+ # you can also use the slice syntax for updating..
145
+ values[2 :5 ] = [[1 ,2 ,4 ], [4 , 5 , 6 ], [6 , 7 , 8 ]]
146
+ values.update()
150
147
```
151
148
152
149
- [x] Append to values block:
153
150
154
151
``` python
155
- to_append = [[1 , 2 , 3 ], [4 , 5 , 6 ]]
156
- values.append(to_append)
152
+ to_append = [[1 , 2 , 3 ], [4 , 5 , 6 ]]
153
+ values.append(to_append)
157
154
```
0 commit comments