Пример #1
0
    def _get_files_in_folder(self, folder_id):
        """ 
        Gets the metadata for all the children inside a Google Drive folder
        
        :param: folder_id = the Google Drive id of a folder

        :return: list of dicts that have all the file metadata
        """
        children_ids = gdrive.get_children(self.get_service(), folder_id)
        total = 0
        files_list = []
        for child_id in children_ids:
            metadata = gdrive.get_file_metadata(self.get_service(), child_id)
            if metadata["labels"]["trashed"]:
                continue  # the file was marked as trash, don't download

            # add file's info as tuple to the returned list
            title = metadata["title"]
            mime = metadata["mimeType"]
            if len(metadata["parents"]) != 0:
                # parent id is in a dict inside a list
                parents = metadata["parents"][0]
                if parents["isRoot"]:
                    parent_id = "root"
                else:
                    parent_id = parents["id"]
            else:
                # some files have an empty parents list
                parent_id = None

            files_list.append(
                {"id": child_id, "mime": mime, "title": title, "parent_id": parent_id, "metadata": metadata}
            )

            # logging to stdout
            total += 1
            print("Retrieved file " + str(total) + ". " + title + " (" + mime + ")")

        return files_list
Пример #2
0
 def test_get_children_of_root_folder_only_type(self):
     """ tests just getting first page results of children of root 
         Google Drive folder and making sure it's a dictionary type object"""
     children = gdrive.get_children(self.service, "root")
     self.assertEqual(type([]), type(children))