示例#1
0
def update_using_config():
    name = prompt('Enter the configuration name')
    fourfour = prompt('Enter the view id (four by four)')

    (ok, view) = socrata.views.lookup(fourfour)
    if not ok:
        print("Failed to lookup that view", view)
        return update_using_config()

    path = file_picker()
    with open(path, 'rb') as file:
        (revision, job) = socrata.using_config(name, view).csv(file)
        on_job(revision, job)
示例#2
0
    def run():
        field_name = prompt('Enter the field name of the column to change')
        expr = prompt(
            'Enter the SoQL expression which will populate the data in your column'
        )

        (ok, new_output_schema
         ) = output_schema.change_column_transform(field_name).to(expr).run()

        if not ok:
            print('Failed to change column!\n', new_output_schema)
            transform_column_data(revision, output_schema)()
        else:
            print("New output schema created!")

        use_output_schema(revision, new_output_schema)()
示例#3
0
    def run():
        field_name = prompt(
            'Enter the field name that you would like your new column to have')
        expr = prompt(
            'Enter the SoQL expression which will populate the data in your column'
        )

        (ok,
         new_output_schema) = output_schema.add_column(field_name, field_name,
                                                       expr).run()

        if not ok:
            print('Failed to add column!\n', new_output_schema)
            add_column(revision, output_schema)()
        else:
            print("New output schema created!")
        use_output_schema(revision, new_output_schema)()
示例#4
0
    def run():
        field_name = prompt('Enter the field name of the column to change')
        attr = prompt(
            'Enter the attribute you want to change, one of "field_name", "description", "display_name"'
        )
        attr_value = prompt('Enter the new value of the attribute')

        (ok, new_output_schema) = output_schema.change_column_metadata(
            field_name, attr).to(attr_value).run()

        if not ok:
            print('Failed to change column!\n', new_output_schema)
            change_column_metadata(revision, output_schema)()
        else:
            print("New output schema created!")

        use_output_schema(revision, new_output_schema)()
示例#5
0
    def run():
        field_name = prompt('Column field name')

        (ok, new_output_schema) = output_schema.drop_column(field_name).run()

        if not ok:
            print('Failed to drop column!\n', new_output_schema)
            drop_column(revision, output_schema)()
        use_output_schema(revision, new_output_schema)()
示例#6
0
def file_picker():
    files = 'files'
    examples = [
        join(files, f) for f in listdir(files) if isfile(join(files, f))
    ]

    print("Examples:")
    for e in examples:
        print(e)

    return prompt('Enter the file path')
示例#7
0
def create():
    name = prompt('Enter the dataset name')
    description = prompt('Enter the dataset description')
    (ok, revision) = socrata.new({'name': name, 'description': description})

    interaction(
        dedent("""
        A Revision holds the changes to an existing dataset.
        When you load a Revision in the UI, like here

        {uri}

        you are looking at staged changes (of data, metadata, or both),
        that can be applied at some point in the future to the actual
        Socrata View. When the chages are applied, you will be able to
        query and make visualizations from the View.

        You have created your revision, what would you like to do?
        """.format(uri=revision.ui_url())),
        [('Return', back), ('Upload a csv', upload_csv(revision)),
         ('Open the revision in a browser', browse(revision))])
示例#8
0
    def run():
        name = prompt('Enter a name for this configuration')
        action = prompt(
            'Enter an action to take when this config is used, either "update" or "replace"'
        )

        (ok, config) = output_schema.build_config(name, action)
        if not ok:
            print("Creating the config failed!", config)
            return
        else:
            print(
                dedent("""
            Configuration created!

            To {action} your view {fourfour} using config {name},
            start the adventure game over and choose the "Use Configuration"
            path
            """.format(fourfour=revision.attributes['fourfour'],
                       action=action,
                       name=name)))

            sys.exit(0)