Skip to content

Commit

Permalink
fix: run pyink, autoflake, flynt and remove from __future__
Browse files Browse the repository at this point in the history
  • Loading branch information
jpoehnelt committed Nov 6, 2023
1 parent 8131e63 commit 8ac4994
Show file tree
Hide file tree
Showing 214 changed files with 6,682 additions and 6,523 deletions.
77 changes: 39 additions & 38 deletions admin_sdk/directory/quickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
# limitations under the License.

# [START admin_sdk_directory_quickstart]
from __future__ import print_function

import os.path

from google.auth.transport.requests import Request
Expand All @@ -23,48 +21,51 @@
from googleapiclient.discovery import build

# If modifying these scopes, delete the file token.json.
SCOPES = ['https://www.googleapis.com/auth/admin.directory.user']
SCOPES = ["https://www.googleapis.com/auth/admin.directory.user"]


def main():
"""Shows basic usage of the Admin SDK Directory API.
Prints the emails and names of the first 10 users in the domain.
"""
creds = None
# The file token.json stores the user's access and refresh tokens, and is
# created automatically when the authorization flow completes for the first
# time.
if os.path.exists('token.json'):
creds = Credentials.from_authorized_user_file('token.json', SCOPES)
# If there are no (valid) credentials available, let the user log in.
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
else:
flow = InstalledAppFlow.from_client_secrets_file(
'credentials.json', SCOPES)
creds = flow.run_local_server(port=0)
# Save the credentials for the next run
with open('token.json', 'w') as token:
token.write(creds.to_json())
"""Shows basic usage of the Admin SDK Directory API.
Prints the emails and names of the first 10 users in the domain.
"""
creds = None
# The file token.json stores the user's access and refresh tokens, and is
# created automatically when the authorization flow completes for the first
# time.
if os.path.exists("token.json"):
creds = Credentials.from_authorized_user_file("token.json", SCOPES)
# If there are no (valid) credentials available, let the user log in.
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
else:
flow = InstalledAppFlow.from_client_secrets_file(
"credentials.json", SCOPES
)
creds = flow.run_local_server(port=0)
# Save the credentials for the next run
with open("token.json", "w") as token:
token.write(creds.to_json())

service = build('admin', 'directory_v1', credentials=creds)
service = build("admin", "directory_v1", credentials=creds)

# Call the Admin SDK Directory API
print('Getting the first 10 users in the domain')
results = service.users().list(customer='my_customer', maxResults=10,
orderBy='email').execute()
users = results.get('users', [])
# Call the Admin SDK Directory API
print("Getting the first 10 users in the domain")
results = (
service.users()
.list(customer="my_customer", maxResults=10, orderBy="email")
.execute()
)
users = results.get("users", [])

if not users:
print('No users in the domain.')
else:
print('Users:')
for user in users:
print(u'{0} ({1})'.format(user['primaryEmail'],
user['name']['fullName']))
if not users:
print("No users in the domain.")
else:
print("Users:")
for user in users:
print(f"{user['primaryEmail']} ({user['name']['fullName']})")


if __name__ == '__main__':
main()
if __name__ == "__main__":
main()
# [END admin_sdk_directory_quickstart]
83 changes: 45 additions & 38 deletions admin_sdk/reports/quickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
# limitations under the License.

# [START admin_sdk_reports_quickstart]
from __future__ import print_function

import os.path

from google.auth.transport.requests import Request
Expand All @@ -23,48 +21,57 @@
from googleapiclient.discovery import build

# If modifying these scopes, delete the file token.json.
SCOPES = ['https://www.googleapis.com/auth/admin.reports.audit.readonly']
SCOPES = ["https://www.googleapis.com/auth/admin.reports.audit.readonly"]


def main():
"""Shows basic usage of the Admin SDK Reports API.
Prints the time, email, and name of the last 10 login events in the domain.
"""
creds = None
# The file token.json stores the user's access and refresh tokens, and is
# created automatically when the authorization flow completes for the first
# time.
if os.path.exists('token.json'):
creds = Credentials.from_authorized_user_file('token.json', SCOPES)
# If there are no (valid) credentials available, let the user log in.
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
else:
flow = InstalledAppFlow.from_client_secrets_file(
'credentials.json', SCOPES)
creds = flow.run_local_server(port=0)
# Save the credentials for the next run
with open('token.json', 'w') as token:
token.write(creds.to_json())
"""Shows basic usage of the Admin SDK Reports API.
Prints the time, email, and name of the last 10 login events in the domain.
"""
creds = None
# The file token.json stores the user's access and refresh tokens, and is
# created automatically when the authorization flow completes for the first
# time.
if os.path.exists("token.json"):
creds = Credentials.from_authorized_user_file("token.json", SCOPES)
# If there are no (valid) credentials available, let the user log in.
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
else:
flow = InstalledAppFlow.from_client_secrets_file(
"credentials.json", SCOPES
)
creds = flow.run_local_server(port=0)
# Save the credentials for the next run
with open("token.json", "w") as token:
token.write(creds.to_json())

