Exemple #1
0
def save():
    filename_path = Path(os.environ['FILENAME'])

    content = request.get_json()

    if filename_path.suffix in ('.csv', '.tsv'):
        pyexcel.save_as(array=list(content['data'].values())[0],
                        dest_file_name=str(filename_path))
    else:
        try:
            pyexcel_export.save_data(str(filename_path), content['data'])
        except NameError:
            pyexcel.save_book_as(bookdict=content['data'],
                                 dest_file_name=str(filename_path))

    try:
        config = json.loads(os.environ.get('CONFIG', ''))
        assert isinstance(config, dict)
    except (json.decoder.JSONDecodeError, AssertionError):
        if 'CONFIG' in os.environ:
            config_path = Path(os.environ['CONFIG'])
            if config_path.exists():
                config = yaml.safe_load(config_path.read_text())
            else:
                config = dict()

            config['simplecel'] = content['config']

            config_path.write_text(yaml.safe_dump(config, allow_unicode=True))

    return Response(status=200)
Exemple #2
0
    def save(self):
        data = OrderedDict()
        data['TagDict'] = []

        data['TagDict'].append(list(list(self.entries.values())[0].keys()))

        assert data['TagDict'][0] == [
            'Front', 'Back', 'Additional keywords', 'Tags'
        ]

        for entry in self.entries.values():
            data['TagDict'].append(list(entry.values()))

        for matrix in data['TagDict']:
            for row in matrix:
                for cell in row:
                    assert isinstance(cell, (int, str, bool))

        pyexcel_export.save_data(self.filename, data, meta=self.meta)
def test_read_pyexcel_yaml(in_file, test_file, out_file, request):
    """

    :param str in_file:
    :param test_file: function defined in conftest.py
    :param out_file: function defined in conftest.py
    :return:
    """
    in_file = test_file(in_file)

    assert isinstance(in_file, Path)

    data, meta = pyexcel_export.get_data(in_file)

    assert isinstance(data, OrderedDict)
    for k, v in data.items():
        assert isinstance(v, list)
        for row in v:
            assert isinstance(row, list)
            for cell in row:
                assert isinstance(cell, (int, str, bool, float))

    pyexcel_export.save_data(out_file(out_base=request.node.name, out_format=".xlsx"), data=data, meta=meta)
Exemple #4
0
 def save(self):
     pyexcel_export.save_data(self.excel_filename,
                              data=self.excel_raw,
                              retain_meta=True,
                              created=self.created,
                              modified=datetime.now().isoformat())
Exemple #5
0
from pathlib import Path

import pyexcel_export


if __name__ == '__main__':
    data = pyexcel_export.get_data('PathoDict.yaml')[0]
    pyexcel_export.save_data('PathoDict.xlsx', data)