예제 #1
0
def create_api_session():
    try:
        api = DatasetAPI(config['dkan']['uri'], config['dkan']['user'],
                         config['dkan']['password'])
        return api
    except Exception as e:
        return e
예제 #2
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")
예제 #3
0
def connect():
    global api
    if api:
        return ""

    try:
        logging.debug(_("DKAN-Login: %s @ %s"), config.dkan_username,
                      config.dkan_url)
        # Last parameter is debug mode: True = Debugging ON
        api = DatasetAPI(config.dkan_url, config.dkan_username,
                         config.dkan_password, True)
        return ""
    except LoginError as err:
        logging.error(_("Fehler bei Verbindung zur DKAN-Instanz!"))
        logging.error(_("Fehlermeldung %s"), str(err))
        logging.error(
            _("Bitte prüfen Sie die angegebenen DKAN-Url und -Zugangsdaten."))
        return "Fehler: " + str(err)
예제 #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'
예제 #5
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)
예제 #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)
    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'
예제 #7
0
def connect(args):
    global api
    print("DKAN url:", args.dkan_url)

    # Last parameter is debug mode: True = Debugging ON
    api = DatasetAPI(args.dkan_url, args.user, args.passw, True)
예제 #8
0
#uri = os.environ.get('URI', False)
#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)