20 Adds the last folder downloaded to root path
23 local_path (str): Root path where is saved files
24 Returns : The actual folder where files where downloaded
26 path_child = os.popen(
"ls {}".format(local_path)).read()
27 local_path_full = local_path+path_child
28 local_path_full = local_path_full.strip(
"\n")
29 local_path_renamed = local_path_full.replace(
" ",
"_")
30 os.rename(local_path_full, local_path_renamed)
31 if os.path.isdir(local_path_renamed):
32 return local_path_renamed+
"/"
36 """Downloads files uploaded directly via Otto Light interface in a temporal folder
39 event (dict): Contains the bucket and folder info where file was uploaded
40 local_path (str): Root path where is saved files
44 ACCESS_ID, ACCESS_KEY = os.environ.get(
"AWS_KEY_ID"), os.environ.get(
"AWS_KEY_SECRET")
46 s3_client = boto3.client(
"s3", aws_access_key_id=ACCESS_ID, aws_secret_access_key=ACCESS_KEY)
47 bucket = event[
"bucket"]
48 s3_path = event[
"path"]
50 if type(file) == list
and len(file) > 0:
51 uploaded_files = local_path+
"uploaded_files/"
52 if not os.path.exists(uploaded_files):
53 os.mkdir(uploaded_files)
55 s3_client.download_file(bucket, s3_path+
"/"+i, uploaded_files+i)
57 s3_client.download_file(bucket, s3_path+
"/"+file, local_path+file)
63 Transform Gdrive link to ID drive to be downloaded by Google API and execute all procedure
66 event (dict): Shared link of the folder/file to download
67 Returns : The actual folder where files where downloaded
69 _ROOT_DIR = os.path.expanduser(
'~')
70 path = _ROOT_DIR+
"/GDrive_downloads/"
71 os.makedirs(path, exist_ok=
True)
72 webhook_url = event[
"on_finish"]
74 if event[
"drive_link"] !=
"":
75 drive_link = event[
"drive_link"]
76 if "folder" in drive_link:
78 drive_link = drive_link.split(
"folders/")[-1].split(
"?usp")[0]
79 elif "file" in drive_link:
81 drive_link = drive_link.split(
"d/")[-1].split(
"/")[0]
82 elif "spreadsheets" in drive_link:
83 drive_link = drive_link.split(
"spreadsheets/d/")[-1].split(
"/")[0]
84 download_file_or_folder(drive_link, path)
89 path_output, files = clean_files(event, local_path)
90 os.system(
"rm -r {}*".format(path))
91 print(f
"Files uploaded to {path_output}")
97 return path_output, files
98 except Exception
as e:
99 raise Exception(
"An error occurred: {}".format(e))