Skip to content

Commit ebb251a

Browse files
committed
lint
1 parent efcb899 commit ebb251a

File tree

2 files changed

+67
-62
lines changed

2 files changed

+67
-62
lines changed

quickstart.py

+58-55
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,72 @@
1-
import os.path
1+
import os.path
22

3-
from google.auth.transport.requests import Request
4-
from google.oauth2.credentials import Credentials
5-
from google_auth_oauthlib.flow import InstalledAppFlow
6-
from googleapiclient.discovery import build
7-
from googleapiclient.errors import HttpError
3+
from google.auth.transport.requests import Request
4+
from google.oauth2.credentials import Credentials
5+
from google_auth_oauthlib.flow import InstalledAppFlow
6+
from googleapiclient.discovery import build
7+
from googleapiclient.errors import HttpError
88
from pprint import pprint
99

1010
# If modifying these scopes, delete the file token.json.
11-
SCOPES = ["https://www.googleapis.com/auth/drive.metadata.readonly", "https://www.googleapis.com/auth/drive"]
11+
SCOPES = [
12+
"https://www.googleapis.com/auth/drive.metadata.readonly",
13+
"https://www.googleapis.com/auth/drive",
14+
]
15+
16+
17+
def get_creds():
18+
creds = None
19+
# The file token.json stores the user's access and refresh tokens, and is
20+
# created automatically when the authorization flow completes for the first
21+
# time.
22+
if os.path.exists("token.json"):
23+
creds = Credentials.from_authorized_user_file("token.json", SCOPES)
24+
# If there are no (valid) credentials available, let the user log in.
25+
if not creds or not creds.valid:
26+
if creds and creds.expired and creds.refresh_token:
27+
creds.refresh(Request())
28+
else:
29+
flow = InstalledAppFlow.from_client_secrets_file("credentials.json", SCOPES)
30+
creds = flow.run_local_server(port=0)
31+
# Save the credentials for the next run
32+
with open("token.json", "w") as token:
33+
token.write(creds.to_json())
34+
return creds
1235

13-
def get_creds():
14-
creds = None
15-
# The file token.json stores the user's access and refresh tokens, and is
16-
# created automatically when the authorization flow completes for the first
17-
# time.
18-
if os.path.exists("token.json"):
19-
creds = Credentials.from_authorized_user_file("token.json", SCOPES)
20-
# If there are no (valid) credentials available, let the user log in.
21-
if not creds or not creds.valid:
22-
if creds and creds.expired and creds.refresh_token:
23-
creds.refresh(Request())
24-
else:
25-
flow = InstalledAppFlow.from_client_secrets_file(
26-
"credentials.json", SCOPES
27-
)
28-
creds = flow.run_local_server(port=0)
29-
# Save the credentials for the next run
30-
with open("token.json", "w") as token:
31-
token.write(creds.to_json())
32-
return creds
3336

3437
def get_service(creds):
35-
service = build("drive", "v3", credentials=creds)
36-
return service
38+
service = build("drive", "v3", credentials=creds)
39+
return service
3740

38-
def main():
39-
"""Shows basic usage of the Drive v3 API.
40-
Prints the names and ids of the first 10 files the user has access to.
41-
"""
42-
creds = get_creds()
4341

42+
def main():
43+
"""Shows basic usage of the Drive v3 API.
44+
Prints the names and ids of the first 10 files the user has access to.
45+
"""
46+
creds = get_creds()
4447

45-
try:
46-
service = get_service(creds)
48+
try:
49+
service = get_service(creds)
4750

48-
# Call the Drive v3 API
49-
results = (
50-
service.files()
51-
.list(pageSize=10, fields="nextPageToken, files(id, name)")
52-
.execute()
53-
)
54-
items = results.get("files", [])
51+
# Call the Drive v3 API
52+
results = (
53+
service.files()
54+
.list(pageSize=10, fields="nextPageToken, files(id, name)")
55+
.execute()
56+
)
57+
items = results.get("files", [])
5558

56-
if not items:
57-
print("No files found.")
58-
return
59-
print("Files:")
60-
for item in items:
61-
pprint(item)
62-
print(f"{item['name']} ({item['id']})")
63-
except HttpError as error:
64-
# TODO(developer) - Handle errors from drive API.
65-
print(f"An error occurred: {error}")
59+
if not items:
60+
print("No files found.")
61+
return
62+
print("Files:")
63+
for item in items:
64+
pprint(item)
65+
print(f"{item['name']} ({item['id']})")
66+
except HttpError as error:
67+
# TODO(developer) - Handle errors from drive API.
68+
print(f"An error occurred: {error}")
6669

6770

68-
if __name__ == "__main__":
69-
main()
71+
if __name__ == "__main__":
72+
main()

test.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,22 @@
22
from pprint import pprint
33
from dotenv import load_dotenv
44
import os
5+
import json
56

67
load_dotenv()
78

89
creds = get_creds()
910

1011

11-
service = get_service(creds)
12+
service = get_service(creds)
1213

13-
file_id = os.getenv("TEST_FILE_ID")
14+
file_id = os.getenv("TEST_FILE_ID")
1415

1516

16-
file = service.files().get(fileId=file_id).execute()
17+
comments = service.comments().list(fileId=file_id, fields="comments").execute()
1718

18-
print(file)
19-
comments = service.comments().list(fileId=file_id,fields='comments').execute()
20-
for comment in comments.get('comments'):
21-
pprint(comment)
19+
all_comments = list(comments.get("comments"))
20+
# for comment in comments.get('comments'):
21+
# pprint(comment)
22+
23+
print(json.dumps(all_comments, indent=4))

0 commit comments

Comments
 (0)