Example #1
0
    def generate_memo(self, memo_type):
        self.make_bools_into_strings()  # for printing bools into docx

        # file stuff
        if memo_type == "Report":
            template_name = (
                "document_review_templates/FinancialReportReview_Template.docx"
            )
        elif memo_type == "Statement":
            template_name = (
                "document_review_templates/FinancialStatementReview_template.docx"
            )
        script_dir = os.path.dirname("main.py")
        absolute_path = os.path.join(script_dir, template_name)

        # create the document itself now
        document = mailmerge.MailMerge(absolute_path)
        document.merge(**self.review_results)

        # output our merged document
        output_name = "%s %s Financial %s Review Notes.docx" % (
            self.review_results["case_number"],
            self.review_results["condo_name"], memo_type)
        output_path = os.path.join(script_dir, output_name)
        document.write(output_path)
        print "\nYour Financial %s Review Memo has been generated!" % memo_type
Example #2
0
def main():

    # set up "form.docx" for reading
    template = str(os.getcwd()) + '\\' + "form.docx"

    # set up "input.xlsx" for reading
    input_file = str(os.getcwd()) + '\\' + "input.xlsx"
    wb = openpyxl.load_workbook(filename=input_file)
    ws = wb.active
    
    # setup output folder
    current_dir = os.getcwd()
    output_path = current_dir + '\\' + "output"
    os.mkdir(output_path)

    # get data and write documents
    for row in ws.iter_rows(min_row=3, max_row=ws.max_row, min_col=2, max_col=ws.max_column):

        # read data
        name = str(row[0].value)
        date = str(row[1].value)
        asset = str(row[2].value)
        serial_num = str(row[3].value)
        hardware_list = str(row[4].value)

        # name format of created documents
        save_string = "hardware_" + name + ".docx"

        # create and save documents
        document = mailmerge.MailMerge(template)
        document.merge(NAME=name, DATE=date[:-8], ASSET=asset, SERIAL_NUM=serial_num, LIST=hardware_list)
        document.write("output" + '\\' + save_string)
Example #3
0
    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 create_document(doctype, lastname, rowname, rows=[], **kwargs):
    msword_template = get_msword_template_path(doctype)
    document = mailmerge.MailMerge(msword_template)
    eazy_merge(document, rowname, rows, **kwargs)
    temproot = os.path.join(settings.MEDIA_ROOT, 'tempfiles')
    outfile = get_temporary_path(lastname, doctype, root=temproot)
    print('outfile', outfile)
    document.write(outfile)
    document.close()
    time.sleep(1)
    return (outfile)
Example #5
0
 def generate_order(self):
     for file_name in self.file_names:
         script_dir = os.path.dirname("main.py")
         absolute_path = os.path.join(script_dir, file_name)
         document = mailmerge.MailMerge(absolute_path)
         document.merge(**self.merge_dict)
         output_name = file_name.replace("admin_action_templates/",
                                         "").replace("_Template", "")
         output_path = os.path.join(
             script_dir, "{} {}".format(self.cdm.case_list[0], output_name))
         document.write(output_path)
         print "\nYour {} has been generated!".format(output_name)
Example #6
0
 def sophisticated(self, transaction, xxtemplate, outfile):
     msword_template = self.get_msword_template_path('invoice')
     document = mailmerge.MailMerge(msword_template)
     stmt = StatementCreator(transaction)
     self.eazy_merge(document, 'invoice', stmt.get_payments(),
                     **stmt.get_fields())
     temproot = os.path.join(settings.MEDIA_ROOT, 'tempfiles')
     outfile = self.get_temporary_path(transaction.person,
                                       'statement',
                                       root=temproot)
     print('outfile', outfile)
     document.write(outfile)
     document.close()
     time.sleep(1)
Example #7
0
    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 generate_memo(self):
        self.make_bools_into_strings()  # for printing bools into docx

        # file stuff
        template_name = (
            "document_review_templates/BudgetReview_Template.docx")
        script_dir = os.path.dirname("main.py")
        absolute_path = os.path.join(script_dir, template_name)

        # create the document itself now
        document = mailmerge.MailMerge(absolute_path)
        document.merge(**self.review_results)

        # output our merged document
        output_name = "%s %s Budget Review Notes.docx" % (
            self.review_results["case_number"],
            self.review_results["condo_name"])
        output_path = os.path.join(script_dir, output_name)
        document.write(output_path)
        print "\nYour Budget Review Memo has been generated!"
