Skip to main content

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"
}



Release files for kraken-convert 0.0.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kraken-convert 0.0.7
File Size Uploaded
kraken-convert-0.0.7.tar.gz 7.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for kraken-convert 0.0.7
File Interpreter ABI Platform
kraken_convert-0.0.7-py3-none-any.whl Python 3 none any Details

Total release size: 15.8 kB

Release files / kraken-convert-0.0.7.tar.gz

Download URL kraken-convert-0.0.7.tar.gz
Size 7.9 kB
Tags Source
SHA-256 checksum
How to use checksums
701e62e351903d80be3faefc70705327c547ca6a77dae56d252499384d6c7d7d
BLAKE2b-256 checksum
How to use checksums
ddc9f644647fb5f84337e485e4302f4471e046a951cfc6fc976339795fb4891f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.18

Release files / kraken_convert-0.0.7-py3-none-any.whl

Download URL kraken_convert-0.0.7-py3-none-any.whl
Size 7.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
19280fd3049d4eebca4300684b89e70e7889aa5a35b2e34504433f5719403086
BLAKE2b-256 checksum
How to use checksums
7a6e683fa1d1238e5f1bc4a8ac1ee8a04cd5f201011b6998fb1d91fce7e8fade
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.18

Release history Release notifications | RSS feed

This release

0.0.7 This release

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.3

2 release files

0.0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page