Skip to content

Commit 62b3d56

Browse files
authored
updating examples - addresses PR #1345 (#1436)
- changes import statements to `import models40 as models` for examples - fixed comment formatting on a few files
1 parent a2ff13b commit 62b3d56

12 files changed

+50
-52
lines changed

examples/python/cloud-function-content-cleanup-automation/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,21 +211,21 @@ The following steps assume deployment using the Google Cloud UI Console.
211211

212212
```python
213213
import looker_sdk
214-
from looker_sdk import models40
214+
from looker_sdk import models40 as models
215215

216216
config_file = "looker.ini"
217217
sdk = looker_sdk.init40(config_file)
218218

219219
def restore_soft_delete_dashboard(dashboard_id):
220-
dashboard = models40.WriteDashboard(deleted=False)
220+
dashboard = models.WriteDashboard(deleted=False)
221221
try:
222222
sdk.update_dashboard(str(dashboard_id), body=dashboard)
223223
print(f"Successfully restored dashboard {dashboard_id}")
224224
except Exception as e:
225225
print(f"Error: {e}")
226226

227227
def restore_soft_delete_look(look_id):
228-
look = models40.WriteLookWithQuery(deleted=False)
228+
look = models.WriteLookWithQuery(deleted=False)
229229
try:
230230
sdk.update_look(str(look_id), body=look)
231231
print(f"Successfully restored look {look_id}")

examples/python/cloud-function-content-cleanup-automation/main.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
- Update NOTIFICATION_EMAIL_ADDRESS (email address for content deletion notification).
1313
- Toggle dry run of automation off/on.
1414
15-
Last modified: March 2023
15+
Last modified: Feb 27 2024
1616
"""
1717

1818
import looker_sdk
19-
from looker_sdk import models40
19+
from looker_sdk import models40 as models
2020
from looker_sdk import error
2121
from google.cloud import storage
2222
from google.cloud import exceptions
@@ -85,7 +85,7 @@ def get_unused_content_query_id(days: int):
8585
""" Get a re-useable query ID for a System Activity query which returns all content that hasn't been used in at least 90 (default) days.
8686
This query ID can be used to run the query and send a schedule with the query's results.
8787
"""
88-
unused_content_query = models40.WriteQuery(
88+
unused_content_query = models.WriteQuery(
8989
model="system__activity",
9090
view="content_usage",
9191
fields=[
@@ -128,7 +128,7 @@ def get_deleted_content_query_id(days: int):
128128
""" Get a re-usable query ID for a System Activity query which returns all content that's been soft deleted for 90+ (default) days.
129129
This query ID can be used to run the query and send a schedule with the query's results.
130130
"""
131-
deleted_query = models40.WriteQuery(
131+
deleted_query = models.WriteQuery(
132132
model="system__activity",
133133
view="content_usage",
134134
fields=[
@@ -180,7 +180,7 @@ def send_content_notification(query_id: str, delete_type: str, address: str):
180180
"""
181181
created_date = datetime.today().strftime('%Y-%m-%d')
182182

183-
scheduled_plan_destination_body = models40.ScheduledPlanDestination(
183+
scheduled_plan_destination_body = models.ScheduledPlanDestination(
184184
format="csv",
185185
type="email",
186186
address=address,
@@ -189,7 +189,7 @@ def send_content_notification(query_id: str, delete_type: str, address: str):
189189
apply_formatting=False,
190190
apply_vis=False
191191
)
192-
unused_content_notification = models40.WriteScheduledPlan(
192+
unused_content_notification = models.WriteScheduledPlan(
193193
name=f"[Looker Automation] {delete_type.capitalize()} deleted content ({created_date}).",
194194
query_id=query_id,
195195
scheduled_plan_destination=[
@@ -230,8 +230,8 @@ def get_look_ids(content: list):
230230
def soft_delete_dashboard(dashboard_id: str):
231231
""" Soft delete the given dashboard. """
232232
# todo: to toggle off safe mode and soft delete dashboards, comment out `deleted=False`` line and uncomment `deleted=True` line
233-
dashboard = models40.WriteDashboard(deleted=False)
234-
# dashboard = models40.WriteDashboard(deleted=True)
233+
dashboard = models.WriteDashboard(deleted=False)
234+
# dashboard = models.WriteDashboard(deleted=True)
235235
try:
236236
sdk.update_dashboard(dashboard_id, body=dashboard)
237237
print(f"Successfully soft deleted dashboard: {dashboard_id}")
@@ -242,8 +242,8 @@ def soft_delete_dashboard(dashboard_id: str):
242242
def soft_delete_look(look_id: str):
243243
""" Soft delete the given look. """
244244
# todo: to toggle off safe mode and soft delete Looks, comment out `deleted=False`` line and uncomment `deleted=True` line
245-
look = models40.WriteLookWithQuery(deleted=False)
246-
# look = models40.WriteLookWithQuery(deleted=True)
245+
look = models.WriteLookWithQuery(deleted=False)
246+
# look = models.WriteLookWithQuery(deleted=True)
247247
try:
248248
sdk.update_look(look_id, body=look)
249249
print(f"Successfully soft deleted Look: {look_id}")

