Import text file to Grist

22 Sep 2022

import grist_PE

DOC_ID_X = os.getenv("DOC_ID_X")
Document_Object = GristDocAPI(DOC_ID_X, server=SERVER, api_key=API_KEY_GRIST)

file = '/path/to/file.txt'

with open(file, 'r') as df:
    lines = df.readlines()
    for line in lines:
        count += 1
        print(count)

        if '\n' in line:
            line = line.replace('\n', '')

        parts = line.split(' ')

        name = parts[0]
        ref = parts[1]
        print(f"{name=}")
        print(f"{ref=}")

        grist_PE.Document_Object.add_records('Master', [
                                        {   'name': name,
                                            'ref': ref,
                                            }
                                    ])

        print()

links

social