def main(args):
    # Get the dataset name from the command line
    if args.DataSet != "":

        # Get the dataset info from the XML
        ods = getDatasetInfo(args.DataSet)
        # Create the connection to the database
        connection = ods.getConnection()
        # Create the dataframe
        df = pd.read_sql(ods.query, con=connection)
        # Close the database connection
        connection.close
        # Save the dataframe to a file
        writeFile(df, args.FileName)
        # Post the file to SCGC?
        if args.Upload == True:
            # Authenticate to the portal
            auth = Authorization('austin-aph.data.socrata.com',
                                 'Your_Socrata_Username',
                                 'Your_Socrata_Password')
            socrata = Socrata(auth)
            # Find the view for the dataset
            (ok, view) = socrata.views.lookup(ods.view)
            assert ok, view
            # Open the file
            with open(args.FileName, 'rb') as my_file:
                # Get the config file for the view
                (ok, job) = socrata.using_config(ods.config, view).csv(my_file)
                assert ok, job
                # Write out the progress of the job
                assert ok, job
                (ok, job) = job.wait_for_finish(progress=lambda job: print(
                    'Job progress:', job.attributes['status']))
Exemplo n.º 2
0
    def test_upload_to_config(self):
        p = Socrata(auth)
        name = "some_config %s" % str(uuid.uuid4())
        (ok, config) = p.configs.create(name, "replace")
        self.assertTrue(ok, config)

        p = Socrata(auth)
        with open('test/fixtures/simple.csv', 'rb') as my_file:
            (rev, job) = p.using_config(name, self.view).csv(my_file)
            self.assertEqual(rev.attributes['action']['type'], 'replace')
            self.assertTrue(job.attributes['created_at'])
Exemplo n.º 3
0
    def test_source_to_config(self):
        p = Socrata(auth)
        name = "some_config %s" % str(uuid.uuid4())
        (ok, config) = p.configs.create(name, "replace")
        self.assertTrue(ok, config)

        p = Socrata(auth)
        (rev, job) = p.using_config(name, self.view).csv("""a,b,c
                1,2,3
                4,5,6
                7,8,9
            """,
                                                         filename="abc.csv")
        self.assertEqual(rev.attributes['action']['type'], 'replace')
        self.assertTrue(job.attributes['created_at'])
                     os.environ['SOCRATA_PASSWORD'])

socrata = Socrata(auth)
# Just so you can run this script a lot and not have config name collisions
config_name = 'parking-config-%s' % str(uuid.uuid4())

# Create the dataset initially
with open('../files/parking.csv', 'rb') as file:
    (revision, output) = socrata.create(name="parking").csv(file)

    print("Created", revision.ui_url())

    # Create a config fr updating in the future
    (ok, config) = output.build_config(config_name, 'replace')
    assert ok, config

    print("Created configuration", config_name)

    (ok, job) = revision.apply(output_schema=output)
    assert ok, job
    # Let's wait for the upsert to finish before opening a new revision
    job.wait_for_finish()

# Update step
(ok, view) = socrata.views.lookup(revision.view_id())
assert ok, view

with open('../files/parking-updated.csv', 'rb') as updated_file:
    (rev, job) = socrata.using_config(config_name, view).csv(updated_file)
    rev.open_in_browser()
Exemplo n.º 5
0
    def test_config_not_found(self):
        p = Socrata(auth)

        with open('test/fixtures/simple.csv', 'rb') as my_file:
            with self.assertRaises(SocrataException):
                (rev, job) = p.using_config("nope", self.view).csv(my_file)