Skip to main content

Kraken convert

Project description

kraken convert

Overview

Converts records using a mapping record

github

https://github.com/tactik8/krakenconvert2

pypi

methods:

  • convert: converts records

How to use:

Basics

input_records = [
        {
        "record_id": "1234",
        "firstName": "firstName1",
        "lastName": "lastName1",
        "email": "test1@test.com"
        }
    ]

    mapping_record = {
        "@type": "'test'",
        "@id": "'/system/table/' + str(r.record_id)",
        "givenName": "r.firstName",
        "familyName": "r.lastName",
        "email": "r.email"
    }

    results = convert(input_records, map)
    print(results)

Structure of record


mapping_record = {
    "@type": "dataset",
    "name": "NAME OF THE DATASER",
    "distribution": {
        "@type": "DataDownload",
        "contentUrl": "URL WHERE TO DOWNLOAD DATASET",
        "encodingFormat": "text/tab-separated-values"
      },
    "variableMeasured": EXAMPLE OF RECORD (NOT USED, SIMPLY FOR REFERENCE),
    "potentialAction": [

        LIST OF ACTIONS
        EACH REPLACEACTION REPLACE A GIVEN VALUE
        - * MEANS EVERY PROPERTYID
        
        EACH CREATEACTION CREATES A BRAND NEW RECORD
        - R.NAME REFERS TO THE NAME PROPERTY OF THE RECORD
        
        {
            "@type": "replaceAction",
            "replacee": {
                "@type": "propertyValue",
                "propertyID": "*",
                "value": ".."
            },
            "replacer": {
                "@type": "propertyValue",
                "propertyID": "*",
                "value": "NoneValue"
            }
        },
        {
            "@type": "replaceAction",
            "replacee": {
                "@type": "propertyValue",
                "propertyID": "derived_NAICS",
                "value": "44"
            },
            "replacer": {
                "@type": "propertyValue",
                "propertyID": "derived_NAICS",
                "value": "22"
            }
        },
        {
            "@type": "createAction",
            "instrument": {
                "@type": "'organization'",
                "name": "r.business_name",
                "legalName": "r.business_name",
                "naics": [
                    "r.derived_NAICS", 
                    "r.source_NAICS_primary",
                    "r.source_NAICS_secondary"
                ],
                "numberOfEmployees": "r.get('total_no_employees', None)",
                "brand": "r.alt_business_name",
                "description":  "r.get('business_description', None)",
                "taxID": "r.get('business_id_no', None)",
                "location": {
                    "@type": "'place'",
                    "latitude": "r.latitude",
                    "longitude": "r.longitude",
                    "address": {
                        "@type": "'PostalAddress'",
                        "streetAddress": "(r.unit + ', ' + r.street_no + ' ' +  r.street_name) if r.unit else (r.street_no + ' ' +  r.street_name)",
                        "addressLocality": "r.city",
                        "addressRegion":  "r.prov_terr",
                        "postalCode": "r.postal_code",
                        "addressCountry": "'CA'"
                    }
                }
            }
        }
    ],
}



Example of record


mapping_record = {
    "@type": "dataset",
    "name": "company directory records from GoC opendata",
    "distribution": {
        "@type": "DataDownload",
        "contentUrl": "https://www150.statcan.gc.ca/n1/pub/21-26-0003/212600032023001-eng.htm",
        "encodingFormat": "text/tab-separated-values"
      },
    "variableMeasured": {
        "idx": "87cfdddd858f54356f04", 
        "business_name": "Innomar Pharmacy Inc.", 
        "alt_business_name": "..", 
        "business_sector": "Community Pharmacy", 
        "business_subsector": "..", 
        "business_description": "..", 
        "business_id_no": "..", 
        "licence_number": "..", 
        "licence_type": "..", 
        "derived_NAICS": "44", 
        "source_NAICS_primary": "..", 
        "source_NAICS_secondary": "..", 
        "NAICS_descr": "..", 
        "NAICS_descr2": "..", 
        "latitude": "46.10593", 
        "longitude": "-64.80623", 
        "full_address": "100 Arden Street, Suite 309, Moncton Nb", 
        "postal_code": "..", 
        "unit": "..", 
        "street_no": "100", 
        "street_name": "Arden Street", 
        "street_direction": "..", 
        "street_type": "..", 
        "city": "Moncton", 
        "prov_terr": "NB", 
        "total_no_employees": "..", 
        "status": "..", 
        "provider": "City of Moncton", 
        "geo_source": "Source", 
        "CSDUID": "1307022", 
        "CSDNAME": "Moncton", 
        "PRUID": "13"
    },
    "potentialAction": [
        {
            "@type": "replaceAction",
            "replacee": {
                "@type": "propertyValue",
                "propertyID": "*",
                "value": ".."
            },
            "replacer": {
                "@type": "propertyValue",
                "propertyID": "*",
                "value": "NoneValue"
            }
        },
        {
            "@type": "replaceAction",
            "replacee": {
                "@type": "propertyValue",
                "propertyID": "derived_NAICS",
                "value": "44"
            },
            "replacer": {
                "@type": "propertyValue",
                "propertyID": "derived_NAICS",
                "value": "22"
            }
        },
        {
            "@type": "createAction",
            "instrument": {
                "@type": "'organization'",
                "name": "r.business_name",
                "legalName": "r.business_name",
                "naics": [
                    "r.derived_NAICS", 
                    "r.source_NAICS_primary",
                    "r.source_NAICS_secondary"
                ],
                "numberOfEmployees": "r.get('total_no_employees', None)",
                "brand": "r.alt_business_name",
                "description":  "r.get('business_description', None)",
                "taxID": "r.get('business_id_no', None)",
                "location": {
                    "@type": "'place'",
                    "latitude": "r.latitude",
                    "longitude": "r.longitude",
                    "address": {
                        "@type": "'PostalAddress'",
                        "streetAddress": "(r.unit + ', ' + r.street_no + ' ' +  r.street_name) if r.unit else (r.street_no + ' ' +  r.street_name)",
                        "addressLocality": "r.city",
                        "addressRegion":  "r.prov_terr",
                        "postalCode": "r.postal_code",
                        "addressCountry": "'CA'"
                    }
                }
            }
        }
    ],
    "url": "https://www150.statcan.gc.ca/n1/pub/21-26-0003/212600032023001-eng.htm"
}



Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kraken-convert-0.0.7.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

kraken_convert-0.0.7-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file kraken-convert-0.0.7.tar.gz.

File metadata

  • Download URL: kraken-convert-0.0.7.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for kraken-convert-0.0.7.tar.gz
Algorithm Hash digest
SHA256 701e62e351903d80be3faefc70705327c547ca6a77dae56d252499384d6c7d7d
MD5 1d366701df12ac6db396a2dec6158351
BLAKE2b-256 ddc9f644647fb5f84337e485e4302f4471e046a951cfc6fc976339795fb4891f

See more details on using hashes here.

File details

Details for the file kraken_convert-0.0.7-py3-none-any.whl.

File metadata

File hashes

Hashes for kraken_convert-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 19280fd3049d4eebca4300684b89e70e7889aa5a35b2e34504433f5719403086
MD5 914f1c2f58d5d321ece498992000e71f
BLAKE2b-256 7a6e683fa1d1238e5f1bc4a8ac1ee8a04cd5f201011b6998fb1d91fce7e8fade

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page