examples/python/content_validator_comparison.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import looker_sdk
2-
from looker_sdk import models
2+
from looker_sdk import models40 as models
33
import configparser
44
import hashlib
55
import csv

examples/python/create_db_connections.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import looker_sdk
2-
from looker_sdk import models
2+
from looker_sdk import models40 as models
33
import base64
44

55
with open("credentials_file.json", "rb") as f:

examples/python/download_dashboard_pdf.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
$ python download_dashboard_pdf.py "A Test Dashboard" '{"filter1": "value1, value2", "filter2": "value3"}'
99
$ python download_dashboard_pdf.py "A Test Dashboard" {} "single_column"
1010
11-
Last modified: August 25, 2021
11+
Last modified: Feb 27 2024
1212
"""
1313

1414
import json
@@ -19,11 +19,10 @@
1919
from typing import cast, Dict, Optional
2020

2121
import looker_sdk
22-
from looker_sdk import models
22+
from looker_sdk import models40 as models
2323

2424
sdk = looker_sdk.init40("../../looker.ini")
2525

26-
2726
def main():
2827
dashboard_title = sys.argv[1] if len(sys.argv) > 1 else ""
2928
filters = json.loads(sys.argv[2]) if len(sys.argv) > 2 else None

examples/python/download_look.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
$ python download_look.py "A simple look"
88
$ python download_look.py "A simple look" 545 842 png
99
10-
Last modified: August 25, 2021
10+
Last modified: Feb 27 2024
1111
"""
1212

1313
import sys
1414
import textwrap
1515
import time
1616

1717
import looker_sdk
18-
from looker_sdk import models
18+
from looker_sdk import models40 as models
1919

2020
sdk = looker_sdk.init40("../../looker.ini")
2121

examples/python/download_tile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import time
33

44
import looker_sdk
5-
from looker_sdk import models
5+
from looker_sdk import models40 as models
66
from looker_sdk.rtl import transport
77

88
class MyTransportOptions(transport.PTransportSettings): timeout = 300

examples/python/kill_queries.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@
99
1010
Authors: Lan
1111
12-
Last modified: July 18, 2021
12+
Last modified: Feb 27 2024
1313
"""
1414

1515
import looker_sdk
16-
from looker_sdk import models40
1716
sdk = looker_sdk.init40(config_file='../looker.ini', section='Looker')
1817

1918

examples/python/logout_all_users.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from typing import cast, Sequence
22

33
import looker_sdk
4-
from looker_sdk import models
54

5+
from looker_sdk import models40 as models
66

77
sdk = looker_sdk.init40("../../looker.ini")
88

examples/python/manage_schedules.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
1212
Authors: Lan
1313
14-
Last modified: July 18, 2021
14+
Last modified: Feb 27 2024
1515
"""
1616

1717
import looker_sdk
18-
from looker_sdk import models40
18+
from looker_sdk import models40 as models
1919
sdk = looker_sdk.init40(config_file='../looker.ini', section='Looker')
2020

2121

