-
-
Save RChloe/f2c739bf4416b01f90cd07838c7316b2 to your computer and use it in GitHub Desktop.
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
from tekdrive import TekDrive | |
from datetime import date | |
import os | |
# Put your access key (with `directory:read` claim) and file id here | |
ACCESS_KEY = "YOUR_ACCESS_KEY" | |
here = os.path.dirname(__file__) | |
def main(): | |
# set up access key authorizer | |
td = TekDrive( | |
access_key=ACCESS_KEY | |
) | |
# find folder with scope measurements to be analyzed | |
results = td.search.folders(name="to_be_analyzed") | |
results_list = list(results) | |
folder_to_analyze_id = results_list[0].id | |
# initialize folder instance with found id | |
folder_to_analyze = td.folder(folder_to_analyze_id) | |
# grab current date to label and create new folder | |
today=date.today() | |
folder_name = "analyzed-"+today.strftime("%b%d%Y") | |
folder_final = td.folder.create(folder_name) | |
# iterate over each file in the folder | |
for child in folder_to_analyze.children(): | |
file = td.file(child.id) | |
# create a new local file and download file contents from TekDrive | |
with open(file.name,"w"): | |
contents_path = os.path.join(here, file.name) | |
file.download(contents_path) | |
# move the file in TekDrive to a different folder to show that it's been downloaded | |
file.move(folder_final['folder']['id']) | |
# analyze files locally or in TekScope | |
# upload analyzed files to TekDrive/TekScope | |
folder_path = os.path.join(here, "analyzed_files") | |
parent_folder_id = folder_to_analyze.parent_folder_id | |
parent_folder = td.folder(parent_folder_id) | |
for file in os.listdir(folder_path): | |
file_path = os.path.join(folder_path,file) | |
parent_folder.upload(file_path, file) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment