def getpartdate(ye, mo): """ creates a date at 01/m/y """ months = { "january": 1, "february": 2, "march": 3, "april": 4, "may": 5, "june": 6, "july": 7, "august": 8, "september": 9, "october": 10, "november": 11, "december": 12 } d = 1 m = 1 if mo.strip() != "" and mo in months: m = months[mo] y = asm.cint(ye) if y == 0: return None return datetime.datetime(y, m, d)
if a.DateOfBirth is None: a.DateOfBirth = asm.subtract_days(a.DateBroughtIn, 365) a.CreatedDate = a.DateBroughtIn a.LastChangedDate = a.DateBroughtIn a.ShortCode = d["File"] a.ShelterCode = str(a.ID) + " " + d["File"] a.BreedID = asm.breed_id_for_name(d["Breed"].replace(" mix", "")) a.BreedName = asm.breed_name_for_id(a.BreedID) if d["Breed"].find("mix") != -1: a.CrossBreed = 1 a.Breed2ID = 442 a.BreedName = asm.breed_name(a.BreedID, a.Breed2ID) a.BaseColourID = asm.colour_id_for_name(d["Color"]) a.Sex = asm.getsex_mf(d["Male Female"]) a.Weight = asm.cint(d["Weight"].replace("lbs", "").strip()) if a.Weight > 0: l = asm.Log() logs.append(l) l.LogTypeID = 4 # Weight l.LinkID = a.ID l.LinkType = 0 l.Date = a.DateBroughtIn l.Comments = d["Weight"] a.NeuteredDate = getdate(d["Spay Neuter Date"]) if a.NeuteredDate is not None: a.Neutered = 1 a.HealthProblems = d["Medical Notes"] create_vacc("Rabies", d["Rabies Date"], d["Rabies Renewal"])
a.AnimalName = d["Name"] if a.AnimalName.strip() == "": a.AnimalName = "(unknown)" a.DateBroughtIn = asm.getdate_mmddyy(d["IntakeDate"]) if a.DateBroughtIn is None: a.DateBroughtIn = lastbroughtin else: lastbroughtin = a.DateBroughtIn a.BreedID = asm.breed_id_for_name(d["CatBreed"], 261) a.BaseColourID = asm.colour_id_for_name(d["CatColor"]) a.AnimalTypeID = asm.iif(d["OwnerSurrender"] == "1", 11, 12) a.SpeciesID = 2 a.Sex = asm.getsex_mf(d["Sex"]) a.DateOfBirth = asm.getdate_mmddyy(d["DOB"]) if a.DateOfBirth is None: dy = 365 * asm.cint(d["AgeYrs"]) dy += 30 * asm.cint(d["AgeMos"]) dy += 7 * asm.cint(d["AgeWks"]) dy += asm.cint(d["AgeDays"]) a.DateOfBirth = asm.subtract_days(a.DateBroughtIn, dy) a.Neutered = asm.iif(d["SpayOrNeuteredPreviously"] == "1", 1, 0) if a.Neutered == 0: a.Neutered = asm.iif(d["Spay/NeuterDate"] != "", 1, 0) a.NeuteredDate = asm.getdate_mmddyy(d["Spay/NeuterDate"]) a.AnimalComments = d["Comments"] a.IdentichipDate = asm.getdate_mmddyy(d["MicrochipDate"]) if a.IdentichipDate is not None: a.Identichipped = 1 a.IdentichipNumber = d["Microchip#"] a.CombiTestDate = asm.getdate_mmddyy(d["FIV/FELVDate"]) if a.CombiTestDate is not None:
a.AnimalTypeID = animaltype # There is a species column, but the last file I saw it seemed to be pretty optional and not filled in a.SpeciesID = asm.species_id_for_name(d["as_animal_type"]) a.generateCode() a.ShortCode = d["id"] a.ShelterCode = d["id"] a.AnimalName = d["name"] a.AcceptanceNumber = d["litter_id"] a.DateBroughtIn = getdate(d["intake_date"]) if a.DateBroughtIn is None: a.DateBroughtIn = getdate(d["created_at"]) a.DateOfBirth = getdate(d["birthday"]) if a.DateOfBirth is None: a.DateOfBirth = a.DateBroughtIn a.Sex = 1 if d["gender"] == "1": # They use 1 for female, 0 for male a.Sex = 0 a.Size = asm.cint(d["size_when_grown"]) primary = d["breed"] secondary = d["breed_secondary"] asm.breed_ids(a, primary, secondary, DEFAULT_BREED) color = d["color_primary"] a.BaseColourID = asm.colour_id_for_name(color) a.IdentichipNumber = d["tattoo"] if a.IdentichipNumber != "": a.Identichipped = 1 a.Weight = asm.atof(d["weight"]) a.Neutered = d["altered"] == "true" and 1 or 0 intaketype = d["intake_reason"] if intaketype.find("Transfer In") != -1: a.IsTransfer = 1 a.EntryReasonID = 15 elif intaketype.find("Stray") != -1: a.EntryReasonID = 7
o.OwnerTown = add["city"] o.OwnerCounty = add["state"] o.OwnerPostcode = add["zip"] else: # Otherwise, address fields are in the person table o.OwnerAddress = row["ADDR1"].encode( "ascii", "xmlcharrefreplace") + "\n" + row["ADDR2"].encode( "ascii", "xmlcharrefreplace") o.OwnerTown = row["CITY"] o.OwnerCounty = row["STATE"] o.OwnerPostcode = row["POSTAL_ID"] if asm.strip(row["EMAIL"]) != "(": o.EmailAddress = asm.strip(row["EMAIL"]) if row["HOME_PH"] != 0: o.HomeTelephone = asm.strip(row["HOME_PH"]) if row["WORK_PH"] != 0: o.WorkTelephone = asm.strip(row["WORK_PH"]) if row["THIRD_PH"] != 0: o.MobileTelephone = asm.strip(row["THIRD_PH"]) o.IsACO = asm.cint(row["ACO_IND"]) o.IsStaff = asm.cint(row["STAFF_IND"]) o.IsVolunteer = asm.cint(row["VOL_IND"]) o.IsDonor = asm.cint(row["DONOR_IND"]) o.IsMember = asm.cint(row["MEMBER_IND"]) o.IsBanned = asm.cint(row["NOADOPT"] == "T" and "1" or "0") if "FOSTERS" in row: o.IsFosterer = asm.cint(row["FOSTERS"]) # o.ExcludeFromBulkEmail = asm.cint(row["MAILINGSAM"]) # Not sure this is correct # Animals for row in canimal: if not IMPORT_ANIMALS_WITH_NO_NAME and row["PETNAME"].strip() == "": continue a = asm.Animal() animals.append(a) ppa[row["ANIMALKEY"]] = a
a = ppa[d["Animal ID"]] intaketype = d[ "Intake Type"] # Seems to change names a lot, has been AnimalIntakeType, Entry Category subtype = d[ "Intake Sub-Type"] # Also seems to change, has been AnimalIntakeSub-Type, Animal Type # Intake Date if "Intake Date" in d: a.DateBroughtIn = getdate(d["Intake Date"]) # Intake person linkperson = 0 if "Intake From Name" in d and d["Intake From Name"] != "" and d[ "Intake From Name"] in ppo: linkperson = ppo[d["Intake From Name"]].ID # Age if "Age (Months)" in d: a.DateOfBirth = asm.subtract_days( a.DateBroughtIn, 30 * asm.atoi(asm.cint(d["Age (Months)"]))) # Location if "Location" in d and d["Location"] != "": locs = d[ "Location"] # Locations are a comma separated list, with latest on the right if locs.find(",") != -1: locs = locs[locs.rfind(",") + 1:] a.ShelterLocation = asm.location_id_for_name(locs, True) # a.ShelterLocation = asm.location_from_db(locs) if intaketype == "Transfer In": a.IsTransfer = 1 a.EntryReasonID = 15 a.BroughtInByOwnerID = linkperson elif intaketype == "Stray": a.EntryReasonID = 7 a.BroughtInByOwnerID = linkperson elif intaketype == "Surrender":
if d["Animal ID"] == "Animal ID": continue if d["Animal ID"] not in ppa: continue a = ppa[d["Animal ID"]] intaketype = d["Intake Type"] # Seems to change names a lot, has been AnimalIntakeType, Entry Category subtype = d["Intake Sub-Type"] # Also seems to change, has been AnimalIntakeSub-Type, Animal Type # Animal name if "Name" in d: a.AnimalName = d["Name"] # Intake Date if "Intake Date" in d: a.DateBroughtIn = getdate(d["Intake Date"]) # Intake person linkperson = 0 if "Intake From Name" in d and d["Intake From Name"] != "" and d["Intake From Name"] in ppo: linkperson = ppo[d["Intake From Name"]].ID # Age if "Age (Months)" in d: a.DateOfBirth = asm.subtract_days(a.DateBroughtIn, 30 * asm.atoi(asm.cint(d["Age (Months)"]))) # Location if "Location" in d and d["Location"] != "": locs = d["Location"] # Locations are a comma separated list, with latest on the right if locs.find(",") != -1: locs = locs[locs.rfind(",")+1:] a.ShelterLocation = asm.location_id_for_name(locs, True) # a.ShelterLocation = asm.location_from_db(locs) if intaketype == "Transfer In": a.IsTransfer = 1 a.EntryReasonID = 15 a.BroughtInByOwnerID = linkperson elif intaketype == "Stray": a.EntryReasonID = 7 a.BroughtInByOwnerID = linkperson elif intaketype == "Surrender": a.EntryReasonID = 17
if a.AnimalName.strip() == "": a.AnimalName = "(unknown)" a.DateBroughtIn = d.dogIntakeDate or d.dateAdded a.DateOfBirth = d.dogDateBorn or a.DateBroughtIn a.CreatedDate = d.dateAdded or a.DateBroughtIn a.CreatedBy = d.addedBy or "conversion" a.LastChangedBy = d.modifiedBy or "conversion" a.LastChangedDate = d.dateModified or a.CreatedDate a.generateCode() if d.dogSerialNum and asm.nulltostr(d.dogSerialNum) != "": a.ShortCode = d.dogSerialNum a.Sex = asm.iif(d.dogSex.lower().startswith("m"), 1, 0) a.Neutered = asm.iif( d.dogSex.lower().find("s") != -1 or d.dogSex.lower().find("n") != -1, 1, 0) a.Size = 2 a.Weight = asm.cint(d.dogWeight) a.NeuteredDate = d.dogDateNeutered a.IsGoodWithCats = asm.iif(d.dogWithCats == 1, 0, 1) a.IsGoodWithDogs = asm.iif(d.dogWithDogs == 1, 0, 1) a.IsGoodWithChildren = asm.iif(d.dogWithKids == 1, 0, 1) a.IsHouseTrained = asm.iif(d.dogHousebroken == 1, 0, 1) if d.dogLeftEarNum != "" or d.dogRightEarNum != "": a.Tattoo = 1 a.TattooNumber = "L:%s R:%s" % (d.dogLeftEarNum, d.dogRightEarNum) a.RabiesTag = d.dogRabiesTag a.HeartwormTestDate = d.dogHWTDate if a.HeartwormTestDate is not None: a.HeartwormTested = 1 a.Archived = 0 a.AnimalComments = note_fix(d.dogDescription) comments = "Color: %s" % d.dogColor
o.OwnerSurname = row["LNAME"] o.OwnerName = o.OwnerTitle + " " + o.OwnerForeNames + " " + o.OwnerSurname # Find the address if addrlink.has_key(row["PERSONKEY"]): addrkey = addrlink[row["PERSONKEY"]] if addresses.has_key(addrkey): add = addresses[addrkey] o.OwnerAddress = add["address"] o.OwnerTown = add["city"] o.OwnerCounty = add["state"] o.OwnerPostcode = add["zip"] o.EmailAddress = row["EMAIL"] o.HomeTelephone = row["HOME_PH"] o.WorkTelephone = row["WORK_PH"] o.MobileTelephone = row["THIRD_PH"] o.IsACO = asm.cint(row["ACO_IND"]) o.IsStaff = asm.cint(row["STAFF_IND"]) o.IsVolunteer = asm.cint(row["VOL_IND"]) o.IsDonor = asm.cint(row["DONOR_IND"]) o.IsMember = asm.cint(row["MEMBER_IND"]) o.IsBanned = asm.cint(row["NOADOPT"] == "T" and "1" or "0") o.IsFosterer = asm.cint(row["FOSTERS"]) o.ExcludeFromBulkEmail = asm.cint(row["MAILINGSAM"]) # Animals for row in canimal: a = asm.Animal() animals.append(a) ppa[row["ANIMALKEY"]] = a a.DateBroughtIn = asm.getdate_yyyymmdd(row["ADDEDDATET"]) if a.DateBroughtIn is None:
a.SpeciesID = 2 else: a.SpeciesID = asm.species_id_for_name(row["SPECIES"]) a.generateCode(gettypeletter(a.AnimalTypeID)) a.ShortCode = row["FORMNUM"] ob = row["BREEDID"] a.CrossBreed = 0 if ob.find("Mix") != -1: a.CrossBreed = 1 a.Breed2ID = 442 ob = ob.replace("Mix", "") a.BreedID = asm.breed_id_for_name(ob) a.BreedName = asm.breed_name(a.BreedID, a.Breed2ID) a.Sex = asm.getsex_mf(row["SEX"]) a.Size = getsize(row["RSize"]) a.Neutered = asm.cint(row["SPAYED"]) a.NeuteredDate = asm.getdate_mmddyy(row["SPAYDATE"]) a.DateOfBirth = asm.getdate_mmddyy(row["DOB"]) if a.DateOfBirth is None: a.DateOfBirth = a.DateBroughtIn a.BaseColourID = asm.colour_id_for_name(row["RColor"]) a.RabiesTag = row["TAG"] a.IdentichipNumber = row["MICROCHIP"] if a.IdentichipNumber.strip() != "": a.Identichipped = 1 a.IdentichipDate = a.DateBroughtIn a.AnimalName = row["PETNAME"] if a.AnimalName == "": a.AnimalName = "(unknown)" a.Markings = row["RDescr"] comments = ""
if a.EntryReasonID == 7: a.AnimalTypeID = 12 # Stray Cat elif d["Species"] == "Dog": a.AnimalTypeID = 2 # Unwanted Dog if a.EntryReasonID == 7: a.AnimalTypeID = 10 # Stray Dog else: a.AnimalTypeID = 40 # Misc a.SpeciesID = asm.species_id_for_name(d["Species"]) a.AnimalName = d["AnimalName"] if a.AnimalName.strip() == "": a.AnimalName = "(unknown)" a.DateBroughtIn = getdate(d["IntakeDate"]) if a.DateBroughtIn is None: a.DateBroughtIn = asm.today() ageinmonths = asm.cint(d["AgeMonths"]) age = asm.cint(d["Age"]) if age > 0: ageinmonths += (age * 12) if ageinmonths == 0: ageinmonths = 12 a.DateOfBirth = asm.subtract_days(a.DateBroughtIn, int(ageinmonths * 30.5)) a.CreatedDate = getdate(d["CreateDate"]) a.LastChangedDate = getdate(d["UpdateDate"]) a.generateCode() if asm.cint(d["AnimalNumber"]) > 0: a.ShortCode = d["AnimalNumber"] else: # Animals with a 0 or non-integer number are non-shelter a.NonShelterAnimal = 1 a.Archived = 1 a.OriginalOwnerID = get_asm_ownerid(d["ID"])
dt.Description = row["Desc"] dt.DefaultCost = asm.get_currency(row["Amount"]) # invoices.csv for row in asm.csv_to_list(PATH + "invoices.csv"): if not ppt.has_key(row["Item"]): continue if not ppo.has_key(row["custid"]): continue od = asm.OwnerDonation() ownerdonations.append(od) dt = ppt[row["Item"]] o = ppo[row["custid"]] od.OwnerID = o.ID od.DonationTypeID = dt.ID od.Date = asm.getdate_ddmmyyyy(row["Date"]) od.Donation = asm.get_currency(row["Amount"]) od.Quantity = asm.cint(row["Qty"]) try: od.UnitPrice = od.Donation / od.Quantity except: od.UnitPrice = od.Donation od.Comments = row["Desc"] # Now that everything else is done, output stored records for o in owners: print o for od in ownerdonations: print od for dt in donationtypes: print dt print "DELETE FROM configuration WHERE ItemName Like 'VariableAnimalDataUpdated';"
a.NonShelterAnimal = 1 a.generateCode("A") a.BreedID = asm.breed_from_db(row["Breed"]) a.Breed2ID = asm.breed_from_db(row["Crossbreed type"], 0) a.BreedName = row["Breed"] if row["Crossbreed type"] != "": a.BreedName += " / " + row["Crossbreed type"] a.BaseColourID = asm.colour_from_db(row["Colour"]) a.IdentichipNumber = row["Microchipped Number"] if a.IdentichipNumber != "": a.Identichipped = 1 a.TattooNumber = row["Tattoo Number"] if a.TattooNumber != "": a.Tattoo = 1 a.Neutered = asm.iif(row["Neutered/Spayed"] != "No", 1, 0) a.ShelterLocation = 1 a.Markings = row["Marking"] a.Weight = asm.cint(row["Weight"]) a.Sex = asm.getsex_mf(row["Sex"]) a.Size = asm.size_from_db(row["Size"]) a.CoatType = asm.coattype_from_db(row["Coat Type"]) a.Archived = 1 # the licence ol = asm.OwnerLicence() ownerlicences.append(ol) lt = row["Licence Type"] ol.OwnerID = o.ID ol.AnimalID = a.ID ol.LicenceTypeID = asm.licencetype_from_db(lt) licnum = "%s%s-%s" % (lt[0:3].upper(), lt[len(lt) - 2:], row["Licence Number"]) if numused.has_key(licnum):
for d in ccatinfo: a = asm.Animal() animals.append(a) ppa[d["CatName"]] = a a.AnimalTypeID = 12 # stray cat if d["AcquiredType"].startswith("County"): a.AnimalTypeID = 44 # county shelter cat a.TransferIn = 1 a.SpeciesID = 2 a.AnimalName = d["CatName"] if a.AnimalName.strip() == "": a.AnimalName = "(unknown)" a.DateBroughtIn = asm.getdate_mmddyy(d["DateAcquired"]) if a.DateBroughtIn is None: a.DateBroughtIn = asm.today() ea = asm.cint(d["EstimatedAge"]) eu = d["EstimatedAgeUnits"] if eu.startswith("Week"): ea = ea * 7 elif eu.startswith("Month"): ea = ea * 30.5 elif eu.startswith("Year"): ea = ea * 365 a.DateOfBirth = asm.subtract_days(a.DateBroughtIn, ea) if a.DateOfBirth is None: a.DateOfBirth = asm.today() a.CreatedDate = a.DateBroughtIn a.LastChangedDate = a.DateBroughtIn a.generateCode() a.ShortCode = d["IDNumber"] a.Markings = d["Description"]