-
Notifications
You must be signed in to change notification settings - Fork 0
/
dropbox_IO_module.py
50 lines (40 loc) · 1.41 KB
/
dropbox_IO_module.py
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
38
39
40
41
42
43
44
45
46
47
48
49
import os
import dropbox
from dropbox import files
from dotenv import load_dotenv
import threading
# load .env
load_dotenv()
app_key = os.environ.get("app_key")
app_secret = os.environ.get("app_secret")
oauth2_refresh_token = os.environ.get("oauth2_refresh_token")
dbx = dropbox.Dropbox(
app_key=app_key,
app_secret=app_secret,
oauth2_refresh_token=oauth2_refresh_token
)
# dbx.check_and_refresh_access_token()
path = os.getcwd()
def update_tasks():
try:
for entry in dbx.files_list_folder('/working_time').entries:
dbx.files_download_to_file(path+"\\"+entry.name, "/working_time/"+entry.name)
print(f"The {entry.name} has been updated")
except Exception as e:
print(e)
print("Updating process goes wrong")
def upload_tasks():
print("Sending data to the cloud")
try:
binary_file = open("data_tasks_time.json", mode="rb")
dbx.files_upload(binary_file.read(), "/working_time/data_tasks_time.json", mode=files.WriteMode.overwrite)
print("Sending is successful")
except Exception as e:
print("Sending process goes wrong")
print(e)
def parallel_updating():
print("Work time file is updating...")
updating = threading.Thread(target=update_tasks)
updating.start()
updating.join()
print("Update is finished.")