示例#1
0
def main(args):
    """
    This is the main routine for the mrep.py program.

    First we process args from the command line with builtin argparse module.
    You can read about argparse in Hellmann's book Python Standard Library By Example

    The first argument passed to mrep.py is interpreted as the 'command'. The
    following commands are supported:

    - subs

    The second argument is a filename representing the Excel doc to process.

    Depending on the command passed, mrep.py will hand control to a function
    that will be responsible for instantiating an instance of a particular kind
    of report, processing the data, and writing out a 'processed' Excel document.
    """
    cmd_parser = argparse.ArgumentParser(description='Process monthly report files')
    #make instance of argument parser called process monthly report files
    cmd_parser.add_argument('command', type=str)
    #adding argument called command
    cmd_parser.add_argument('file_input', nargs='?', type=str)
    opts = cmd_parser.parse_args(args)
    if opts.command == 'subs_process':
        report = do_subs_all()
        em = EmailCredentials()
        send_mail_sb(em.coming_from, em.going_to, create_message_subject(), create_message_text(report[1]), report[0],
                     em.server, em.port, username=em.username, password=em.password)  # todo, make a class for Mailer and call it that way?
    elif opts.command == 'send_subs_email':
        service = ReportPath(BASEPATH)
        output_file = service.generate_individual_report_filename('subs')
        em = EmailCredentials()
        send_mail_sb(em.coming_from, em.going_to, create_message_subject(), "Subscriber Reporting", output_file,
                     em.server, em.port, username=em.username, password=em.password)  # todo: Make this send the thing. Right now sending something called '.bin'
    elif opts.command == 'update_subs':
        update_subs()
    elif opts.command == 'pull_subs':
        pull_subs_all()
    elif opts.command == 'email_subs':
        send_email()
    # elif opts.command == 'subs_all':
    #     update_subs()
    #     report, text = pull_subs_all()
    #     send_email(report, text) #todo make send email function work
    else:
        raise NotImplementedError('Command not recognized')
示例#2
0
def send_email():
    service = ReportPath(BASEPATH)
    output_file = service.generate_individual_report_filename('subs')
    em = EmailCredentials()
    send_mail_sb(em.coming_from, em.going_to, create_message_subject(), "Subscriber Reporting", output_file,
                em.server, em.port, username=em.username, password=em.password)  # todo: Make this send the thing. Right now sending something called '.bin'