示例#1
0
 def _dl_canvas_file(self, url, path, requester):
     canvas_path = urllib.parse.urlparse(url).path
     resp = requester.request("GET", canvas_path)
     file = File(requester, resp.json())
     dl_path = os.path.join(path, file.filename)
     if not self._should_write(dl_path):
         return
     file.download(dl_path)
     self.logger.info(f"{dl_path} downloaded")
     return True
示例#2
0
    def get_file(self, file_id, **kwargs):
        """
        Return the standard attachment json object for a file.

        :calls: `GET /api/v1/files/:id \
        <https://canvas.instructure.com/doc/api/files.html#method.files.api_show>`_

        :param file_id: The ID of the file to retrieve.
        :type file_id: int
        :rtype: :class:`canvasapi.file.File`
        """
        response = self.__requester.request('GET', 'files/{}'.format(file_id),
                                            **combine_kwargs(**kwargs))
        return File(self.__requester, response.json())
示例#3
0
文件: canvas.py 项目: quoyi/canvasapi
    def get_file(self, file, **kwargs):
        """
        Return the standard attachment json object for a file.

        :calls: `GET /api/v1/files/:id \
        <https://canvas.instructure.com/doc/api/files.html#method.files.api_show>`_

        :param file: The object or ID of the file to retrieve.
        :type file: :class:`canvasapi.file.File` or int

        :rtype: :class:`canvasapi.file.File`
        """
        file_id = obj_or_id(file, "file", (File, ))

        response = self.__requester.request("GET",
                                            "files/{}".format(file_id),
                                            _kwargs=combine_kwargs(**kwargs))
        return File(self.__requester, response.json())
示例#4
0
    def copy_file(self, source_file, **kwargs):
        """
        Copies a file into the current folder.

        :calls: `POST /api/v1/folders/:dest_folder_id/copy_file \
        <https://canvas.instructure.com/doc/api/files.html#method.folders.copy_file>`_

        :param source_file: The object or id of the source file.
        :type source_file: int or :class:`canvasapi.file.File`

        :rtype: :class:`canvasapi.folder.Folder`
        """
        from canvasapi.file import File

        file_id = obj_or_id(source_file, "source_file", (File, ))
        kwargs['source_file_id'] = file_id

        response = self._requester.request('POST',
                                           'folders/{}/copy_file'.format(
                                               self.id),
                                           _kwargs=combine_kwargs(**kwargs))

        return File(self._requester, response.json())
示例#5
0
        if s.user_id != 7196:
            continue

        print("Submission Object", type(s), dir(s), s)
        pp.pprint(s)

        if not 'attachments' in dir(s):
            print("No Attachments:")
        else:
            print("Attachments:", len(s.attachments))
            for a in s.attachments:
                #print("   Attachment Object:", type(a), dir(a), a)
                #pp.pprint(a)

                f = File(s._requester, a)
                path = OPT['path'].rstrip('/') + '/' + str(a['id']) + '/'
                if os.path.isdir(path):
                    print('\tExists already -- maybe part of a group?')
                    continue
                os.makedirs(path)
                filename = path + a['filename']
                f.download(filename)
                print("\t", "Filename:", filename)
                print("\t  ", "Submitted:", s.submitted_at)
                print("\t  ", "created_at:", a['created_at'])
                print("\t  ", "updated_at:", a['updated_at'])
                print("\t  ", "modified_at:", a['modified_at'])
                print("\t  ", "workflow_state:", a['workflow_state'])
        print()