def search_files_list()

in libs/google/drive.py [0:0]


  def search_files_list(self, owner="'me' in owners", drive_query=""):
    """
    Searches users drives files
    :param drive_query: q
    :param owner: q
    :return: list of files with name containing the searched term.
    """
    files_list = []
    try:
      file_search = "%s and name contains '%s'" % (owner, drive_query)
      r = json.loads(self.call_google_api(service=self.service,
                                          q=file_search,
                                          api_resource="files",
                                          api_method="list",
                                          response_field=None,
                                          corpus="user",
                                          spaces="drive"))
      files_list.extend(r["files"])

      if "nextPageToken" in r:
        next_page_token = r["nextPageToken"]
        while next_page_token is not None:
          r = json.loads(self.call_google_api(service=self.service,
                                              q=file_search,
                                              api_resource="files",
                                              api_method="list",
                                              response_field=None,
                                              corpus="user",
                                              spaces="drive",
                                              pageToken=next_page_token))
          files_list.extend(r["files"])
          if "nextPageToken" in r:
            next_page_token = r["nextPageToken"]
          else:
            next_page_token = None

      return files_list
    except(ValueError, KeyError, TypeError):
      return None