def get_list_of_sheets(self,dir_id:str) -> list:
        """[It checks the list of files in google drive and returns the list of sheet names]

        Args:
            dir_id ([string]): [The id for the directory from which we need to take sheets]

        Returns:
            [list]: [list of sheets in directory]
        """        
        try:
            SCOPES = ['https://www.googleapis.com/auth/drive']
            SERVICE_ACCOUNT_FILE = os.getenv('SERVICE_FILE_NAME_JSON')
            credentials = service_account.Credentials.from_service_account_file(SERVICE_ACCOUNT_FILE, scopes=SCOPES)
            resource = {
            "service_account": credentials,
            "id": dir_id,
            "fields": "files(name)",
            }
            res = getfilelist.GetFileList(resource)  # or r = getfilelist.GetFolderTree(resource)
            files=res["fileList"][0]["files"]
            # The files consist a list of dictionary for all files in directory 
            sheets = [ each["name"] for each in files if "sheet" in each["name"].lower() ]
            return sheets
        except Exception as e:
            print("Process stopped as ",e)
Example #2
0
def refresh_download_list(ID):
    print("Fetching download list...")
    # using my API key
    # api_key = "AIzaSyCVfDC3KrWlV9d6fe5JMH9F6rgErX7CMOw"
    resource = {
        "drive_ipv4": "172.217.1.202",
        "api_key": "AIzaSyCVfDC3KrWlV9d6fe5JMH9F6rgErX7CMOw",
        "id": ID,
        "fields": "files(name,id)",
    }
    file_list = getfilelist.GetFileList(resource)
    with open("file_list.json", "w") as f:
        f.write(json.dumps(file_list, sort_keys=True, indent=4))
def main():
    service, creds = connect_to_drive()
    resource = {
        "oauth2": creds,
        "id": FOLDERS[1],
        "fields": "files(name,id)",
    }

    # or r = getfilelist.GetFolderTree(resource)
    res = getfilelist.GetFileList(resource)

    added = []
    items = list(res.items())
    for r in items[2][1][0]['files']:
        filename = r[u'name']
        file_id = r[u'id']
        # print(filename)
        added.append(filename)
        download_images(service, file_id, filename)  # Donwload images

    server()  # Add to folder
    deleteSer(added[1:])
    server(added=added)  # remove the weird dot
Example #4
0
        print('Files:')
        for item in items:
            print(item)
            print('{0} ({1})'.format(item['name'], item['id']))
#uploadFile('unnamed.jpg','unnamed.jpg','image/jpeg')
# downloadFile('1hMesLGxOjQ38LOkP7BRhGNxLfVerJ3jC','F:\Master\P1\CreativeDesign\project\Mine\K\T\R\images\\1.jpg')
#createFolder('Google')
# searchFile(10,"name contains 'Getting'")

Destination = 'F:\Master\P1\CreativeDesign\project\Mine\K\T\R\images'

resource = {
    "oauth2": http,
    "id": "1HHoB9HgAPYKhcqbmxz8M06G3ZNhRppjl",
    "fields": "files(name,id)",
}
# getting an order dictionary containing the informations of the Folder Id presented in the resource dic
res = getfilelist.GetFileList(resource)

# print(json.dumps(res, indent=2))  # printing the ordered dict in a readable way

# extracting a list containg multiple ditionaries each one have an Id and Name of the files in the dictionary
FileList = res["fileList"][0]["files"]
# downloading the files to the distenation folder
for i in range (len(FileList)):
    print(FileList[i])
    fileName = FileList[i]["name"]
    fileId = FileList[i]["id"]
    downloadFile(fileId, Destination + "\\" + fileName)
    
def get_files(resource):
    res = getfilelist.GetFileList(resource)
    files_list = res['fileList'][0]
    return files_list