def main(): parser = argparse.ArgumentParser(description="Get Stock Details.") parser.add_argument('username', help="Username for onvista.de") parser.add_argument('password', help="Password for onvista.de") parser.add_argument('--database', help="Database to store stuff in") parser.add_argument('--email', help="Email to send stuff to") parser.add_argument('--no-color', action='store_const', const=True) args = parser.parse_args() data = getDataFromPage(args.username, args.password) if args.email != None: send_email(args.email, data) if args.database != None: store_in_db(args.database, data) if args.email == None and args.database == None: print buildText(data, colored=(args.no_color != True))
def send_email(email, data): msg = MIMEMultipart('alternative') msg['Subject'] = "notes" msg['From'] = "*****@*****.**" msg["To"] = email part1 = MIMEText(buildText(data), 'plain') part1 = MIMEText(buildHTML(data), 'html') msg.attach(part1) s = smtplib.SMTP('localhost') s.sendmail(email, '*****@*****.**', msg.as_string()) s.quit()