-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathdbx_integration.py
More file actions
37 lines (24 loc) · 944 Bytes
/
Copy pathdbx_integration.py
File metadata and controls
37 lines (24 loc) · 944 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import dropbox
from dotenv import load_dotenv
import sys
import os
load_dotenv()
# Your Dropbox API access token
ACCESS_TOKEN = os.getenv("TOKEN")
if not ACCESS_TOKEN:
print("You forgot to add your Dropbox credentials to the `.env` file! Add it and try again!")
sys.exit(1)
# Initialize the Dropbox client
dbx = dropbox.Dropbox(ACCESS_TOKEN)
print(
"Get your token at https://www.dropbox.com/developers/apps and ensure you have the necessary permissions ticked on!"
)
def upload_file(file_path, dropbox_path):
with open(file_path, "rb") as f:
dbx.files_upload(f.read(), dropbox_path)
print(f"File {file_path} uploaded to {dropbox_path} successfully.")
# Generate a shared link
shared_link_metadata = dbx.sharing_create_shared_link_with_settings(dropbox_path)
return shared_link_metadata.url # type: ignore
if __name__ == "__main__":
upload_file("requirements.txt", "/requirements.txt")