コード例 #1
0

def setAttrValue(d, k, v):
    for x in d["$values"]:
        if x["Name"] == k:
            x["Value"] = v


def getAttrValue(d, k):
    for x in d["$values"]:
        if x["Name"] == k:
            return x["Value"]


COUNT = 0
for aoitem in apiIterator("/api/AO_IndividualsData", []):
    #create item
    p = loads(TEMPLATE)
    #set id
    id = aoitem["Identity"]["IdentityElements"]["$values"][0]
    print("processing... {0}".format(id))
    p["Identity"]["IdentityElements"]["$values"][0] = id
    p["PrimaryParentIdentity"]["IdentityElements"]["$values"][0] = id
    setAttrValue(p["Properties"], "ID", id)

    # set HPE:
    hpe = getAttrValue(aoitem["Properties"], "HPETeachLevel")
    if hpe:
        #mapping
        hpe = MAPPING[hpe]
        setAttrValue(p["Properties"], "HPETeachLevel", hpe)
コード例 #2
0
from iMISutils import apiIterator, apipost, accessAttrib, updateAttrib
from sys import argv, exit
from json import loads
from pprint import pprint

if len(argv) != 4:
    print("Need Panelname, old attr, new attr.")
    exit(1)
PANEL = argv[1]
OLDATTR = argv[2].split(",")
NEWATTR = argv[3].split(",")
if len(OLDATTR) != len(NEWATTR):
    print("Mismatching length")
    exit(1)

COUNT = 0
for pitem in apiIterator("/api/{0}".format(PANEL), []):
    #id
    pid = "~{0}".format("|".join(
        pitem["Identity"]["IdentityElements"]["$values"]))
    print("processing... {0}".format(pid))

    for x in range(len(OLDATTR)):
        accessAttrib(pitem,
                     NEWATTR[x],
                     accessAttrib(pitem, OLDATTR[x], collection="Properties"),
                     collection="Properties")
    updateAttrib(pitem, PANEL, idval=pid)
    COUNT += 1
print("Processed: ({0}) entries.".format(COUNT))
コード例 #3
0
from sys import exit, argv

if len(argv) != 2:
    print("Require source and destination category.")
    exit(1)

SOURCE = argv[1]


def modifyItem(storeobj):
    storeobj["ItemFinancialInformation"]["IncursHandling"] = True
    storeobj["ItemFinancialInformation"]["IncursShipping"] = False

    sobj = json.dumps(storeobj)
    r = requests.put("%s/api/Item/%s" % (API_URL, storeobj["ItemId"]),
                     headers=HEADERS,
                     data=sobj)
    if r.status_code != 201:
        print(r.status_code)
        print(r.url)
        print("----")
        print(sobj)
        print("----")
        exit(1)


for storeobj in apiIterator("/api/Item",
                            (("ItemClassId", "SALES-%s" % SOURCE), )):
    print(storeobj["Name"].encode("utf-8"))
    modifyItem(storeobj)
コード例 #4
0
        for x in FINANCE_EMAILS_BEGINS:
            if email.startswith(x): return
        if any(x in email for x in FINANCE_EMAILS_CONTAINS): return
        # if no finance words found, dupe this record and place in Reception
        newaddr = dict(ADDR_TMPL)
        newaddr["AddressPurpose"] = "Reception"
        newaddr["Email"] = email
        orgobj["Addresses"]["$values"].append(newaddr)
        print "%s" % orgobj["PartyId"]
        jobj = json.dumps(orgobj)
        r = requests.put("%s/api/Party/%s" % (API_URL, orgobj["PartyId"]),
                         headers=HEADERS,
                         data=jobj)
        if r.status_code != 201:
            print r.status_code
            print r.text
            print "----"
            print jobj
            print "----"
            print HEADERS
            exit(1)


COUNT = 0
for orgobj in apiIterator("/api/Party",
                          (("Status", "A"), ("CustomerTypeCode", "ORG"))):
    print ".",
    if orgobj["Name"].startswith("*"): continue
    if getAddr(orgobj, "Reception"): continue
    checkAndAdd(orgobj)
コード例 #5
0
    if r.status_code != 201:
        print(r.status_code)
        print(r.text)
        print("----")
        print(sobj)
        print("----")
        exit(1)

COUNT = 0
if len(argv) != 2:
    print("Need comma list of shop types to process. [SAC,TE,WEB,HPE]")
    exit(1)
