def process_vacc(animalno, vaccdate=None, vaccexpires=None, vaccname=""): """ Processes a vaccination record. PP have multiple formats of this data file """ if ppa.has_key(animalno): a = ppa[animalno] else: asm.stderr("cannot process vacc %s, %s, %s, - no matching animal" % (animalno, vaccdate, vaccname)) return av = asm.AnimalVaccination() animalvaccinations.append(av) if vaccdate is None: vaccdate = a.DateBroughtIn av.AnimalID = a.ID av.VaccinationID = 8 vaccmap = { "Bordatella": 6, "Bordetella": 6, "6-in-1 Canine": 8, "5-in-1 Canine": 8, "4-in-1 Canine": 8, "D-A2-P": 8, "Rabies": 4, "FeLV": 12, "FVRCP": 14, "Distemper": 1 } for k, i in vaccmap.iteritems(): if vaccname.find(k) != -1: av.VaccinationID = i av.DateRequired = vaccdate av.DateOfVaccination = vaccdate av.DateExpires = vaccexpires av.Comments = "Type: %s" % vaccname
def get_asm_ownerid(oldanimalid): if not oldanimalid in atop: asm.stderr("can't find old animal id %s in PersonAnimal.csv" % oldanimalid) return 0 oldpersonid = atop[oldanimalid] if not oldpersonid in ppo: asm.stderr("can't find old person id %s in ppo" % oldpersonid) return 0 return ppo[oldpersonid].ID
def process_test(animalno, testdate=None, testname="", result=""): """ Process a test record """ if ppa.has_key(animalno): a = ppa[animalno] else: asm.stderr("cannot process test %s, %s, %s, %s - no matching animal" % (animalno, testdate, testname, result)) return at = asm.AnimalTest() animaltests.append(at) at.AnimalID = a.ID if testdate is None: testdate = a.DateBroughtIn at.DateRequired = testdate at.DateOfTest = testdate asmresult = 0 if result == "Negative": asmresult = 1 if result == "Positive": asmresult = 2 at.TestResultID = asmresult + 1 if testname == "Heartworm": a.HeartwormTested = 1 a.HeartwormTestDate = testdate a.HeartwormTestResult = asmresult at.TestTypeID = 3 elif testname == "FIV": a.CombiTested = 1 a.CombiTestDate = testdate a.CombiTestResult = asmresult at.TestTypeID = 1 elif testname == "FELV": a.CombiTested = 1 a.CombiTestDate = testdate a.FLVResult = asmresult at.TestTypeID = 2 else: at.TestTypeID = 1 at.Comments = "Test for %s" % testname
a.CreatedDate = m.MovementDate if "Outcome By" in d: a.CreatedBy = "conversion/%s" % d["Outcome By"] a.LastChangedDate = m.MovementDate movements.append(m) elif d["Outcome Type"] == "Euthanasia": a.DeceasedDate = getdate(d["Outcome Date"]) a.PutToSleep = 1 a.PTSReasonID = 4 # Sick a.Archived = 1 elif d["Outcome Type"] == "Died": a.DeceasedDate = getdate(d["Outcome Date"]) a.PutToSleep = 0 a.PTSReasonID = 2 # Died a.Archived = 1 else: asm.stderr("UNKNOWN OUTCOME TYPE '%s'" % d["Outcome Type"]) if asm.file_exists("%s/tests.csv" % PATH): for d in asm.csv_to_list("%s/tests.csv" % PATH): if d["Animal ID"] == "Animal ID": continue if d["Animal ID"] not in ppa: continue a = ppa[d["Animal ID"]] testdate = getdate(d["Date"]) t = asm.animal_test(a.ID, testdate, testdate, d["Product"], d["Result"]) animaltests.append(t) if asm.file_exists("%s/procedures.csv" % PATH): for d in asm.csv_to_list("%s/procedures.csv" % PATH): if d["Animal ID"] == "Animal ID": continue if d["Animal ID"] not in ppa: continue a = ppa[d["Animal ID"]]
a.CreatedDate = a.DateBroughtIn a.LastChangedDate = a.DateBroughtIn animals.append(a) # We don't have a placements file, use placement status to decide what to do if not USE_PLACEMENTS_FILE: if d["Placement Status"] == "Adopted" or d[ "Placement Status"] == "Fostered" or d[ "Placement Status"] == "Reclaimed": # Find the person o = None oname = "%s %s" % (d["First Name"], d["Last Name"]) if oname in pponame: o = pponame[oname] if o is None: asm.stderr("could not find person record for %s" % oname) continue m = asm.Movement() m.OwnerID = o.ID m.AnimalID = a.ID m.MovementDate = getdate(d["Placement Date"]) if m.MovementDate is None: m.MovementDate = a.DateBroughtIn if d["Placement Status"].strip() == "Adopted": m.MovementType = 1 a.Archived = 1 elif d["Placement Status"].strip() == "Reclaimed": m.MovementType = 5 a.Archived = 1 elif d["Placement Status"].strip() == "Fostered": m.MovementType = 2 movements.append(m)
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: asm.stderr("Bad datebroughtin: '%s'" % row["ADDEDDATET"]) a.DateBroughtIn = datetime.datetime.today() a.AnimalTypeID = gettype(row["ANIMLDES"]) a.generateCode(gettypeletter(a.AnimalTypeID)) if row["REGISTRATI"] != "": a.ShelterCode = "%s (%s)" % (row["REGISTRATI"], row["ANIMALKEY"]) a.ShortCode = row["REGISTRATI"] a.SpeciesID = asm.species_id_for_name(row["ANIMLDES"].split(" ")[0]) a.AnimalName = row["PETNAME"] if a.AnimalName.strip() == "": a.AnimalName = "(unknown)" age = row["AGE"].split(" ")[0] a.DateOfBirth = asm.getdate_yyyymmdd(row["DOB"]) if a.DateOfBirth is None: a.DateOfBirth = asm.now() a.EntryReasonID = 4 a.Neutered = asm.cint(row["FIX"])
"#8 Unlicensed loose": 3, "#9 Defecation": 2, "Dead Animal P/U": 6, "Barking": 8, "Owner Surrender p/u": 3, "Misc Animal Control": 10, "Cat in Trap Pick Up": 3, "Random Stray": 3 } for d in asm.csv_to_list("%s/dispatch.csv" % PATH, strip=True): ac = asm.AnimalControl() animalcontrol.append(ac) dd = get_dispatch_date(d["DispatchDate"]) if dd is None: dd = asm.today() asm.stderr("Bad dispatch date: %s" % d["DispatchDate"]) ac.CallDateTime = dd ac.IncidentDateTime = dd ac.DispatchDateTime = dd ac.CompletedDate = dd ac.IncidentTypeID = 3 ac.IncidentCompletedID = 3 if d["Priority"] in typemap: ac.IncidentTypeID = typemap[d["Priority"]] ac.DispatchAddress = d["Address"] ac.DispatchTown = d["City"] ac.DispatchCounty = d["State"] ac.DispatchPostcode = d["Zip Code"] ac.DispatchedACO = d["ACO Assigned"] comments = "Case Number: %s" % d["Case Number"] comments += "\nSubject: %s" % d["Subject of Call"]
print "DELETE FROM dbfs WHERE ID >= %d;" % START_ID # Create a transfer owner to = asm.Owner() owners.append(to) to.OwnerSurname = "Other Shelter" to.OwnerName = to.OwnerSurname # And an unknown owner uo = asm.Owner() owners.append(uo) uo.OwnerSurname = "Unknown Owner" uo.OwnerName = uo.OwnerSurname # Load up data files asm.stderr("Load data files") canimaldispo = asm.csv_to_list("%s/sysAnimalDispositionChoices.csv" % PATH) canimalrectypes = asm.csv_to_list("%s/sysAnimalReceivedTypes.csv" % PATH) canimalstatuses = asm.csv_to_list("%s/sysAnimalStatusChoices.csv" % PATH) cbreeds = asm.csv_to_list("%s/sysBreeds.csv" % PATH) ccolors = asm.csv_to_list("%s/sysCoatColors.csv" % PATH) cgenders = asm.csv_to_list("%s/sysGenderChoices.csv" % PATH) cpens = asm.csv_to_list("%s/sysPens.csv" % PATH) cshelterareas = asm.csv_to_list("%s/sysShelterAreas.csv" % PATH) cspecies = asm.csv_to_list("%s/sysSpecies.csv" % PATH) cvacctype = asm.csv_to_list("%s/sysVaccinations.csv" % PATH) cadoptions = asm.csv_to_list("%s/tblAdoptions.csv" % PATH) canimalguardians = asm.csv_to_list("%s/tblAnimalGuardians.csv" % PATH) canimals = asm.csv_to_list("%s/tblAnimals.csv" % PATH) canimalids = asm.csv_to_list("%s/tblAnimalIDs.csv" % PATH) canimalimages = []
a.NonShelterAnimal = 0 movements.append(m) # At least one customer has used holds to store adoptions instead of dispositions # They also entered them multiple times. if HOLDS_AS_ADOPTIONS: holdadopt = {} for row in db.query("select * from hold").list(): a = None if str(row.AnimalUid) in ppa: a = ppa[str(row.AnimalUid)] o = None if str(row.CustUid) in ppo: o = ppo[str(row.CustUid)] if a is None or o is None: asm.stderr("No animal/person combo: %s, %s" % (row.AnimalUid, row.CustUid)) continue # Do we already have this animal/person combo? k = "a=%so=%s" % (a.ID, o.ID) if not k in holdadopt: holdadopt[k] = "x" m = asm.Movement() m.AnimalID = a.ID m.OwnerID = o.ID m.MovementType = 1 m.MovementDate = row.Startts a.Archived = 1 a.ActiveMovementID = m.ID a.ActiveMovementDate = m.MovementDate a.ActiveMovementType = 1 a.NonShelterAnimal = 0
uo = asm.Owner() owners.append(uo) uo.OwnerSurname = "Unknown Owner" uo.OwnerName = uo.OwnerSurname # Call the API to get the pet list r = asm.post_data( "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"])
m.MovementDate = releasedate or intakedate a.Archived = 1 a.ActiveMovementID = m.ID a.ActiveMovementType = 5 a.LastChangedDate = m.MovementDate movements.append(m) # Process licence files LICENCE_FILES = [ "20082009", "20102011", "20122013", "20142015", "2016", "2018", "2019" ] for s in LICENCE_FILES: fname = PATH + s + ".csv" fdate = asm.getdate_yyyymmdd("%s/01/01" % s[:4]) asm.stderr("%s / %s" % (fname, fdate)) for d in asm.csv_to_list(fname): process_licence(d, fdate) # Process impound files IMPOUND_FILES = ["impound2017", "impound2018", "impound2019"] for s in IMPOUND_FILES: fname = PATH + s + ".csv" fdate = asm.getdate_yyyymmdd("%s/01/01" % s[7:]) asm.stderr("%s / %s" % (fname, fdate)) for d in asm.csv_to_list(fname): process_impound(d, fdate) # Now that everything else is done, output stored records for a in animals: print a