Example #1
0
class DataImportResource(BaseResource):

    upload_schema = DataImportSchema()

    @use_kwargs(upload_schema, location='json')
    def put(
        self,
        source: IMPORTABLE_LOCATIONS,
        file: Path,
    ) -> Response:
        return self.rest_api.import_data(source=source, filepath=file)

    @use_kwargs(upload_schema, location='form_and_file')
    def post(
        self,
        source: IMPORTABLE_LOCATIONS,
        file: FileStorage,
    ) -> Response:
        with TemporaryDirectory() as temp_directory:
            filename = file.filename if file.filename else f'{source}.csv'
            filepath = Path(temp_directory) / filename
            file.save(str(filepath))
            response = self.rest_api.import_data(source=source,
                                                 filepath=filepath)

        return response
Example #2
0
class DataImportResource(BaseResource):

    put_schema = DataImportSchema()

    @use_kwargs(put_schema, location='json')  # type: ignore
    def put(self, source: Literal['cointracking.info'], filepath: Path) -> None:
        return self.rest_api.import_data(source=source, filepath=filepath)
Example #3
0
class DataImportResource(BaseResource):

    put_schema = DataImportSchema()

    @use_kwargs(put_schema, location='json')  # type: ignore
    def put(self, source: Literal['cointracking.info', 'crypto.com'],
            filepath: Path) -> Response:
        return self.rest_api.import_data(source=source, filepath=filepath)

    def post(self) -> Response:
        req_parser = RequestParser()
        req_parser.add_argument(
            'source',
            location='form',
            required=True,
            help="Source is required",
            choices=('cointracking.info', 'crypto.com'),
        )
        req_parser.add_argument(
            'file',
            type=FileStorage,
            location='files',
            required=True,
            help="A file is required",
        )

        args = req_parser.parse_args()
        return self.rest_api.import_data_from_file(source=(args['source']),
                                                   file=(args['file']))
Example #4
0
class DataImportResource(BaseResource):

    upload_schema = DataImportSchema()

    @use_kwargs(upload_schema, location='json')  # type: ignore
    def put(self, source: Literal['cointracking.info', 'crypto.com'],
            file: Path) -> Response:
        return self.rest_api.import_data(source=source, filepath=file)

    @use_kwargs(upload_schema, location='form_and_file')  # type: ignore
    def post(
        self,
        source: Literal['cointracking.info', 'crypto.com'],
        file: FileStorage,
    ) -> Response:
        with TemporaryDirectory() as temp_directory:
            filename = file.filename if file.filename else f'{source}.csv'
            filepath = Path(temp_directory) / filename
            file.save(str(filepath))
            response = self.rest_api.import_data(source=source,
                                                 filepath=filepath)

        return response