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.6.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: kraken-convert-0.0.6.tar.gz
  • Upload date:
  • Size: 8.0 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.6.tar.gz
Algorithm Hash digest
SHA256 f70370de42bad4db73a9a1f15b1f5b84aba16305b4b0a23151c86a5493d5ba90
MD5 f21f316893bc632ed0e387f51f8703ee
BLAKE2b-256 b4ef1cc175710c918c9013a3caec580fec004a1082862b1b63950f8fa6be9859

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kraken_convert-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 848f228f958143033c92ccef50e147d1ff102fe056264b8af4a1d5a09ca38943
MD5 17442903e4a5d83fbcc607ca6ba0d51d
BLAKE2b-256 d8ab02b956c65122464c54ac9a259dcc0527571bd1eb5e629e2597acfc4d8892

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