service = build('admin', 'reports_v1', credentials=creds)
service = build("admin", "reports_v1", credentials=creds)

# Call the Admin SDK Reports API
print('Getting the last 10 login events')
results = service.activities().list(userKey='all', applicationName='login',
maxResults=10).execute()
activities = results.get('items', [])
# Call the Admin SDK Reports API
print("Getting the last 10 login events")
results = (
service.activities()
.list(userKey="all", applicationName="login", maxResults=10)
.execute()
)
activities = results.get("items", [])

if not activities:
print('No logins found.')
else:
print('Logins:')
for activity in activities:
print(u'{0}: {1} ({2})'.format(activity['id']['time'],
activity['actor']['email'], activity['events'][0]['name']))
if not activities:
print("No logins found.")
else:
print("Logins:")
for activity in activities:
print(
"{0}: {1} ({2})".format(
activity["id"]["time"],
activity["actor"]["email"],
activity["events"][0]["name"],
)
)


if __name__ == '__main__':
main()
if __name__ == "__main__":
main()
# [END admin_sdk_reports_quickstart]
78 changes: 41 additions & 37 deletions admin_sdk/reseller/quickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
# limitations under the License.

# [START admin_sdk_reseller_quickstart]
from __future__ import print_function

import os.path

from google.auth.transport.requests import Request
Expand All @@ -23,46 +21,52 @@
from googleapiclient.discovery import build

# If modifying these scopes, delete the file token.json.
SCOPES = ['https://www.googleapis.com/auth/apps.order']
SCOPES = ["https://www.googleapis.com/auth/apps.order"]


def main():
"""Calls the Admin SDK Reseller API. Prints the customer ID, SKU ID,
and plan name of the first 10 subscriptions managed by the domain.
"""
creds = None
# The file token.json stores the user's access and refresh tokens, and is
# created automatically when the authorization flow completes for the first
# time.
if os.path.exists('token.json'):
creds = Credentials.from_authorized_user_file('token.json', SCOPES)
# If there are no (valid) credentials available, let the user log in.
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
else:
flow = InstalledAppFlow.from_client_secrets_file(
'credentials.json', SCOPES)
creds = flow.run_local_server(port=0)
# Save the credentials for the next run
with open('token.json', 'w') as token:
token.write(creds.to_json())
"""Calls the Admin SDK Reseller API. Prints the customer ID, SKU ID,
and plan name of the first 10 subscriptions managed by the domain.
"""
creds = None
# The file token.json stores the user's access and refresh tokens, and is
# created automatically when the authorization flow completes for the first
# time.
if os.path.exists("token.json"):
creds = Credentials.from_authorized_user_file("token.json", SCOPES)
# If there are no (valid) credentials available, let the user log in.
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
else:
flow = InstalledAppFlow.from_client_secrets_file(
"credentials.json", SCOPES
)
creds = flow.run_local_server(port=0)
# Save the credentials for the next run
with open("token.json", "w") as token:
token.write(creds.to_json())

service = build('reseller', 'v1', credentials=creds)
service = build("reseller", "v1", credentials=creds)

# Call the Admin SDK Reseller API
print('Getting the first 10 subscriptions')
results = service.subscriptions().list(maxResults=10).execute()
subscriptions = results.get('subscriptions', [])
if not subscriptions:
print('No subscriptions found.')
else:
print('Subscriptions:')
for subscription in subscriptions:
print(u'{0} ({1}, {2})'.format(subscription['customerId'],
subscription['skuId'], subscription['plan']['planName']))
# Call the Admin SDK Reseller API
print("Getting the first 10 subscriptions")
results = service.subscriptions().list(maxResults=10).execute()
subscriptions = results.get("subscriptions", [])
if not subscriptions:
print("No subscriptions found.")
else:
print("Subscriptions:")
for subscription in subscriptions:
print(
"{0} ({1}, {2})".format(
subscription["customerId"],
subscription["skuId"],
subscription["plan"]["planName"],
)
)


if __name__ == '__main__':
main()
if __name__ == "__main__":
main()
# [END admin_sdk_reseller_quickstart]
Loading

0 comments on commit 8ac4994

Please sign in to comment.