@@ -41,25 +41,25 @@ def get_schedules(id, content, user_id=None, all_users=True):
4141

4242
def resume_schedules(id, content, enabled, user_id=None, all_users=True):
4343

44-
""" Pause or resume all schedules of a Look, or a dashboard
45-
46-
Args:
47-
id: id of the Looker content containing schedules
48-
content(str): 'look', 'dashboard', or 'lookml_dashboard'
49-
enabled (bool): set "True" to resume schedule, or "False" to pause schedule
50-
51-
Notes: Schedules with "enabled = False" will disappear from Admin > Schedules in Looker UI but
52-
their data can be retrived in Looker's System Activity. Once schedules are resumed with "enabled = True",
53-
they will be sent once and reappear in Admin > Schedules
54-
"""
44+
""" Pause or resume all schedules of a Look, or a dashboard
45+
46+
Args:
47+
id: id of the Looker content containing schedules
48+
content(str): 'look', 'dashboard', or 'lookml_dashboard'
49+
enabled (bool): set "True" to resume schedule, or "False" to pause schedule
50+
51+
Notes: Schedules with "enabled = False" will disappear from Admin > Schedules in Looker UI but
52+
their data can be retrived in Looker's System Activity. Once schedules are resumed with "enabled = True",
53+
they will be sent once and reappear in Admin > Schedules
54+
"""
5555

5656
"Get all schedules of a Looker content"
5757
schedules = get_schedules(id=id, content=content)
5858

5959
for i in range(0, len(schedules)):
6060
sdk.update_scheduled_plan(
6161
scheduled_plan_id=schedules[i]['id'],
62-
body=models40.WriteScheduledPlan(
62+
body=models.WriteScheduledPlan(
6363
enabled = enabled
6464
))
6565

@@ -70,16 +70,16 @@ def resume_schedules(id, content, enabled, user_id=None, all_users=True):
7070

7171
def copy_schedules(from_id, to_id, content, user_id=None, all_users=True):
7272

73-
""" Copy schedules from one Looker content to another content.
74-
This script has only been tested for content of the same type (i.e.: look to look, dashboard to dashboard)
73+
""" Copy schedules from one Looker content to another content.
74+
This script has only been tested for content of the same type (i.e.: look to look, dashboard to dashboard)
7575
76-
Args:
77-
from_id: id of the Looker content containing schedules
78-
to_id: id of the Looker content which schedules will be copied to
79-
content(str): 'look', 'dashboard', or 'lookml_dashboard'
80-
user_id(int, optional): If user_id is None then schedules owned by the user calling the API will be returned
81-
all_users(bool, optional): If all_user is True then return schedules owned by all users
82-
"""
76+
Args:
77+
from_id: id of the Looker content containing schedules
78+
to_id: id of the Looker content which schedules will be copied to
79+
content(str): 'look', 'dashboard', or 'lookml_dashboard'
80+
user_id(int, optional): If user_id is None then schedules owned by the user calling the API will be returned
81+
all_users(bool, optional): If all_user is True then return schedules owned by all users
82+
"""
8383

8484
"Get all schedules of a Looker content"
8585
schedules = get_schedules(id=from_id, content=content, user_id=user_id, all_users=all_users)
@@ -88,7 +88,7 @@ def copy_schedules(from_id, to_id, content, user_id=None, all_users=True):
8888
for i in range(0, len(schedules)):
8989

9090
# Write the base schedule plans with all required fields
91-
body = models40.WriteScheduledPlan(
91+
body = models.WriteScheduledPlan(
9292

9393
# Required fields for all content type
9494
name = schedules[i]['name'],
@@ -110,7 +110,7 @@ def copy_schedules(from_id, to_id, content, user_id=None, all_users=True):
110110
elif content == 'lookml_dashboard':
111111
body['lookml_dashboard_id'] = to_id
112112

113-
"""Additional parameters can be added in the models40.WriteScheduledPlan() method for 'body',
113+
"""Additional parameters can be added in the models.WriteScheduledPlan() method for 'body',
114114
or through Python's dictionary syntax: body[parameter] = value """
115115

116116

0 commit comments

Comments
 (0)