a.HealthProblems = d["Known issues"] ec = d["Entry Category"].strip().lower() if ec.startswith("stray"): a.EntryReasonID = 7 elif ec.startswith("surrender"): a.EntryReasonID = 17 elif ec.startswith("born"): a.EntryReasonID = 13 elif ec.startswith("transfer"): a.EntryReasonID = 15 a.TransferIn = 1 a.ReasonForEntry = d["Source/origin"] a.AnimalComments = d["Full description"] a.DateBroughtIn = getdate(d["Arrival"]) or asm.today() a.DateOfBirth = getdate(d["Date of birth"]) if a.DateOfBirth is None: a.DateOfBirth = asm.subtract_days(a.DateBroughtIn, 365) a.CreatedDate = a.DateBroughtIn a.LastChangedDate = a.DateBroughtIn hcomments = d["Internal notes"] hcomments = "\nEntry category: " + d["Entry Category"] hcomments += "\nBreed: " + d["Breeds"] + "/" + d["CrossBreed"] hcomments += "\nColor: " + d["Color"] hcomments += "\nDisposition: " + d["Disposition"] a.HiddenAnimalDetails = hcomments dd = getdate(d["Disposition date"]) di = d["Disposition"].strip()
for d in asm.csv_to_list(ADOPTED_FILENAME): # Each row contains an animal, person and adoption if d["PET NAME"].strip() == "": continue a = asm.Animal() animals.append(a) species, gender, neutered = get_sgn(d["SPECIES / GENDER"]) if species == "F": a.AnimalTypeID = 11 # Unwanted Cat a.SpeciesID = 2 else: a.AnimalTypeID = 2 # Unwanted Dog a.SpeciesID = 1 a.AnimalName = d["PET NAME"] if a.AnimalName.strip() == "": a.AnimalName = "(unknown)" a.DateBroughtIn = getdate(d["INTAKE"]) or asm.today().replace( year=2017, month=1, day=1) a.DateOfBirth = getdate(d["DOB"]) or a.DateBroughtIn a.CreatedDate = a.DateBroughtIn a.LastChangedDate = a.DateBroughtIn a.generateCode() a.Sex = asm.getsex_mf(gender) breed, color = get_bc(d["BREED/COLOR"]) breed = breed.strip() color = color.strip() asm.breed_ids(a, breed) a.BaseColourID = asm.colour_id_for_name(color) a.Size = 2 a.Neutered = neutered in ("N", "S") and 1 or 0 a.EntryReasonID = 17 # Surrender a.IdentichipNumber = d["AVID #"] if a.IdentichipNumber != "":
if ol.ExpiryDate is None: ol.ExpiryDate = asm.add_days(ol.IssueDate, 3650) ol.Comments = "Item: %s\nAnimal: %s\nReceipt: %s" % ( d["Fee Item"], d["Animal Name"], d["Receipt #"]) # People and microchips next for d in asm.csv_to_list("%s/microchips.csv" % PATH, strip=True): if d["Associated people"].strip() == "": continue # Can't do anything without person if d["Microchip"].strip() == "": continue # Pointless without an actual microchip o = get_owner(d["Associated people"].strip()) # Bare minimum non-shelter animal record for the microchip a = asm.Animal() animals.append(a) a.AnimalTypeID = 40 # Non-shelter a.DateBroughtIn = asm.today() a.ShelterCode = "%s (%s)" % (d["Microchip"], a.ID) a.ShortCode = d["Microchip"] a.NonShelterAnimal = 1 a.Archived = 1 a.AnimalName = d["Animal"] a.OwnerID = o.ID a.OriginalOwnerID = o.ID a.IdentichipNumber = d["Microchip"] a.Identichipped = 1 a.SpeciesID = d["Species"] == "Cat" and 2 or 1 a.Sex = asm.getsex_mf(d["Gender"]) a.Neutered = d["Altered"] == "Yes" and 1 or 0 # Dispatch/incidents typemap = {
ppa[d["Animal #"]] = a if d["Species"] == "Cat": a.AnimalTypeID = 11 # Unwanted Cat if d["Intake Type"] == "Stray": a.AnimalTypeID = 12 # Stray Cat elif d["Species"] == "Dog": a.AnimalTypeID = 2 # Unwanted Dog if d["Intake Type"] == "Stray": a.AnimalTypeID = 10 # Stray Dog else: a.AnimalTypeID = 40 # Misc a.SpeciesID = asm.species_id_for_name(d["Species"]) a.AnimalName = d["Animal Name"] if a.AnimalName.strip() == "": a.AnimalName = "(unknown)" a.DateBroughtIn = getdate(d["Intake Date"]) or asm.today() if "Date Of Birth" in d and d["Date Of Birth"].strip() != "": a.DateOfBirth = getdate(d["Date Of Birth"]) else: a.DateOfBirth = asm.subtract_days(a.DateBroughtIn, 365) a.CreatedDate = a.DateBroughtIn a.LastChangedDate = a.DateBroughtIn if d["Intake Type"] == "Transfer In": a.IsTransfer = 1 a.generateCode() a.ShortCode = d["ARN"] if a.ShortCode.strip() == "": a.ShortCode = d["Animal #"] if "Distinguishing Markings" in d: a.Markings = d["Distinguishing Markings"] a.IsNotAvailableForAdoption = 0 a.ShelterLocation = asm.location_id_for_name(d["Location"])
for d in asm.csv_to_list_cols(ANIMAL_FILENAME, ANIMAL_COLS): # Each row contains an animal a = asm.Animal() animals.append(a) ppa[d["ID"]] = a if d["Species"] == "Cat": a.AnimalTypeID = 11 # Unwanted Cat elif d["Species"] == "Dog": a.AnimalTypeID = 2 # Unwanted Dog else: a.AnimalTypeID = 40 # Misc a.SpeciesID = asm.species_id_for_name(d["Species"]) a.AnimalName = d["Name"] if a.AnimalName.strip() == "": a.AnimalName = "(unknown)" a.DateBroughtIn = getdate(d["AddedDate"]) or asm.today() a.DateOfBirth = getdate(d["DOB"]) or asm.subtract_days( a.DateBroughtIn, 365) a.CreatedDate = getdate(d["AddedDate"]) a.CreatedBy = d["AddedBy"] a.LastChangedDate = getdate(d["AddedDate"]) a.LastChangedBy = d["AddedBy"] #if d["Intake Type"] == "Transfer In": # a.IsTransfer = 1 a.generateCode() a.IsNotAvailableForAdoption = 0 a.Sex = asm.getsex_mf(d["Sex"]) a.Size = 2 a.Neutered = d["Altered"] == "TRUE" and 1 or 0 a.EntryReasonID = 17 # Surrender a.IsGoodWithCats = 2
"https://api.petfinder.com/v2/oauth2/token", "grant_type=client_credentials&client_id=" + API_KEY + "&client_secret=" + SECRET_KEY) access_token = json.loads(r["response"])["access_token"] data = asm.get_url(URL, headers={"Authorization": "Bearer " + access_token}) rows = json.loads(data["response"])["animals"] asm.stderr("processing %d animals" % len(rows)) for r in rows: asm.stderr(r) broughtin = getdate(r["published_at"]) if broughtin is None: broughtin = asm.today() petid = nte(r["id"]) name = nte(r["name"]) breed1 = nte(r["breeds"]["primary"]) breed2 = nte(r["breeds"]["secondary"]) crossbreed = r["breeds"]["mixed"] species = nte(r["species"]) color = nte(r["colors"]["primary"]) size = nte(r["size"]) coat = nte(r["coat"]) age = nte(r["age"]) sex = nte(r["gender"]) description = nte(r["description"]) description = asm.strip_unicode(description) description = description.replace("'", "'").replace( """, "\"").replace("'", "'").replace(" ", " ")
animaltype = 11 animalletter = "U" else: animaltype = 2 animalletter = "D" a.AnimalTypeID = animaltype a.SpeciesID = asm.species_id_for_name(d["Species"]) if "Animal ID" in d: a.ShortCode = "RG%s" % d["Animal ID"] a.ShelterCode = "%s %s" % (a.ShortCode, a.ID) ppa[d["Animal ID"]] = a else: a.generateCode() a.AnimalName = d["Name"] broughtin = asm.today() if "Created" in d and d["Created"] != "": broughtin = getdate(d["Created"]) if "Received Date" in d and d["Received Date"] != "": broughtin = getdate(d["Received Date"]) a.DateBroughtIn = broughtin dob = broughtin a.EstimatedDOB = 1 if "General Age" in d: if d["General Age"].find("Baby") != -1: dob = asm.subtract_days(asm.today(), 91) elif d["General Age"].find("Young") != -1: dob = asm.subtract_days(asm.today(), 182) elif d["General Age"].find("Adult") != -1: dob = asm.subtract_days(asm.today(), 730)
o.Comments = d["PERSONCOMMENTS"] o.JurisdictionID = asm.jurisdiction_from_db( d["PERSONADDITIONALCOUNCILNAME"]) # Animal intake records for d in asm.csv_to_list(ANIMAL_FILENAME, remove_non_ascii=True): # Each row contains an animal with intake info: a = asm.Animal() animals.append(a) ppa[d["Animal_Identifier"]] = a a.SpeciesID = asm.species_id_for_name(d["Species"]) a.AnimalTypeID = asm.type_id_for_species_id(a.SpeciesID) a.AnimalName = d["Name"] if a.AnimalName.strip() == "": a.AnimalName = "(unknown)" a.DateBroughtIn = getdate(d["Date_Admitted"]) or asm.today() if d["Date_Of_Birth"].strip() != "": a.DateOfBirth = getdate(d["Date_Of_Birth"]) if a.DateOfBirth is None: a.DateOfBirth = asm.subtract_days(a.DateBroughtIn, 365) a.CreatedDate = a.DateBroughtIn a.LastChangedDate = a.DateBroughtIn #asm.additional_field("Legacy_Tag_No", 0, a.ID, d["Tag_no"]) #asm.additional_field("Legacy_Tag_No_Q", 0, a.ID, d["Tag_no_qualifier"]) a.ShortCode = d["Tag_no"] a.ShelterCode = a.ShortCode a.BreedID = asm.breed_from_db(d["Breed"], 1) a.BreedName = d["Breed"] if d["Cross_Breed"] != "": a.Breed2ID = asm.breed_from_db(d["Cross_Breed"], 1) a.CrossBreed = 1
for d in asm.csv_to_list("%s/animals.csv" % PATH): a = asm.Animal() animals.append(a) ppa[d["ID"]] = a if d["Species"] == "Cat": a.AnimalTypeID = 11 # Unwanted Cat elif d["Species"] == "Dog": a.AnimalTypeID = 2 # Unwanted Dog else: a.AnimalTypeID = 40 # Misc a.SpeciesID = asm.species_id_for_name(d["Species"]) a.AnimalName = d["Name"] if a.AnimalName.strip() == "": a.AnimalName = "(unknown)" a.DateBroughtIn = getdate(d["Date of Well Check"]) or getdate(d["Adopted Date"]) or getdate(d["Birthday"]) or asm.today() a.DateOfBirth = getdate(d["Birthday"]) or a.DateBroughtIn a.CreatedDate = a.DateBroughtIn a.LastChangedDate = a.DateBroughtIn a.ShelterCode = d["ID"][d["ID"].rfind("-")+1:] a.ShortCode = a.ShelterCode a.BaseColourID = asm.colour_id_for_name(d["Animal Color"]) a.IsNotAvailableForAdoption = 0 a.Sex = asm.getsex_mf(d["Sex"]) a.Size = 2 a.Neutered = asm.iif(d["Spay / Neuter"] == "Yes", 1, 0) a.EntryReasonID = 17 # Surrender a.Archived = 0 a.HiddenAnimalDetails = "Color: %s\nPrevious Name: %s\nBiter: %s\nDiet: %s\n%s" % (d["Animal Color"], d["Previous Name"], d["Biter"], d["Diet"], d["Special Needs"]) a.SourceAdoptedDate = getdate(d["Adopted Date"])
for d in data: a = asm.Animal() animals.append(a) a.AnimalTypeID = asm.iif(d["Pet Type"] == "Cat", 11, 2) if a.AnimalTypeID == 11 and d["Intake Type"] == "Stray": a.AnimalTypeID = 12 a.SpeciesID = asm.species_id_for_name(d["Pet Type"]) a.AnimalName = d["Pet Name"] if a.AnimalName.strip() == "": a.AnimalName = "(unknown)" if d["DOB"].strip() == "": a.DateOfBirth = asm.getdate_mmddyyyy(d["Intake Date"]) else: a.DateOfBirth = asm.getdate_mmddyyyy(d["DOB"]) if a.DateOfBirth is None: a.DateOfBirth = asm.today() a.DateBroughtIn = asm.getdate_mmddyyyy(d["Intake Date"]) if a.DateBroughtIn is None: a.DateBroughtIn = asm.today() a.CreatedDate = asm.getdate_mmddyyyy(d["Added On"]) a.CreatedBy = "%s/%s" % (d["Added By"], "conversion") a.LastChangedDate = asm.getdate_mmddyyyy(d["Updated On"]) a.LastChangedBy = d["Last Updated By"] if d["Intake Type"] == "Shelter Transfer" or d[ "Intake Type"] == "Rescue Transfer": a.IsTransfer = 1 a.ShelterCode = d["Pet ID"] a.ShortCode = d["Pet ID"] a.Markings = d["Colors or Markings"] a.BaseColourID = asm.colour_id_for_name(d["Colors or Markings"], True) a.IsNotAvailableForAdoption = 0
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): licnum = licnum + "-2" if numused.has_key(licnum) and licnum.endswith("-2"): licnum = licnum[0:len(licnum) - 2] + "-3" ol.LicenceNumber = licnum numused[licnum] = "X" ol.LicenceFee = asm.get_currency(row["Fee"]) ol.IssueDate = asm.getdate_ddmmyyyy(row["Issued"]) ol.ExpiryDate = asm.getdate_ddmmyyyy(row["Expired"]) if ol.IssueDate is None: ol.IssueDate = asm.today() if ol.ExpiryDate is None: ol.ExpiryDate = asm.today() ol.Comments = row["Comments"] # Now that everything else is done, output stored records for a in animals: print a for o in owners: print o for ol in ownerlicences: print ol asm.stderr_summary(animals=animals, ownerlicences=ownerlicences, owners=owners) print "DELETE FROM configuration WHERE ItemName LIKE 'DBView%';" print "COMMIT;"