Skip to content

Conversation

@felixlohmeier
Copy link

The OpenRefine Templating supports exporting data in any text format (i.e. to construct JSON or XML). The graphical user interface offers four input fields:

  1. prefix
  2. row template (supports GREL inside two curly brackets, e.g. {{jsonize(cells["name"].value)}})
  3. row separator
  4. suffix

The proposed new method adds the templating feature to the client:
export_templating(self, engine='', prefix='', template='', rowSeparator='\n', suffix='')

example

in:

from google.refine import refine

server1 = refine.Refine('http://localhost:3333')

project1 = server1.new_project(project_file='tests/data/duplicates.csv')

data = project1.export_templating(
    prefix='''{ "events" : [
''',
    template='''    { "name" : {{jsonize(cells["name"].value)}}, "purchase" : {{jsonize(cells["purchase"].value)}} }''',
    rowSeparator=''',
''',
    suffix='''
] }''')

print(data.read())

out:

{ "events" : [
    { "name" : "Danny Baron", "purchase" : "TV" },
    { "name" : "Melanie White", "purchase" : "iPhone" },
    { "name" : "D. Baron", "purchase" : "Winter jacket" },
    { "name" : "Ben Tyler", "purchase" : "Flashlight" },
    { "name" : "Arthur Duff", "purchase" : "Dining table" },
    { "name" : "Daniel Baron", "purchase" : "Bike" },
    { "name" : "Jean Griffith", "purchase" : "Power drill" },
    { "name" : "Melanie White", "purchase" : "iPad" },
    { "name" : "Ben Morisson", "purchase" : "Amplifier" },
    { "name" : "Arthur Duff", "purchase" : "Night table" }
] }

@felixlohmeier
Copy link
Author

Hi @paulmakepeace, do you still want to receive pull requests? This one is waiting for you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant