Skip to content

Commit

Permalink
move drive directory id to env
Browse files Browse the repository at this point in the history
  • Loading branch information
zeriyoshi committed Aug 16, 2023
1 parent e5b6b7c commit 5cfb04d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
temporary.jpg
.env
temporary
*.DS_Store
7 changes: 4 additions & 3 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# Google Drive
# ----------------------------------------------------------------
drive_service_account_key = os.environ["GOOGLE_DRIVE_SERVICE_ACCOUNT_KEY"]
drive_directory_id = os.environ["GOOGLE_DRIVE_DIRECTORY_ID"]

drive = build('drive', 'v3', credentials = service_account.Credentials.from_service_account_info(
json.loads(drive_service_account_key)).with_scopes(['https://www.googleapis.com/auth/drive']
Expand All @@ -21,7 +22,7 @@
page_token = None
while True:
response = drive.files().list(
q = "'1dNtUKp3OrhtkntOVXRhTo2gY5Vs0pkze' in parents and trashed = false",
q = "'" + drive_directory_id + "' in parents and trashed = false",
spaces = "drive",
fields = "nextPageToken, files(id)",
pageToken = page_token
Expand All @@ -36,7 +37,7 @@
id = random.choice(items)

# Download file from Google Drive
downloader = MediaIoBaseDownload(io.FileIO("temporary.jpg", "wb"), drive.files().get_media(fileId = id))
downloader = MediaIoBaseDownload(io.FileIO("temporary", "wb"), drive.files().get_media(fileId = id))
finished = False
while finished is False:
_, finished = downloader.next_chunk()
Expand Down Expand Up @@ -64,5 +65,5 @@
)

# Upload picture and Tweet
media = api_1_1.media_upload("./temporary.jpg")
media = api_1_1.media_upload("./temporary")
client_2_0.create_tweet(media_ids = [media.media_id])

0 comments on commit 5cfb04d

Please sign in to comment.