#!/usr/bin/python3
# create a frictionless data package by combining n data packages together
# given a dataset's data may come from multiple uploads from a data provider there would then be
# a need to be able to combine the upload data package jsons together to have one that represented
# the dataset in its entirety.
# proof of concept; not used;
import json
import sys
from datapackage import Package

concatPackageName = sys.argv[1]
concatDpkJson = {}
try:
    concatDpkJson = json.loads(sys.argv[2])
except:
    print("invalid json - 1st datapackage")
try:
    datapackageJson = Package(concatDpkJson)
except:
    print("invalid data package - 1st datapackage")
concatDpkJson['name'] = concatPackageName
i = 2
for arg in sys.argv[2:]:
    try:
        dpkgJson = json.loads(arg)
    except:
        print("invalid json - datapackage " + str(i))
    try:
        #is valid datapackage json?
        datapackageJson = Package(dpkgJson)
    except:
        print("invalid data package - datapackage " + str(i))
    concatDpkJson["resources"].extend(dpkgJson["resources"])
    i = i + 1
    #To do - need to test that resource names are unique 
try:
    #is valid datapackage json?
    combinedDataPackageJson = Package(concatDpkJson)
except:
    print("invalid combined data package")
print(json.dumps(concatDpkJson))
b333afab666e9a0b0a4441d0ca844383ca973771
<mask token>

<mask token>
try:
    concatDpkJson = json.loads(sys.argv[2])
except:
    print('invalid json - 1st datapackage')
try:
    datapackageJson = Package(concatDpkJson)
except:
    print('invalid data package - 1st datapackage')
<mask token>
for arg in sys.argv[2:]:
    try:
        dpkgJson = json.loads(arg)
    except:
        print('invalid json - datapackage ' + str(i))
    try:
        datapackageJson = Package(dpkgJson)
    except:
        print('invalid data package - datapackage ' + str(i))
    concatDpkJson['resources'].extend(dpkgJson['resources'])
    i = i + 1
try:
    combinedDataPackageJson = Package(concatDpkJson)
except:
    print('invalid combined data package')
print(json.dumps(concatDpkJson))

<mask token>
concatPackageName = sys.argv[1]
concatDpkJson = {}
try:
    concatDpkJson = json.loads(sys.argv[2])
except:
    print('invalid json - 1st datapackage')
try:
    datapackageJson = Package(concatDpkJson)
except:
    print('invalid data package - 1st datapackage')
concatDpkJson['name'] = concatPackageName
i = 2
for arg in sys.argv[2:]:
    try:
        dpkgJson = json.loads(arg)
    except:
        print('invalid json - datapackage ' + str(i))
    try:
        datapackageJson = Package(dpkgJson)
    except:
        print('invalid data package - datapackage ' + str(i))
    concatDpkJson['resources'].extend(dpkgJson['resources'])
    i = i + 1
try:
    combinedDataPackageJson = Package(concatDpkJson)
except:
    print('invalid combined data package')
print(json.dumps(concatDpkJson))

import json
import sys
from datapackage import Package
concatPackageName = sys.argv[1]
concatDpkJson = {}
try:
    concatDpkJson = json.loads(sys.argv[2])
except:
    print('invalid json - 1st datapackage')
try:
    datapackageJson = Package(concatDpkJson)
except:
    print('invalid data package - 1st datapackage')
concatDpkJson['name'] = concatPackageName
i = 2
for arg in sys.argv[2:]:
    try:
        dpkgJson = json.loads(arg)
    except:
        print('invalid json - datapackage ' + str(i))
    try:
        datapackageJson = Package(dpkgJson)
    except:
        print('invalid data package - datapackage ' + str(i))
    concatDpkJson['resources'].extend(dpkgJson['resources'])
    i = i + 1
try:
    combinedDataPackageJson = Package(concatDpkJson)
except:
    print('invalid combined data package')
print(json.dumps(concatDpkJson))

#!/usr/bin/python3
# create a frictionless data package by combining n data packages together
# given a dataset's data may come from multiple uploads from a data provider there would then be
# a need to be able to combine the upload data package jsons together to have one that represented
# the dataset in its entirety.
# proof of concept; not used;
import json
import sys
from datapackage import Package

concatPackageName = sys.argv[1]
concatDpkJson = {}
try:
    concatDpkJson = json.loads(sys.argv[2])
except:
    print("invalid json - 1st datapackage")
try:
    datapackageJson = Package(concatDpkJson)
except:
    print("invalid data package - 1st datapackage")
concatDpkJson['name'] = concatPackageName
i = 2
for arg in sys.argv[2:]:
    try:
        dpkgJson = json.loads(arg)
    except:
        print("invalid json - datapackage " + str(i))
    try:
        #is valid datapackage json?
        datapackageJson = Package(dpkgJson)
    except:
        print("invalid data package - datapackage " + str(i))
    concatDpkJson["resources"].extend(dpkgJson["resources"])
    i = i + 1
    #To do - need to test that resource names are unique 
try:
    #is valid datapackage json?
    combinedDataPackageJson = Package(concatDpkJson)
except:
    print("invalid combined data package")
print(json.dumps(concatDpkJson))