for type in argv[1].split(","):
    if type == "SAC":
        for cls in ("SALES-VCE-SACS-M", "SALES-VCE-SACS" ):
            for storeobj in apiIterator("/api/Item", (("ItemClassId", cls), ("ItemStatus", "A"))):
                print(storeobj["Name"].encode("utf-8"))
                modifyItem(storeobj, type="sac")
                print(".", end=" ")
                COUNT += 1
    elif type == "TE":
        for cls in ("SALES-VCE-TE", "SALES-VCE-TE-M"):
            for storeobj in apiIterator("/api/Item", (("ItemClassId", cls), ("ItemStatus", "A"))):
                print(storeobj["Name"].encode("utf-8"))
                modifyItem(storeobj, type="te")
                print(".", end=" ")
                COUNT += 1
    elif type == "WEB" or type == "HPE":
        for cls in ("SALES-HPEH", "SALES-HPEH-M", "SALES-VIC-WREC", "SALES-VIC-WREC-M"):
            for storeobj in apiIterator("/api/Item", (("ItemClassId", cls), ("ItemStatus", "A"))):
                print(storeobj["Name"].encode("utf-8"))
コード例 #6
0
from iMISutils import apiIterator, accessAttrib, updateAttrib
from json import load
from sys import argv, exit
from random import shuffle, randint
import unicodecsv

if len(argv) != 3:
    print("Require OLD_TYPE and NEW_TYPE.")
    exit(1)

OLD_TYPE = argv[1]
NEW_TYPE = argv[2]

COUNT = 0
print("Processing individuals ({0})".format(OLD_TYPE))
for item in apiIterator("/api/Person", [["CustomerTypeCode", OLD_TYPE],]):
    #set value
    accessAttrib(item, "CustomerTypeCode", NEW_TYPE)
    # write value
    print("Updating value... {0}".format(item["Id"]))
    if not updateAttrib(item, "Person"):
        print("Unhappy result.")
        break
    COUNT += 1
print("Processed: ({0}) entries.".format(COUNT))
コード例 #7
0
from iMISutils import apiIterator, accessAttrib, updateAttrib
from sys import argv, exit

if len(argv) != 3:
    print("Require OLD_TYPE and NEW_TYPE.")
    exit(1)

OLD_TYPE = argv[1]
NEW_TYPE = argv[2]

COUNT = 0
print("Processing events ({0})".format(OLD_TYPE))
for item in apiIterator("/api/Event", [["CategoryId", OLD_TYPE],]):
    #set value
    item["Category"]["EventCategoryId"] = NEW_TYPE
    # write value
    print("Updating value... {0}".format(item["EventId"]))
    if not updateAttrib(item, "Event", "EventId"):
        print("Unhappy result.")
        break
    COUNT += 1
print("Processed: ({0}) entries.".format(COUNT))
コード例 #8
0
from iMISutils import apiIterator, accessProperty, updateProperty
from json import load
from sys import argv, exit
from random import shuffle, randint
import unicodecsv

if len(argv) != 4:
    print("Require Business object, property, and JSON file for mapping old to new.")
    exit(1)

BUSINESS_OBJ = argv[1]
PROPERTY = argv[2]
JSON_MAP = load(open(argv[3], "rb"))
PROP_GOOD_VALS = set(JSON_MAP.values())

UNKNOWNS = [] # [[ID, data],]
print("Processing business object ({0})".format(BUSINESS_OBJ))
for item in apiIterator("/api/{0}".format(BUSINESS_OBJ), []):
    itemvalue = accessProperty(item, PROPERTY)
    if itemvalue in JSON_MAP:
        accessProperty(item, PROPERTY, JSON_MAP[itemvalue])
        # write value
        print("Updating value...")
        if not updateProperty(item, BUSINESS_OBJ):
            print("Unhappy result.")
            break
    elif itemvalue == "" or itemvalue is None: pass
    elif itemvalue not in PROP_GOOD_VALS:
        print("Bad data: ({0}) - {1}".format(item["Identity"]["IdentityElements"]["$values"][0], itemvalue))
コード例 #9
0
    print("Require MemberTypes.")
    exit(1)

MEMTYPES = argv[1].split(",")

CHAPTER = {
    "$type": "Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts",
    "Name": "Chapter",
    "Value": "VIC"
}

COUNT = 0
for MEMT in MEMTYPES:
    print("Processing type ({0})".format(MEMT))
    for csitem in apiIterator(
            "/api/CsContact",
        [["MemberType", MEMT], ["Chapter", "ne:VIC"], ["IsCompany", "false"]]):
        #get real person item:
        item = getPerson(csitem["Identity"]["IdentityElements"]["$values"][0])
        if item is False:
            print("Couldn't find person? ({0})".format(
                csitem["Identity"]["IdentityElements"]))
            exit(1)
        #check chapter:
        chap = accessAttrib(item, "Chapter")
        #set value
        if not chap:
            print("Creating chapter prop")
            addAttrib(item, CHAPTER)
        else:
            accessAttrib(item, "Chapter", "VIC")