Exemple #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")
Exemple #2
0
    cursor.execute(sql)
    columns = [desc[0] for desc in cursor.description]
    with open(file, 'w', newline='', encoding='utf8') as writer:
        dw = csv.DictWriter(writer,
                            fieldnames=columns,
                            delimiter=sep,
                            lineterminator='\n')
        dw.writeheader()
        FHAB_writer = csv.writer(writer,
                                 csv.QUOTE_MINIMAL,
                                 delimiter=sep,
                                 lineterminator='\n')
        for row in cursor:
            row = [str(word) if word is not None else '' for word in row]
            filtered = [decodeAndStrip(t) for t in list(row)]
            newDict = dict(zip(columns, filtered))
            try:
                long = float(newDict['Longitude'])
                if long > 0:
                    newDict['Longitude'] = -long
            except ValueError:
                pass
            FHAB_writer.writerow(list(newDict.values()))
    # 2446 FHAB portal data (previously 2156)
    NODE = 2446
    api = DatasetAPI(URI, user, password, debug=False)
    r = api.attach_file_to_node(file=file,
                                node_id=NODE,
                                field='field_upload',
                                update=0)
Exemple #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'
Exemple #4
0
            },
            
        },
    }
    r = api.node('create', data=data)
    print 'Response: %s\n\n' % r.text
    resource_nid = r.json()['nid']
    # Retrieve parent node to see if resource_ref has been created
    print 'RETRIEVE PARENT DATASET TO CHECK REFERENCE'
    r = api.node('retrieve', node_id=dataset_nid)
    print 'Response: %s\n' % r.text
    resource_ref = r.json()['field_resources']['und'][0]['target_id']
    print 'Dataset -> Resource reference is %s\n\n' % resource_ref
    # Update dataset title
    data = {
        'title': 'Updated dataset title'
    }
    r = api.node('update', node_id=dataset_nid, data=data)
    print 'Response: %s\n\n' % r.text
    # Attach file to resource
    csv = os.path.join(os.path.dirname(os.path.abspath(__file__)), '.',
                     'data', 'tension_sample_data.csv')
    print 'ADD FILE TO RESOURCE'
    r = api.attach_file_to_node(csv, resource_nid, 'field_upload')
    print 'Response: %s\n\n' % r.text
    # Retrieve updated resource
    print 'RETRIEVE RESOURCE TO CHECK FILE UPLOAD'
    r = api.node('retrieve', node_id=resource_nid)
    print 'Response: %s\n\n' % r.text
else:
    print 'Please Set the dkan URL as an ENVIRONMENT variable'
Exemple #5
0
# to get info about parent dataset  which will give us the group information.
on2 = "on"
if on2:
    api = DatasetAPI(URI, user, password, True)
    # Get attributes of dataset
    #print('Getting Dataset Attributes')
    r = api.node('retrieve', node_id='1826')

# Update dataset title
onC = "on"
if onC:
    data = {'title': ''}
    r = api.node(action='update', node_id='1826', data=data)
    print('Response: %s\n\n' % r.text)
    r = api.node('retrieve', node_id='1826')
    print(r.json())

# Attach dataset data
onC1 = "on"
if onC1:
    #csv = os.path.join(os.path.dirname(os.path.abspath(__file__)), '.', 'data', 'tension_sample_data.csv')
    csv1 = "C:\Users\AHill\Documents\PythonScripts\TestDatSet_trash.csv"

    r = api.attach_file_to_node(file=csv1,
                                node_id='1826',
                                field='field_upload')
    print('Response: %s\n\n' % r.text)
    r = api.node('retrieve', node_id='1826')
    print(r.json())
Exemple #6
0
        },
    }
    r = api.node('create', data=data)
    print('Response: %s\n\n' % r.text)
    resource_nid = r.json()['nid']
    # Retrieve parent node to see if resource_ref has been created
    print('RETRIEVE PARENT DATASET TO CHECK REFERENCE')
    r = api.node('retrieve', node_id=dataset_nid)
    print('Response: %s\n' % r.text)
    resource_ref = r.json()['field_resources']['und'][0]['target_id']
    print('Dataset -> Resource reference is %s\n\n' % resource_ref)
    # Update dataset title
    data = {
        'title': 'Updated dataset title'
    }
    r = api.node('update', node_id=dataset_nid, data=data)
    print('Response: %s\n\n' % r.text)
    # Attach file to resource
    csv = os.path.join(os.path.dirname(os.path.abspath(__file__)), '.',
                     'data', 'tension_sample_data.csv')
    print('ADD FILE TO RESOURCE')
    r = api.attach_file_to_node(csv, resource_nid, 'field_upload')
    print('Response: %s\n\n' % r.text)
    # Retrieve updated resource
    print('RETRIEVE RESOURCE TO CHECK FILE UPLOAD')
    r = api.node('retrieve', node_id=resource_nid)
    print('Response: %s\n\n' % r.text)
else:
    print('Please Set the dkan URL as an ENVIRONMENT variable')
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'