def add_allegations(self, search=""): if self.selections: print "\nYou have selected the following allegations so far:\n" for selection in self.selections: print str(selection).ljust(3), "|", self.allegations[selection] print "\nIf you're done selecting allegations, type \"done\"." if not search: prompt = "Enter a keyword to find the allegation." search = get_string(prompt).lower().strip() else: print "Searching for %s" % search if search == "done": return # breaks from recursive function possible_selections = [] for i, (fn, al) in enumerate(zip(self.file_names, self.allegations)): with open(fn) as f: content = f.read() if search in al.lower() or search in content.lower(): print str(i).ljust(3), "|", al possible_selections.append(i) if possible_selections: prompt = "Select a number or enter another search term." select = get_string(prompt) else: print "Not found!" select = "" self.add_allegations() try: select = int(select) except ValueError: search = select.lower() self.add_allegations(search=search) if select in possible_selections: self.selections.append(select) self.add_allegations()
def get_merge_data(self): # This is the data we have already, no need to recollect it self.merge_dict = { "CaseNumber" : str(self.cdm.case_list[0]), "Complainant" : self.cdm.case_list[9], "Respondent" : self.cdm.case_list[1], "Date" : datetime.datetime.today().strftime('%m-%d-%Y') } # Here is the data we do need to collect self.merge_dict["DateCaseOpened"] = get_string( "What was the date the case was opened?" ) self.merge_dict["RelatedCaseNumbers"] = get_string( "If applicable, add a comma-separated list of related case numbers." ) # We can operate logic on whether PSTUs should have been completed opened = dateparser.parse(self.merge_dict["DateCaseOpened"]) today = datetime.datetime.today() num_days = today - opened num_days = num_days.days # gives us just the number of days as an int # Now this won't fire if case has been opened for less than 90 days # If it has been open for more than 90, will confirm each required PSTU for x in range(90, num_days, 30): if get_bool("Enter true/yes/1 to confirm a %s-day PSTU." % x): self.merge_dict["%sDayPSTU" % x] = self.merge_dict["Date"] else: self.merge_dict["%sDayPSTU" % x] = None
def generate_initial_checklist(self): wait = get_string( # this doesn't do anything; just a reminder "Press enter to confirm allegations are entered in Versa.") # This is where we actually generate our checklist self.file_name = "checklists/2018 Case Opening Checklist.docx" merge_dict = { # These are the ones we know "Respondent" : self.cdm.case_list[1], "CaseNumber" : str(self.cdm.case_list[0]), } # Then we collect other data from the user merge_dict["DateReceived"] = get_string( "What was the date of receipt for the complaint? ") merge_dict["DateAssigned"] = get_string( "What was the date case was assigned to investigator?") date = datetime.datetime.today().strftime('%m-%d-%Y') initials = get_string("What are your initials? ") merge_dict["InitialsAndDate"] = "%s %s" % (initials, date) # We've got our data, let's generate the document script_dir = os.path.dirname("main.py") absolute_path = os.path.join(script_dir, self.file_name) document = mailmerge.MailMerge(absolute_path) document.merge(**merge_dict) output_path = os.path.join( script_dir, "%s Initial Checklist.docx" % self.cdm.case_list[0]) document.write(output_path) # Open the new document to remind to index subprocess.Popen([output_path], shell=True)
def get_ownership_info(self): print "Owner:", self.cdm.case_list[ -9] # complainant name to search for zip = self.cdm.case_list[-2] # gets complainant zip code search = SearchEngine() data = search.by_zipcode(zip) # Get comp county; if not in Florida (or our list, ask for it manually) if data.state != "FL": print "The complainant lives in %s, not Florida." % data.state zip = self.cdm.case_list[7] # try the respondent instead of comp data = search.by_zipcode(zip) if data.state != "FL": print "The respondent is not in FL, either." county = get_string("In what county is the unit located?") county = county.title().replace("County", "").strip() else: county = data.county.replace("County", "").strip() else: county = data.county.replace("County", "").strip() # Get the list of counties from the AppraiserSites table results = self.dbm.query("SELECT * FROM AppraiserSites") counties = [result[0] for result in results] if county not in counties: print "%s not found in the list of counties." % county county = get_string("In what county is the unit located?") county = county.title().replace("County", "").strip() sql = " SELECT Site From AppraiserSites WHERE County = '%s' " % county results = self.dbm.query(sql) appraiser_site = results.fetchone()[0] wb.open_new_tab(appraiser_site) self.owner = get_bool("Is complainant a unit owner?") self.owner = "unit owner" if self.owner is True else "not unit owner"
def __init__(self): self.review_results = { "review_date": datetime.datetime.today().strftime('%B %d, %Y'), "case_number": get_case_number(), "condo_name": get_string("What is the condominium name?") } self.rule_elements() self.step_through_statute() self.reserve_questions() self.notice_questions() self.generate_memo()
def generate_summary(self): # Combine respondent and project names for easier comparison both = self.cdm.case_list[1].lower() + self.cdm.case_list[2].lower() # Determine project type if "condo" in both: self.project_type = "8002 condo" elif "coop" in both or "co-op" in both or "cooperative" in both: self.project_type = "8004 cooperative" else: self.project_type = get_string("What is the project type?") print( "\n[complainant is %s, project is %s, %s units, fees %s," " corp status %s]") % (self.owner, self.project_type, self.num_of_units, self.fees_paid, self.corp_status)
def generate_closing_checklist(self): wait = get_string( # this doesn't do anything; just a reminder "Press enter to confirm allegation dispositions are entered " "in Versa." ) script_dir = os.path.dirname("main.py") absolute_path = os.path.join(script_dir, self.file_name) document = mailmerge.MailMerge(absolute_path) document.merge(**self.merge_dict) output_path = os.path.join( script_dir, "{} Closing Checklist.docx".format(self.cdm.case_list[0]) ) document.write(output_path) # Open the new document to remind to index subprocess.Popen([output_path], shell=True)
def __init__(self): # needed info for header // could attach to case_data_manager but meh self.review_results = { "review_date": datetime.datetime.today().strftime('%B %d, %Y'), "case_number": get_case_number(), "condo_name": get_string("What is the condominium name?") } # determine proper reporting level self.reporting_level = self.get_annual_revenue() self.review_results["correct_level"] = self.check_reporting_level() # branch off appropriately based on reporting level if "Report of Cash Receipts and Disbursements" in self.reporting_level: self.report_component_review() self.generate_memo("Report") else: self.statement_component_review() self.generate_memo("Statement")
def create_document(self): if not self.case_data: self.case_number = get_case_number() self.project_name = get_string("Enter the respondent or project.") # Creating our .docx file last = self.selections[len(self.selections) - 1] document = docx.Document() document.add_heading( "AEO: %s, %s" % (self.case_number, self.project_name), 0) doc_data = [] for num in self.selections: with open(self.file_names[num], "r") as f: lines = f.readlines() f.close() bolden = [ "Allegation", "Statute/Rule Reference", "Elements", "Evidence" ] p = document.add_paragraph("") p.add_run(lines[0]).bold = True for i in range(1, len(lines)): if any(bold in lines[i] for bold in bolden): p.add_run(lines[i].split(":")[0]).bold = True p.add_run(":") try: p.add_run(lines[i].split(":")[1]) except: print lines[i] else: p.add_run(lines[i]) if num is not last: p.add_run("\n\n_______________________________\n") doc_data.append(self.allegations[num].split(" ")[0]) doc_data = " ".join(doc_data) doc_name = " %s AEO %s.docx" % (doc_data, self.case_number) document.save(doc_name) # Open the new document to remind to index subprocess.Popen([doc_name], shell=True)
def update_case_data(self): # allows user the chance to update selected case data # called by __init__ if case number is exisiting in database column_names = self.dbm.get_column_names("CaseData") while True: print "\n 0. Nothing more to update!" self.print_case_data(column_names) prompt = "Please select a line to update (or 0 if you're done)." line = menu_choice(prompt, str(range(len(self.case_list) + 1))) if line is 0: break elif line is 1: print "You can't change the case number." else: prompt = "Replace data: %s" % self.case_list[line - 1] if type(self.case_list[line - 1]) is int: self.case_list[line - 1] = get_integer(prompt) else: self.case_list[line - 1] = get_string(prompt) self.dbm.amend_case_data(self.case_list, line - 1) self.dbm.query( "SELECT * FROM CaseData") # needed for col names
def get_merge_field_data(self): # Merge variable name: # Assigning these for clarity only self.case_number = self.cdm.case_list[0] # caseNumber self.respondent = self.cdm.case_list[1] # respondent self.project = self.cdm.case_list[2] # project self.resp_address = self.cdm.case_list[3] # respAddress1 self.resp_contact = self.cdm.case_list[4] # respAddress2 self.resp_csz = "%s, %s %s" % ( # respCityStateZip self.cdm.case_list[5], self.cdm.case_list[6], self.cdm.case_list[7] ) self.resp_email = self.cdm.case_list[8] # respEmail self.complainant = self.cdm.case_list[9] # complainant self.comp_salutation = '%s %s' % ( # compSalutation self.cdm.case_list[10], self.cdm.case_list[12] ) self.comp_address = self.cdm.case_list[13] # compAddress self.comp_csz = "%s, %s %s" % ( # compCityStateZip self.cdm.case_list[14], self.cdm.case_list[15], self.cdm.case_list[16] ) self.comp_email = self.cdm.case_list[17] # compEmail ####################################################################### # Important dates get their own sub-section def important_date_subquery(date_type): # Takes DB column name q = self.dbm.query_important_date(date_type, self.case_number) return q.fetchone()[0] def get_and_save_due_date(date_type): # Takes DB column name date = get_due_date(date_type.replace("DueDate", "")) self.dbm.amend_important_date(date_type, date, self.case_number) return date if "dueDateACKC" in self.merge_fields: # this is the merge variable name self.due_date_ackc = important_date_subquery("ACKCDueDate") if self.due_date_ackc is None: self.due_date_ackc = get_and_save_due_date("ACKCDueDate") else: self.due_date_ackc = None if "dueDateCCCLReqEv" in self.merge_fields: # this is the merge variable name self.due_date_cccl = important_date_subquery("CCCLReqEvDueDate") if self.due_date_cccl is None: self.due_date_cccl = get_and_save_due_date("CCCLReqEvDueDate") else: self.due_date_cccl = None if "dueDateAllegation" in self.merge_fields: # this is the merge variable name self.due_date_algl = important_date_subquery("ALGLDueDate") if self.due_date_algl is None: self.due_date_algl = get_and_save_due_date("ALGLDueDate") else: self.due_date_algl = None # this will grab WL/IL too if "dueDateWarning" in self.merge_fields: # this is the merge variable name self.due_date_wl = important_date_subquery("WLDueDate") if self.due_date_wl is None: self.due_date_wl = get_and_save_due_date("WLDueDate") else: self.due_date_wl = None if "dateOfCTC" in self.merge_fields: self.date_of_ctc = important_date_subquery("DateOfCTC") if self.date_of_ctc is None: self.date_of_ctc = get_string("What was the date of CTC?") self.dbm.amend_important_date( "DateOfCTC", self.date_of_ctc, self.case_number) else: self.date_of_ctc = None # Info for complainant letters if "compPhone" in self.merge_fields: prompt = "What phone number did you try to reach complainant at?" self.comp_phone = get_string(prompt) else: self.comp_phone = None if "call1date" and "call2date" in self.merge_fields: self.first_call = get_string("What date was your first call?") self.second_call = get_string("What date was your second call?") else: self.first_call, self.second_call = None, None # Info for respondent letters if "respSalutation" in self.merge_fields: self.resp_salutation = get_respondent_salutation(self.resp_contact) else: self.resp_salutation = None if "certMailNumber" in self.merge_fields: self.cert_mail_number = get_certified_mail_number() else: self.cert_mail_number = None if "ILCallDate" in self.merge_fields: self.il_call_date = get_string("What was the IL call date?") else: self.il_call_date = None # Dates of letters referenced in other letters if "dateOfCCCL" in self.merge_fields: self.cccl_date = get_string("What was the date of CCCL?") else: self.cccl_date = None if "dateOfACKC" in self.merge_fields: self.ackc_date = get_string("What was the date of ACKC?") else: self.ackc_date = None if "dateOfWL" in self.merge_fields: self.wl_date = get_string("What was the date of WL?") else: self.wl_date = None # Self-filling allegations/evidence get their own sub-sections self.allegations = None self.evidence = None
def get_merge_fields(self): self.merge_dict = {} # to hold our merge data we will collect # Different consent orders for different respondent types self.respondent_type = menu_choice( ("Select the respondent type:\n" "1. Association\n" "2. Developer\n"), "12" # acceptable responses ) # Make a list with all the documents we're creating root_folder = "admin_action_templates/" self.file_names = [ root_folder + "COOL_Template.docx", root_folder + "CPW_Template.docx", root_folder + "InvestigativeReport_Template.docx" ] # Add either the association or developer CO per the above if self.respondent_type is 1: self.file_names.append(root_folder + "ConsentOrderAssociation_Template.docx") self.respondent_type = "Association" elif self.respondent_type is 2: self.file_names.append( root_folder + "ConsentOrderDeveloper_Template.docx", ) self.respondent_type = "Developer" # Now collect the merge field, fill information we already have, # and collect the info we don't already have for file_name in self.file_names: # First get the merge fields that are in the current document with mailmerge.MailMerge(file_name) as document: self.merge_fields = sorted(list(document.get_merge_fields())) # Then get the data for those fields for mf in self.merge_fields: # skip if we already have the data if mf in self.merge_dict: continue elif mf == "CondoCity" or mf == "CountyOfCondo": zip = get_integer("What is the condo's zip code?") search = SearchEngine() data = search.by_zipcode(zip) try: self.merge_dict["CondoCity"] = data.city self.merge_dict["CountyOfCondo"] = ( data.county.replace(" County", "")) print "City:", data.city, "|", "County:", data.county except AttributeError: self.merge_dict["CondoCity"] = get_string( "What is the CondoCity?") self.merge_dict["CountyOfCondo"] = get_string( "What is the CountyOfCondo?") elif mf == "Respondent": self.merge_dict[mf] = self.cdm.case_list[1] elif mf == "Project": self.merge_dict[mf] = self.cdm.case_list[2] elif mf == "RespondentAddress": self.merge_dict[mf] = self.cdm.case_list[3] elif mf == "RespondentAddress2": self.merge_dict[mf] = self.cdm.case_list[4] elif mf == "RespondentCityStateZip": self.merge_dict[mf] = "%s, %s %s" % ( # respCityStateZip self.cdm.case_list[5], self.cdm.case_list[6], self.cdm.case_list[7]) elif mf == "RespondentEmail": self.merge_dict[mf] = self.cdm.case_list[8] elif mf == "RespondentSalutation": self.merge_dict[mf] = get_respondent_salutation( self.cdm.case_list[4]) elif mf == "Association": # if respondent is association, we have that data if self.respondent_type == "Association": self.merge_dict[mf] = self.cdm.case_list[1] # if respondent is developer, we need to clarify assoc name elif self.respondent_type == "Developer": self.merge_dict[mf] = get_string( "What is the {}? ".format(mf)) elif mf == "CaseNumber": self.merge_dict[mf] = str(self.cdm.case_list[0]) elif mf == "Condominium": self.merge_dict[mf] = self.cdm.case_list[2] elif mf == "CertMailNumberForCOOL": self.merge_dict[mf] = get_certified_mail_number() elif mf == "DateOfInvestigativeReport": self.merge_dict[mf] = ( datetime.datetime.today().strftime('%B %d, %Y')) elif mf == "NameOfComplainant": self.merge_dict[mf] = (self.cdm.case_list[9]) elif mf == "RegisteredAgentCityStateZip": self.merge_dict[mf] = zip_find("registered agent") else: self.merge_dict[mf] = get_string( "What is the {}? ".format(mf))
def get_remaining_case_data(self): # START HELPER FUNCTIONS # # THESE FUNCTIONS CHECK FOR MATCHING EXISITING DATA FROM OTHER ROWS def check_for_respondent(): sql = '''SELECT %s FROM CaseData WHERE Respondent = "%s" LIMIT 1''' % ( "Respondent, Project, RespAddress, RespContact, RespCity, " "RespState, RespZip, RespEmail", self.resp_name) resp = self.dbm.query(sql) self.resp_list = [] for row in resp: for item in row: self.resp_list.append(item) def check_for_complainant(): sql = '''SELECT %s FROM CaseData WHERE CompName = "%s" LIMIT 1''' % ( "CompName, CompTitle, CompFirst, CompLast, CompAddress, " "CompCity, CompState, CompZip, CompEmail", self.comp_name) comp = self.dbm.query(sql) self.comp_list = [] for row in comp: for item in row: self.comp_list.append(item) # END HELPER FUNCTIONS # ### START get_remaining_case_data ### # # # Respondent and project info # # # self.resp_name = get_string("Enter respondent name.") # See if we can find the respondent in any other case in our database check_for_respondent() if len(self.resp_list) is 8: print "\nFound respondent in database! Assigning data..." for item in self.resp_list: self.case_list.append(item) else: self.case_list.append(self.resp_name) self.case_list.append(get_string("Enter project name.")) self.case_list.append(get_string("Enter respondent address.")) rc = get_string("Enter respondent contact with title.") self.case_list.append(rc) zip = zip_find("respondent").replace(",", "").rsplit(" ", 2) for z in zip: print z self.case_list.append(z) # city / state abbr / zip self.case_list.append(get_string("Enter respondent email.")) # # # Complainant info # # # self.comp_name = get_string("Enter complainant name with title.") # See if we can find complainant in any other case in our database check_for_complainant() if len(self.comp_list) is 9: print "\nFound complainant in database! Assigning data..." for item in self.comp_list: self.case_list.append(item) else: self.case_list.append(self.comp_name) human_name = HumanName(self.comp_name) self.case_list.append(human_name['title']) self.case_list.append(human_name['first']) self.case_list.append(human_name['last']) self.case_list.append(get_string("Enter complainant address.")) zip = zip_find("complainant").replace(",", "").rsplit(" ", 2) for z in zip: print z self.case_list.append(z) # city / state abbr / zip self.case_list.append(get_string("Enter complainant email.")) # Now save our data into our database! try: self.dbm.insert_new_case_data(self.case_list) self.dbm.query("SELECT * FROM CaseData") # needed for next line self.update_case_data() except sqlite3.IntegrityError as e: # this shouldn't actually be invoked, but just in case... print e, " ... case already exists!"