Esempio n. 1
0
def run(args):
    api = DatasetAPI(args.DkanHost, args.Token)
    if args.Action == 'Create':
        data = {'title': args.title, 'type': args.type}
        print("Attempting to create a new {}".format(args.type))
        dataset = api.node('create', data=data)
        print("Process Completed: ", dataset.status_code, dataset.text)
    elif args.Action == 'Attach_File':
        print("Attempting to Upload the file to the Dataset...")
        r = api.attach_file_to_node(args.filename, args.node_id,
                                    'field_upload')
        print("Process Completed: ", r.status_code, r.text)
    elif args.Action == 'Delete':
        print("Attempting to Delete ...")
        op = api.node('delete', node_id=args.node_id)
        print("Process Completed: ", op.status_code, op.text)
    elif args.Action == 'Update':
        print("Attempting to Update ...")
        r = api.node('update',
                     node_id=int(args.node_id),
                     data=eval(args.parameters))
        print("Process Completed: ", r.status_code, r.text)
    else:
        print("We only support 'Create', 'Upload', 'Delete' and 'Update'\
              at the moment")
Esempio n. 2
0
import os
import json
from dkan.client import DatasetAPI

uri = os.environ.get('DKAN_URI', False)
user = os.environ.get('DKAN_USER', 'admin')
password = os.environ.get('DKAN_PASSWORD', 'admin')

if uri:
    api = DatasetAPI(uri, user, password, True)
    data = {'title': 'Test Dataset', 'type': 'dataset'}
    dataset = api.node('create', data=data)
    print dataset.status_code
    print dataset.text
    nid = dataset.json()['nid']
    op = api.node('delete', node_id=nid)
    print op.status_code
    print op.text
else:
    print 'Please Set the dkan URL as an ENVIRONMENT variable'
Esempio n. 3
0
import os
import json
from dkan.client import DatasetAPI

uri = os.environ.get('DKAN_URI', False)
user = os.environ.get('DKAN_USER', 'admin')
password = os.environ.get('DKAN_PASSWORD', 'admin')
token = os.environ.get('TOKEN')

if uri:
    # api = DatasetAPI(uri, user, password, True)
    api = DatasetAPI(uri, token)
    payload = {'parameters[type]': 'resource'}
    nodes = api.node(params=payload).json()
    resource = nodes[0]
    print resource
    csv = os.path.join(os.path.dirname(os.path.abspath(__file__)), '.', 'data',
                       'tension_sample_data.csv')
    # Attach the file to the resource node
    r = api.attach_file_to_node(csv, resource['nid'], 'field_upload')
    print r.status_code
    print r.text
    resource = api.node('retrieve', node_id=resource['nid'])
    print resource.json()['field_upload']
else:
    print 'Please Set the dkan URL as an ENVIRONMENT variable'
Esempio n. 4
0
import os
import json
from dkan.client import DatasetAPI

uri = os.environ.get('DKAN_URI', False)
user = os.environ.get('DKAN_USER', 'admin')
password = os.environ.get('DKAN_PASSWORD', 'admin')

if uri:
  api = DatasetAPI(uri, user, password, True)
  data = {
      'title': 'Test Dataset',
      'type': 'dataset'
  }
  dataset = api.node('create', data=data)
  print dataset.status_code
  print dataset.text
  nid = dataset.json()['nid']
  op = api.node('delete', node_id=nid)
  print op.status_code
  print op.text
else:
  print 'Please Set the dkan URL as an ENVIRONMENT variable'
Esempio n. 5
0
import json
from dkan.client import DatasetAPI

uri = os.environ.get('DKAN_URI', False)
user = os.environ.get('DKAN_USER', 'admin')
password = os.environ.get('DKAN_PASSWORD', 'admin')

if uri:
    api = DatasetAPI(uri, user, password, True)
    # Create dataset
    print 'CREATE DATASET'
    data = {
        'title': 'Test Dataset',
        'type': 'dataset'
    }
    r = api.node('create', data=data)
    print 'Response: %s\n\n' % r.text
    dataset_nid = r.json()['nid']
    # Create resource
    print 'CREATE RESOURCE'
    data = {
        'title': 'Test Resource',
        'type': 'resource',
        'field_dataset_ref': {
            'und': {
                '0': {
                    'target_id': dataset_nid,
                },
            },
            
        },
Esempio n. 6
0
import os
import json
from dkan.client import DatasetAPI

uri = os.environ.get('DKAN_URI', False)
user = os.environ.get('DKAN_USER', 'admin')
password = os.environ.get('DKAN_PASSWORD', 'admin')
token = os.environ.get('TOKEN')

if uri:
  # api = DatasetAPI(uri, user, password, True)
  api = DatasetAPI(uri, token)
  data = {
      'title': 'Test Dataset',
      'type': 'dataset'
  }
  dataset = api.node('create', data=data)
  print dataset.status_code
  print dataset.text
  dataset = dataset.json()
  update = {
    'title': 'Test Dataset Updated',
  }
  r = api.node('update', node_id=dataset['nid'], data=update)
  print r.status_code
  print r.text
else:
  print 'Please Set the dkan URL as an ENVIRONMENT variable'
Esempio n. 7
0
#uri = 'https://test.cadepttech.nucivicdata.com/node/1826/api'
#uri = 'https://test.cadepttech.nucivicdata.com/dataset/flow-targets-southern-california-streams/resource/d2f2657c-1fb4-4ae2-a31b-d4b80ccee3e8'
#uri = 'https://test.cadepttech.nucivicdata.com/api/action/datastore/search.json?resource_id=d2f2657c-1fb4-4ae2-a31b-d4b80ccee3e8'
#uri = 'https://data.ca.gov/node/1691/api'
#URI = 'https://data.ca.gov/'
#uriNode1721Test = 'https://data.ca.gov/api/dataset/node/1721'
#uri = 'https://test.cadepttech.nucivicdata.com/'

#with DatasetAPI(uri, user, password , True) as api:
#	print(api.node('index'))

# gives a list of anything available but on 20....!!!!
onA = "on"
if onA:
    api = DatasetAPI(URI, user, password, True)
    r = api.node('index')
    #print(r.json())
    columns = [desc for desc in r.json()[0]]
    rStack = np.vstack(r.json())
    df2 = pd.DataFrame(data=r.json(), columns=columns)
    print(df2)
    #df.to_csv("outTestTrash.csv", sep=',', encoding='utf-8')
else:
    print("BooHoo")

# only use to list dataset from
on = "on"
if on:
    api = DatasetAPI(URI, user, password, True)

    # List datasets
Esempio n. 8
0
import os
import json
from dkan.client import DatasetAPI

uri = os.environ.get('DKAN_URI', False)
user = os.environ.get('DKAN_USER', 'admin')
password = os.environ.get('DKAN_PASSWORD', 'admin')

if uri:
  api = DatasetAPI(uri, user, password, True)
  data = {
      'title': 'Test Dataset',
      'type': 'dataset'
  }
  dataset = api.node('create', data=data)
  print dataset.status_code
  print dataset.text
  dataset = dataset.json()
  update = {
    'title': 'Test Dataset Updated',
  }
  r = api.node('update', node_id=dataset['nid'], data=update)
  print r.status_code
  print r.text
else:
  print 'Please Set the dkan URL as an ENVIRONMENT variable'
Esempio n. 9
0
import os
import json

try:
    from dkan.client import DatasetAPI
except ImportError:
    import sys
    sys.path.append('../')
    from dkan.client import DatasetAPI

uri = os.environ.get('DKAN_URI', False)
user = os.environ.get('DKAN_USER', 'admin')
password = os.environ.get('DKAN_PASSWORD', 'admin')

if uri:
    api = DatasetAPI(uri, user, password, True)
    data = {'title': 'Test Dataset', 'type': 'dataset'}
    dataset = api.node('create', data=data)
    print(dataset.status_code)
    print(dataset.text)
else:
    print('Please Set the dkan URL as an ENVIRONMENT variable')
Esempio n. 10
0
import os
import json
from dkan.client import DatasetAPI

uri = os.environ.get('DKAN_URI', False)
user = os.environ.get('DKAN_USER', 'admin')
password = os.environ.get('DKAN_PASSWORD', 'admin')
token = os.environ.get('TOKEN')

if uri:
  # Make the api authenticate properly
  # api = DatasetAPI(uri, user, password, True)
  api = DatasetAPI(uri, token)

  # List datasets
  params = {
    'parameters[type]': 'dataset',
  }
  r = api.node(params=params)

  print r.json()
else:
  print 'Please Set the dkan URL as an ENVIRONMENT variable'
Esempio n. 11
0
import os
import json
from dkan.client import DatasetAPI

uri = os.environ.get('DKAN_URI', False)
user = os.environ.get('DKAN_USER', 'admin')
password = os.environ.get('DKAN_PASSWORD', 'admin')

if uri:
  # Make the api authenticate properly
  api = DatasetAPI(uri, user, password, True)

  # List datasets
  params = {
    'parameters[type]': 'dataset',
  }
  r = api.node(params=params)

  print r.json()
else:
  print 'Please Set the dkan URL as an ENVIRONMENT variable'
Esempio n. 12
0
    sys.path.append('../')
    from dkan.client import DatasetAPI

uri = os.environ.get('DKAN_URI', False)
user = os.environ.get('DKAN_USER', 'admin')
password = os.environ.get('DKAN_PASSWORD', 'admin')

if uri:
    api = DatasetAPI(uri, user, password, True)
    # Create dataset
    print('CREATE DATASET')
    data = {
        'title': 'Test Dataset',
        'type': 'dataset'
    }
    r = api.node('create', data=data)
    print('Response: %s\n\n' % r.text)
    dataset_nid = r.json()['nid']
    # Create resource
    print('CREATE RESOURCE')
    data = {
        'title': 'Test Resource',
        'type': 'resource',
        'field_dataset_ref': {
            'und': {
                '0': {
                    'target_id': dataset_nid,
                },
            },

        },
Esempio n. 13
0
import os
import json
from dkan.client import DatasetAPI

uri = os.environ.get('DKAN_URI', False)
user = os.environ.get('DKAN_USER', 'admin')
password = os.environ.get('DKAN_PASSWORD', 'admin')

if uri:
  api = DatasetAPI(uri, user, password, True)
  payload = {'parameters[type]': 'resource'}
  nodes = api.node(params=payload).json()
  resource = nodes[0]
  print resource
  csv = os.path.join(os.path.dirname(os.path.abspath(__file__)), '.',
                     'data', 'tension_sample_data.csv')
  # Attach the file to the resource node
  r = api.attach_file_to_node(csv, resource['nid'], 'field_upload')
  print r.status_code
  print r. text
  resource = api.node('retrieve', node_id=resource['nid'])
  print resource.json()['field_upload']
else:
  print 'Please Set the dkan URL as an ENVIRONMENT variable'