-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added logic to upload <wspr_spot_data.csv> to Google Drive.
- Loading branch information
1 parent
67430a3
commit 9d3fa0e
Showing
5 changed files
with
55 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
.terraform | ||
*.tfstate | ||
.env | ||
service_account.json | ||
# Added by cargo | ||
|
||
/target | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
class CONSTANTS: | ||
FILE_PATH = "./tableau/data" | ||
FILE_NAME = "wspr_spots.csv" | ||
FILE_PATH = "./tableau/data" | ||
FILE_NAME = "wspr_spot_data.csv" | ||
FULL_PATH = FILE_PATH + "/" + FILE_NAME | ||
SCOPES = ["https://www.googleapis.com/auth/drive"] | ||
SERVICE_ACCOUNT_FILE = "service_account.json" | ||
PARENT_FOLDER_ID = "1uVnscmoxu91XT1LMnZoOOn3iCTirlEII" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import constants | ||
from google.oauth2 import service_account | ||
from googleapiclient.discovery import build | ||
|
||
|
||
def authenticate(): | ||
try: | ||
print("\n[Authenticating] <wspr_cdk> service user...") | ||
|
||
credentials = service_account.Credentials.from_service_account_file( | ||
constants.SERVICE_ACCOUNT_FILE, scopes=constants.SCOPES | ||
) | ||
|
||
return credentials | ||
except Exception as e: | ||
print("\n[ERROR] -> Failed to [Authenticate] <wspr_cdk> service user: \n", e) | ||
|
||
|
||
def upload_to_drive(file_path): | ||
try: | ||
credentials = authenticate() | ||
service = build("drive", "v3", credentials=credentials) | ||
|
||
file_metadata = { | ||
"name": "wspr_spot_data", | ||
"parents": [constants.PARENT_FOLDER_ID], | ||
} | ||
|
||
print("[Uploading] file to Google Drive...\n") | ||
|
||
service.files().create(body=file_metadata, media_body=file_path).execute() | ||
except Exception as e: | ||
print("\n[ERROR] -> Failed to upload to Google Drive: \n", e) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters