Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added method for templating export #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

added method for templating export #22

wants to merge 1 commit into from

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