Example #9
0
 def brute_force(self):
     document = mailmerge.MailMerge(INPUTPATH)
     document.merge(**get_fields())
     document.merge_rows('invoice', get_rows())
     document.write(OUTPUTPATH)
     document.close()
Example #10
0
"""
e = open('edge.pkl', 'rb')
edge_case = pickle.load(e)

d = open('deny.pkl', 'rb')
deny = pickle.load(d)

 EXAMPLE OF DICTIONARY BEING PASSED THROUGH TO EACH PAGE
pws_1 = {
    'pws_id': 'TX000000',
    'pws_name': 'WSC',
}
"""


def unpack_pws(dct):
    lst = []
    for item in dct:
        val = dct[item]
        lst.append({'Short_PWS': val[0], 'PWSNAME': val[1]})
    return lst


# Define the templates - assumes they are in the same directory as the code
template = "test.docx"
document = mailmerge.MailMerge(template)
document.merge_pages(unpack_pws(approved))
document.write('EXAMPLE.docx')


Example #11
0
            'pws_id': pws_id,
            'pws_name': pws_name,
            'samp_id': []
        })
        samples = val[3]
        amt_sample = len(samples)
        for i in range(amt_sample):
            sample = samples[i]
            sample_id = sample[0]
            activity = sample[1]
            loc = sample[2]
            # UPDATE BY NAME IS SAMPLE[3]
            create_date = sample[5]
            lst[c]['samp_id'].append({
                'samp_id': sample_id,
                'activity': activity,
                'loc': loc,
                'create_date': create_date
            })
        c += 1
    return lst


# Define the templates - assumes they are in the same directory as the code
template = "table_merge_test.docx"
with mailmerge.MailMerge(template) as document:
    document.merge_pages(table_merge(edge_case))
    document.write('EXAMPLE_tables.docx')

# print(table_merge(edge_case))
Example #12
0
    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))
Example #13
0
def sample_sites_word_merge():
    dsn_tns = cx_Oracle.makedsn('link', 'port#', service_name='other_link')
    conn = cx_Oracle.connect('Username',
                             'password',
                             dsn_tns,
                             encoding='UTF-8',
                             nencoding='UTF-8')
    c = conn.cursor()
    ask = input("ENTER PWS ID: ")
    if len(ask) == 7:
        ask = "TX" + str(ask)
    else:
        while ask[:2] != 'TX':
            ask = input("ENTER FULL PWS ID: ")
    c.execute("SELECT TINWSYS_IS_NUMBER, NAME "
              "FROM SDWIS2TX.TINWSYS "
              "WHERE NUMBER0 = '{}'".format(ask))
    val = c.fetchall()
    tinwsys = val[0][0]
    name = val[0][1]
    c.execute(
        "SELECT TINWSF_IS_NUMBER "
        "FROM SDWIS2TX.TINWSF "
        "WHERE TINWSYS_IS_NUMBER = {} AND TYPE_CODE = 'DS'".format(tinwsys))
    tinwsf0is = c.fetchone()[0]
    c.execute(
        "SELECT IDENTIFICATION_CD, DESCRIPTION_TEXT, LD_CP_TIER_LEV_TXT, "
        "D_LAST_UPDT_TS, ACTIVITY_STATUS_CD "
        "FROM SDWIS2TX.TSASMPPT "
        "WHERE TINWSF0IS_NUMBER = '{}'".format(tinwsf0is))
    val = c.fetchall()
    sites = []
    for v in val:
        if v[0][:3] == 'LCR':
            YEAR = str(v[3].year)
            month = str(v[3].month)
            if len(month) == 1:
                month = "0" + month
            day = str(v[3].day)
            DATE = month + "/" + day + "/" + YEAR
            d = {
                'SAMPLE_ID': v[0][:6],
                'sample_loc': v[1],
                'activity': v[4],
                'tier': v[2],
                'last_update': DATE
            }
            sites.append(d)
    template = "sample_sites.docx"
    today = datetime.datetime.today()
    year = today.year
    month = str(today.month)
    if len(month) == 1:
        month = "0" + str(month)
    day = str(today.day)
    if len(day) == 1:
        day = "0" + str(month)
    code_today = str(year) + month + day
    document = mailmerge.MailMerge(template)
    document.merge(pws_id=ask,
                   pws_name=name,
                   short_id=ask[2:],
                   yearmonthday=code_today,
                   SAMPLE_ID=sites)
    path = r'C:\Users\username\Desktop' + "\\" + "sample_sites_" + ask + ".docx"
    document.write(path)
    c.close()
    conn.close()