def findowner(name): """ Looks for an owner with name given in the collection of owners. If one isn't found, adds a new owner to the collection with the name given (which is assumed to be "surname forenames") and returns that. This means we try our best to reuse and update owner records with the same name. """ # Remove the word "Foster " or "Foster/" from the name - it appeared # in earlier files name = name.replace("Foster ", "") name = name.replace("Foster/", "") # If there's a slash in the name, only take the first portion, # otherwise it will look stupid if name.find("/") != -1: name = name[0:name.find("/")] # Remove any whitespace name = name.strip() for o in owners: if o.OwnerName.find(name) != -1: return o o = asm.Owner() o.OwnerName = name o.OwnerSurname = name[0:name.find(" ")] o.OwnerForeNames = name[name.find(" ") + 1:] owners.append(o) return o
def process_licence(d, dt): if d["Owner"] in ppo: o = ppo[d["Owner"]] else: o = asm.Owner() owners.append(o) name = d["Owner"] firstname = "" lastname = name if name.find(",") != -1: firstname, lastname = name.split(",", 1) ppo[name] = o o.OwnerForeNames = firstname o.OwnerSurname = lastname o.OwnerName = name o.OwnerAddress = d["Address"] o.OwnerTown = "Burnsville" o.OwnerCounty = "MN" o.HomeTelephone = d["Phone"] ol = asm.OwnerLicence() ol.LicenceType = 1 ol.OwnerID = o.ID ol.LicenceNumber = "%s/%s" % (ol.ID, d["Lic. #"]) ol.IssueDate = dt ol.ExpiryDate = asm.add_days(dt, 365) ol.Comments = "Name: %s\nSex: %s\nBreed: %s\nColor: %s" % ( d["Pet Name"], d["Sex"], d["Breed"], d["Color"]) ownerlicences.append(ol)
def findownerbyname(name=""): """ Looks for an owner with the given name, returns a new one, added to the set if it wasn't found """ for o in owners: if o.OwnerName == name: return o o = asm.Owner() o.OwnerName = name sp = name.rfind(" ") o.Surname = name[sp + 1:] o.ForeNames = name[0:sp] owners.append(o) return o
def getcreateowner(first, last, address, city, state, postal): global owners global ppo k = first + last + address if ppo.has_key(k): return ppo[k] else: o = asm.Owner() owners.append(o) ppo[k] = o o.OwnerForeNames = first o.OwnerSurname = last o.OwnerName = first + " " + last o.OwnerAddress = address o.OwnerTown = city o.OwnerCounty = state o.OwnerPostcode = postal return o
def get_owner(s): """ Returns an owner object for the fields in supplied in s. s is asterisk separated with the first one or two items usually being the address and anything remaining being phone numbers """ gotemail = False gotaddress = False gotphone = False gotcell = False o = None for i, c in enumerate(s.split("*")): x = c.strip() if i == 0: # first portion is always name # Do we already have an owner with this name? If so, just return it and save time if x in ppo: return ppo[x] # Otherwise, create the owner and set the name o = asm.Owner() owners.append(o) o.SplitName(x) ppo[x] = o # Is this an address? elif not gotaddress and (x.find(" 94") != -1 or x.find(" 96") != -1): gotaddress = True o.OwnerAddress, o.OwnerTown, o.OwnerCounty, o.OwnerPostcode = extract_address( x) # An email? elif not gotemail and x.find("@") != -1: gotemail = True o.EmailAddress = x # Must be a phone elif not gotphone: gotphone = True o.HomeTelephone = x elif not gotcell: gotcell = True o.MobileTelephone = x return o
def process_subjects(reportuid, ac): """ Handle people linked to an ac record VIC = victim, WIT = witness, OWN / SUS = suspect, ACO """ for row in db.query("select * from ac_subject where reportuid = %s" % reportuid): ck = "sub%s" % row.subjectuid if ck in ppo: o = ppo[ck] else: o = asm.Owner() owners.append(o) ppo[ck] = o o.OwnerForeNames = row.subjFirstName o.OwnerSurname = row.subjLastName if o.OwnerSurname is None or o.OwnerSurname == "": o.OwnerSurname = "Unknown" o.OwnerAddress = row.subjaddr1 + " " + row.subjaddr2 o.OwnerTown = row.subjcity o.OwnerCounty = row.subjstate o.OwnerPostcode = row.subjzipcode o.HomeTelephone = row.subjphone1 o.WorkTelephone = row.subjphone2 o.MobileTelephone = row.subjphone3 o.Comments = asm.strip("%s %s %s" % (row.physdescr, row.notes, row.statement)) st = str(row.subject_type) if st.find("VIC") != -1: ac.VictimID = o.ID if st.find("WIT") != -1 or st.find("ACO") != -1: ac.CallerID = o.ID if st.find("OWN") != -1 or st.find("SUS") != -1: if ac.OwnerID == 0: ac.OwnerID = o.ID elif ac.Owner2ID == 0: ac.Owner2ID = o.ID elif ac.Owner3ID == 0: ac.Owner3ID = o.ID
asm.setid("adoption", START_ID) asm.setid("animal", START_ID) asm.setid("owner", START_ID) asm.setid("animalvaccination", START_ID) asm.setid("internallocation", 2) # Remove existing print "\\set ON_ERROR_STOP\nBEGIN;" print "DELETE FROM internallocation WHERE ID >= 2;" print "DELETE FROM adoption WHERE ID >= %d AND CreatedBy = 'conversion';" % START_ID print "DELETE FROM animal WHERE ID >= %d AND CreatedBy = 'conversion';" % START_ID print "DELETE FROM owner WHERE ID >= %d AND CreatedBy = 'conversion';" % START_ID print "DELETE FROM animalvaccination WHERE ID >= %d AND CreatedBy = 'conversion';" % START_ID # Create a transfer owner to = asm.Owner() owners.append(to) to.OwnerSurname = "Other Shelter" to.OwnerName = to.OwnerSurname # Create an unknown owner uo = asm.Owner() owners.append(uo) uo.OwnerSurname = "Unknown Owner" uo.OwnerName = uo.OwnerSurname # Load up data files cadopt = asm.csv_to_list("%s/adoption_list.csv" % PATH, uppercasekeys=True) cdisp = asm.csv_to_list("%s/disposition.csv" % PATH, uppercasekeys=True) cmed = asm.csv_to_list("%s/medication_usage.csv" % PATH, uppercasekeys=True,
logs = [] nextanimalid = 100 nextanimalvaccinationid = 100 nextlogid = 100 nextownerid = 100 nextownerdonationid = 100 nextmovementid = 100 startanimalid = 100 startanimalvaccinationid = 100 startownerdonationid = 100 startownerid = 100 startlogid = 100 startmovementid = 100 o = asm.Owner(nextownerid) owners.append(o) nextownerid += 1 o.OwnerSurname = "Unknown" o.OwnerName = o.OwnerSurname GUEST_PIN_ID = 0 GUEST_PIN_INTAKE_DATE = 1 GUEST_SHELTER_GUEST_NAME = 2 GUEST_DOG = 3 GUEST_MALE = 4 GUEST_BREED = 5 GUEST_AGE = 6 GUEST_COLOR = 7 GUEST_MICROCHIP__ = 8 GUEST_SOURCE = 9
def getdate(s): if DATE_FORMAT == "DMY": return asm.getdate_ddmmyyyy(s) else: return asm.getdate_mmddyyyy(s) def size_id_for_name(name): return { "": 3, "LARGE": 1, "SMALL": 2, "MEDIUM": 3, "X-LARGE": 0 }[name.upper().strip()] uo = asm.Owner() owners.append(uo) uo.OwnerSurname = "Unknown Owner" uo.OwnerName = "Unknown Owner" uo.Comments = "Catchall for adopted animal data from ShelterLuv" ur = asm.Owner() owners.append(ur) ur.OwnerSurname = "Unknown Rescue" ur.OwnerName = "Unknown Rescue" ur.OwnerType = 2 ur.Comments = "Catchall for transferred animal data from ShelterLuv" print("\\set ON_ERROR_STOP\nBEGIN;") print("DELETE FROM adoption WHERE ID >= %s;" % START_ID) print("DELETE FROM animal WHERE ID >= %s;" % START_ID)
print "\\set ON_ERROR_STOP\nBEGIN;" reader = csv.reader(open("caaws_volunteers.csv"), dialect="excel") irow = 0 nextid = 15 for row in reader: # Skip first row of header irow += 1 if irow < 2: continue # Enough data for row? if len(row) < 2: break if row[0].strip() == "" and row[1].strip() == "" and row[2].strip() == "": continue o = asm.Owner(nextid) nextid += 1 o.OwnerSurname = row[LAST_NAME] o.OwnerForeNames = row[FIRST_NAME] o.OwnerInitials = row[FIRST_NAME][0:1].upper() o.OwnerName = row[FIRST_NAME] + " " + row[LAST_NAME] o.OwnerAddress = row[ADDRESS] city, state, zipcode = city_state_zip(row[CITYSTZIP]) o.OwnerTown = city o.OwnerCounty = state o.OwnerPostcode = zipcode o.HomeTelephone = row[HOME_NUMBER] o.MobileTelephone = row[CELL_NUMBER] o.EmailAddress = row[EMAIL] o.IsVolunteer = 1
animalmap = {} nextanimalid = 100 nextanimalcontrolid = 100 nextownerid = 100 nextownerdonationid = 100 nextmovementid = 100 startanimalid = 100 startanimalcontrolid = 100 startownerdonationid = 100 startownerid = 100 startmovementid = 100 asm.setid("donationtype", 100) unknown = asm.Owner(nextownerid) owners.append(unknown) nextownerid += 1 unknown.OwnerSurname = "Unknown" unknown.OwnerName = unknown.OwnerSurname for row in asm.csv_to_list(PATH + "list1.csv", strip=True): o = asm.Owner(nextownerid) owners.append(o) nextownerid += 1 o.ExtraID = row["MasterID"] o.OwnerTitle = row["TITLE"] o.OwnerForeNames = row["FIRSTNAME"] o.OwnerSurname = row["LASTNAME"] if o.OwnerSurname == "": o.OwnerSurname = "(blank)" o.OwnerName = o.OwnerForeNames + " " + o.OwnerSurname
def process_impound(d, dt): a = asm.Animal() animals.append(a) a.EntryReasonID = 7 # Stray if d["Species"].lower() == "cat": a.AnimalTypeID = 12 # Stray Cat elif d["Species"].lower() == "dog": a.AnimalTypeID = 10 # Stray Dog else: a.AnimalTypeID = 40 # Misc a.SpeciesID = asm.species_id_for_name(d["Species"]) a.AnimalName = d["Animal's Name"].replace("\n", " ") if a.AnimalName == "?" or a.AnimalName.strip() == "": a.AnimalName = "(unknown)" releasedate = getdate(d["Date of Release"]) intakedate = getdate(d["Date of P/U"]) if intakedate is None and releasedate is not None: intakedate = releasedate if intakedate is None: intakedate = dt a.DateBroughtIn = intakedate a.DateOfBirth = asm.subtract_days(a.DateBroughtIn, 365) a.CreatedDate = a.DateBroughtIn a.LastChangedDate = a.DateBroughtIn a.generateCode() a.Sex = asm.getsex_mf(d["Sex-Altered?"]) a.Size = 2 a.Neutered = asm.iif( d["Sex-Altered?"].lower() == "mn" or d["Sex-Altered?"].lower() == "fs", 1, 0) a.IdentichipNumber = d["Microchip"] if a.IdentichipNumber != "no chip found" and a.IdentichipNumber != "Unable to scan" and a.IdentichipNumber != "no" and a.IdentichipNumber != "": a.Identichipped = 1 asm.breed_ids(a, d["Breed"], default=442) if d["Breed"].lower().find("mix") != -1 or d["Breed"].find("X") != -1: a.CrossBreed = 1 a.Breed2ID = 442 a.HiddenDetails = "Breed: %s\nColor: %s\nCollar: %s\nTags: %s\nMicrochip: %s\n" % ( d["Breed"], d["Color"], d["Collar"], d["Tags"], d["Microchip"]) a.Comments = d["Comments"] # Now create the owner if d["Owner's Name"] != "n/a" and d["Owner's Name"] != "" and d[ "Owner's Name"] != "?" and d[ "Owner's Name"] != "Went to Rescue" and d[ "Owner's Name"] != "unknown" and d["Address"] != "" and d[ "Address"] != "n/a": o = asm.Owner() owners.append(o) name = d["Owner's Name"] lastname = name firstname = "" if name.find(" ") != -1: firstname, lastname = name.split(" ", 1) ppo[name] = o o.OwnerForeNames = firstname o.OwnerSurname = lastname o.OwnerName = "%s, %s" % (lastname, firstname) o.OwnerAddress = d["Address"] o.OwnerTown = "Burnsville" o.OwnerCounty = "MN" o.HomeTelephone = d["Phone #"] # Reclaim if there's a date if releasedate is not None: m = asm.Movement() m.AnimalID = a.ID m.OwnerID = o.ID m.MovementType = 5 m.MovementDate = releasedate a.Archived = 1 a.ActiveMovementID = m.ID a.ActiveMovementType = 5 a.LastChangedDate = m.MovementDate movements.append(m) # Was the animal euthanised? if "Euthanized" in d and d["Euthanized"] == "1": a.DeceasedDate = releasedate or intakedate a.PutToSleep = 1 a.PTSReasonID = 4 a.PTSReason = d["If Euthanized, Why?"] a.Archived = 1 # Is this animal still on shelter? If so, we need to get it off with a fake reclaim if a.Archived == 0: m = asm.Movement() m.AnimalID = a.ID m.OwnerID = uo.ID m.MovementType = 5 m.MovementDate = releasedate or intakedate a.Archived = 1 a.ActiveMovementID = m.ID a.ActiveMovementType = 5 a.LastChangedDate = m.MovementDate movements.append(m)
asm.setid("adoption", 1000) asm.setid("animal", 10000) asm.setid("animalcontrol", 1000) asm.setid("owner", 1000) asm.setid("ownerdonation", 1000) asm.setid("ownerlicence", 1000) animals = {} animalcontrol = [] movements = [] owners = {} ownerdonations = [] ownerlicences = [] unknowntransfer = asm.Owner() unknowntransfer.OwnerSurname = "Transfer Location" unknowntransfer.Comments = "Unknown transfer location, see movement comments" owners["0"] = unknowntransfer # Set up animal records first for ca in canimal: a = asm.Animal() a.Archived = 1 a.DateBroughtIn = datetime.datetime.today() - datetime.timedelta(days=365) animals[ca["animalID"]] = a if ca["animalType"] == "C": a.SpeciesID = 2 elif ca["animalType"] == "D": a.SpeciesID = 1 else:
asm.setid("ownerdonation", START_ID) asm.setid("vaccinationtype", 100) asm.setid("testtype", 100) print "DELETE FROM adoption WHERE ID >= %s;" % START_ID print "DELETE FROM animal WHERE ID >= %s;" % START_ID print "DELETE FROM animalmedical WHERE ID >= %s;" % START_ID print "DELETE FROM animalmedicaltreatment WHERE ID >= %s;" % START_ID print "DELETE FROM animaltest WHERE ID >= %s;" % START_ID print "DELETE FROM animalvaccination WHERE ID >= %s;" % START_ID print "DELETE FROM owner WHERE ID >= %s;" % START_ID print "DELETE FROM ownerdonation WHERE ID >= %s;" % START_ID print "DELETE FROM testtype WHERE ID >= 100;" print "DELETE FROM vaccinationtype WHERE ID >= 100;" to = asm.Owner() to.OwnerSurname = "Unknown Transfer Owner" owners.append(to) ro = asm.Owner() ro.OwnerSurname = "Unknown Reclaim Owner" owners.append(ro) fo = asm.Owner() fo.OwnerSurname = "Unknown Foster Owner" owners.append(fo) uo = asm.Owner() uo.OwnerSurname = "Unknown Adopter" owners.append(uo)
asm.setid("animalmedical", 100) asm.setid("animalmedicaltreatment", 100) asm.setid("animalvaccination", 100) asm.setid("owner", 100) asm.setid("ownerdonation", 100) print "DELETE FROM adoption WHERE ID >= 100;" print "DELETE FROM animal WHERE ID >= 100;" print "DELETE FROM animalmedical WHERE ID >= 100;" print "DELETE FROM animalmedicaltreatment WHERE ID >= 100;" print "DELETE FROM animalvaccination WHERE ID >= 100;" print "DELETE FROM owner WHERE ID >= 100;" print "DELETE FROM ownerdonation WHERE ID >= 100;" print "DELETE FROM vaccinationtype;" to = asm.Owner() to.OwnerSurname = "Unknown Transfer Owner" owners.append(to) ro = asm.Owner() ro.OwnerSurname = "Unknown Reclaim Owner" owners.append(ro) # people.csv for row in asm.csv_to_list(PATH + "people.csv"): o = asm.Owner() ppo[row["id"]] = o owners.append(o) o.OwnerForeNames = row["first name"] o.OwnerSurname = row["last name"] o.HomeTelephone = row["home phone"]
print("\\set ON_ERROR_STOP\nBEGIN;") print("DELETE FROM adoption WHERE ID >= %s;" % START_ID) print("DELETE FROM animal WHERE ID >= %s;" % START_ID) print("DELETE FROM animalmedical WHERE ID >= %s;" % START_ID) print("DELETE FROM animalmedicaltreatment WHERE ID >= %s;" % START_ID) print("DELETE FROM owner WHERE ID >= %s;" % START_ID) print("DELETE FROM media WHERE ID >= %s;" % START_ID) print("DELETE FROM dbfs WHERE ID >= %s;" % START_ID) for d in asm.csv_to_list("%s/people.csv" % PATH): if d["name"] == "name": continue # skip repeated header rows if d["id"] in ppo: continue # skip repeated rows # Each row contains a person o = asm.Owner() owners.append(o) ppo[d["id"]] = o ppon[d["name"]] = o o.SplitName(d["name"], False) o.OwnerAddress = d["address"] o.OwnerTown = d["city"] o.OwnerCounty = d["province"] o.OwnerPostcode = d["postal"] o.EmailAddress = d["email"] o.HomeTelephone = d["phone"] o.MobileTelephone = d["phone_cell"] if d["donator"] == "true": o.IsDonor = 1 o.Comments = "group: %s\n%s" % (d["group"], d["notes"]) o.LastChangedDate = getdate(d["updated_at"])
print("\\set ON_ERROR_STOP\nBEGIN;") print("DELETE FROM animal WHERE ID >= 100 AND CreatedBy LIKE '%conversion';") print("DELETE FROM owner WHERE ID >= 100 AND CreatedBy = 'conversion';") print("DELETE FROM adoption WHERE ID >= 100 AND CreatedBy = 'conversion';") pf = "" if PETFINDER_ID != "": asm.setid("media", 100) asm.setid("dbfs", 200) print("DELETE FROM media WHERE ID >= 100;") print("DELETE FROM dbfs WHERE ID >= 200;") pf = asm.petfinder_get_adoptable(PETFINDER_ID) data = asm.csv_to_list(PATH) uo = asm.Owner() uo.OwnerSurname = "Unknown Owner" uo.OwnerName = uo.OwnerSurname owners.append(uo) # petpal files are newest first order for d in reversed(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)"
# --- START OF CONVERSION --- owners = [] movements = [] animals = [] startanimalid = 100 startownerid = 100 startmovementid = 100 nextanimalid = 100 nextownerid = 100 nextmovementid = 100 oa = asm.Owner(nextownerid) nextownerid += 1 oa.OwnerSurname = "Catchall for animals leaving the shelter" oa.OwnerName = "Catchall for animals leaving the shelter" owners.append(oa) DATE_IN = 0 ADOPTED_MOVED = 1 IMPOUND_NO = 2 DATE_OUT = 3 BLANK = 4 DOG_NAME = 5 DESEXED = 6 ADOPTION_FEE_PAID = 7 AGE = 8 BREED = 9