def main(): folder = "supplier-data/descriptions/" ext = ".txt" attachment = "/tmp/processed.pdf" mydate = datetime.datetime.now() title = "Processed Update on {} {}, {}".format(mydate.strftime("%B"), mydate.day, mydate.year) paragraph = extract_data(folder, ext) reports.generate_report(attachment, title, paragraph) # TODO: send the PDF report as an email attachment sender = "*****@*****.**" receiver = "{}@example.com".format(os.environ.get('USER')) subject = "Upload Completed - Online Fruit Store" body = "All fruits are uploaded to our website successfully. A detailed list is attached to this email." message = emails.generate(sender, receiver, subject, body, attachment) emails.send(message)
def main(argv): """Process the JSON data and generate a full report out of it.""" data = load_data("car_sales.json") summary = process_data(data) print(summary) # TODO: turn this into a PDF report report_table = cars_dict_to_table(data) reports.generate('/tmp/cars.pdf', "Cars report", summary, report_table) # TODO: send the PDF report as an email attachment sender = "*****@*****.**" receiver = "{}@example.com".format(os.environ.get('USER')) subject = "Sales summary for last month" message = emails.generate(sender, receiver, subject, summary, "/tmp/cars.pdf") emails.send(message)
def main(argv): """Process the JSON data and generate a full report out of it.""" data = load_data("car_sales.json") summary = process_data(data) print(summary) table_data = cars_dict_to_table(data) reports.generate("/tmp/cars.pdf", "Sales summary for last month", "<br/>".join(summary), table_data) # send the PDF report as an email attachment sender = "*****@*****.**" receiver = "{}@example.com".format(os.environ.get('USER')) subject = "Sales summary for last month" body = "\n".join(summary) message = emails.generate(sender, receiver, subject, body, "/tmp/cars.pdf") emails.send(message)
def main(argv): """Process the JSON data and generate a full report out of it.""" data = load_data("car_sales.json") summary = process_data(data) print(summary) # TODO: turn this into a PDF report table_items = cars_dict_to_table(data) string_print = summary[0] + "<br/>" + summary[1] + "<br/>" + summary[2] reports.generate("/tmp/cars.pdf", "Sales summary for last month", string_print, table_items) # TODO: send the PDF report as an email attachment sender = "*****@*****.**" receiver = "{}@example.com".format(os.environ.get('USER')) subject = "Sales summary for last month" body = "Hi,\nI'm sending an attachment with sales summary for last month." message = emails.generate(sender, receiver, subject, body, "/tmp/cars.pdf") emails.send(message)
def main(argv): """Process the JSON data and generate a full report out of it.""" data = load_data("car_sales.json") summary = process_data(data) print(summary) # TODO: turn this into a PDF report paragraph = "<br/>".join(summary) table_data = cars_dict_to_table(data) # TODO: send the PDF report as an email attachment title = "Sales summary for last month" attachment = "/tmp/cars.pdf" reports.generate(attachment, title, paragraph, table_data) sender = "*****@*****.**" receiver = "{}@example.com".format(os.environ.get('USER')) body = "\n".join(summary) message = emails.generate(sender, receiver, title, body, attachment) emails.send(message)
def main(argv): """Process the JSON data and generate a full report out of it.""" data = load_data("car_sales.json") summary = process_data(data) print(summary) # TODO: turn this into a PDF report table_data = cars_dict_to_table(data) reports.generate("/tmp/cars.pdf", "Sales summary for last month", "<br/>".join(summary), table_data) # TODO: send the PDF report as an email attachment sender = "*****@*****.**" receiver = "*****@*****.**" subject = "Sales summary for last month" body = "\n".join(summary) message = emails.generate(sender, receiver, subject, body, "/tmp/cars.pdf") emails.send(message)
def main(argv): """Process the JSON data and generate a full report out of it.""" data = load_data("../car_sales.json") summary = process_data(data) print(summary) summary_with_brakes = "" summary_with_lines = "" for item in summary: summary_with_brakes += item + '<br/>' summary_with_lines += item + '\n' print(summary_with_brakes) # TODO: turn this into a PDF report table_data = cars_dict_to_table(data) reports.generate("/tmp/cars.pdf", "Cars", summary_with_brakes, table_data) # TODO: send the PDF report as an email attachment recipient = "{}@example.com".format(os.environ.get('USER')) message = emails.generate('*****@*****.**', recipient, 'Sales summary for last month', summary_with_lines, "/tmp/cars.pdf") emails.send(message)
def main(argv): """Process the JSON data and generate a full report out of it.""" data = load_data("car_sales.json") summary = process_data(data) title = "Sales summary for last month<br/><br/>" print(summary) br_summary = '<br/>'.join(summary) new_summary = '\n'.join(summary) table_data = cars_dict_to_table(data) # TODO: turn this into a PDF report reports.generate("/tmp/cars.pdf", title, br_summary, table_data) # TODO: send the PDF report as an email attachment sender = "*****@*****.**" receiver = "{}@example.com".format(os.environ.get('USER')) subject = "Sales summary for last month" message = emails.generate(sender, receiver, subject, new_summary, "/tmp/cars.pdf") emails.send(message)
def main(argv): """Process the JSON data and generate a full report out of it.""" data = load_data("car_sales.json") summary = process_data(data) table_data = cars_dict_to_table(data) print(summary) # TODO: turn this into a PDF report reports.generate("/tmp/cars.pdf", "Sales summary of last month", "<br/>".join(summary), table_data) # TODO: send the PDF report as an email message = emails.generate("*****@*****.**", "*****@*****.**", "Sales summary for last month", "\n".join(summary), "/tmp/cars.pdf") emails.send(message)
def main(argv): """Process the JSON data and generate a full report out of it.""" data = load_data("car_sales.json") summary = process_data(data) print(summary) table_data = cars_dict_to_table(data) # TODO: turn this into a PDF report reports.generate("/tmp/cars.pdf", "A Summary of car sales", "Most Sales, Most Revenue, Most Popular Year", table_data) # TODO: send the PDF report as an email attachment sender = "*****@*****.**" receiver = "{}@example.com".format(os.environ.get('USER')) subject = "Sales sumary for last month" body = "The same summary from the PDF, but using \n between the lines" message = emails.generate(sender, receiver, subject, body, "/tmp/report.pdf") emails.send(message)
def main(argv): """Process the JSON data and generate a full report out of it.""" data = load_data(argv[1]) summary = process_data(data) table_data = cars_dict_to_table(data) # turn this into a PDF report reports.generate( "/tmp/cars.pdf", "Sales Summary for last month", "{}<br/>{}<br/>{}<br/>".format(summary[0], summary[1], summary[2]), table_data) # send the PDF report as an email attachment sender = "<user>@example.com" receiver = "*****@*****.**" subject = "Sales Summary for last month" body = "{}\n{}\n{}\n".format(summary[0], summary[1], summary[2]) message = emails.generate(sender, receiver, subject, body, "/tmp/cars.pdf") emails.send(message)
def main(argv): """Process the JSON data and generate a full report out of it.""" data = load_data("car_sales.json") summary = process_data(data) d = cars_dict_to_table(data) # TODO: turn this into a PDF report reports.generate('/tmp/cars.pdf', 'Sales summary for last month', ''.join(summary), d) # TODO: send the PDF report as an email attachment summary[1] = '\n' summary[3] = '\n' s = ''.join(summary) # print(s) msg = emails.generate('*****@*****.**', '{}@example.com'.format(os.environ.get('USER')), 'Sales summary for last month', s, '/tmp/cars.pdf') # print(msg) r = emails.send(msg)
def main(argv): """Process the JSON data and generate a full report out of it.""" data = load_data("car_sales.json") summary = process_data(data) new_summary = '<br/'.join(summary) print(summary) # TODO: turn this into a PDF report reports.generate("/tmp/cars.pdf", "Car Sales Statistics", new_summary, cars_dict_to_table(data)) # TODO: send the PDF report as an email attachment sender = "*****@*****.**" receiver = "{}@example.com".format(os.environ.get('USER')) subject = "Sales summary for last month" body = "{}\n{}\n{}".format(summary[0], summary[1], summary[2]) message = emails.generate(sender, receiver, subject, body, "/tmp/cars.pdf") emails.send(message)
def main(argv): """Process the JSON data and generate a full report out of it.""" data = load_data("../car_sales.json") summary = process_data(data) formatted_summary = "<br\>".join(summary) path = "tmp/cars.pdf" # change to /tmp/ # TODO: turn this into a PDF report reports.generate(path, "Sales summary for last month", formatted_summary, cars_dict_to_table(data)) # TODO: send the PDF report as an email attachment msg = emails.generate( "*****@*****.**", "<user>@example.com", # add user "Sales summary for last month", "\n".join(summary), path) emails.send(msg)
def main(argv): data = load_data(os.path.expanduser('~') + "/car_sales.json") summary = process_data(data) # Generate a paragraph that contains the necessary summary paragraph = "<br/>".join(summary) # Generate a table that contains the list of cars table_data = cars_dict_to_table(data) # Generate the PDF report title = "Sales summary for last month" attachment = "/tmp/cars.pdf" reports.generate(attachment, title, paragraph, table_data) # Send the email sender = "*****@*****.**" receiver = "{}@example.com".format(os.environ.get('USER')) body = "\n".join(summary) message = emails.generate(sender, receiver, title, body, attachment) emails.send(message)
def check_health(): errormessage = "" if psutil.cpu_percent(interval=1) > 80: errormessage = "CPU usage is over 80%" total, used, free = shutil.disk_usage("/") td = (total // (2**30)) tf = (free // (2**30)) perfree = ((tf / td) * 100) if perfree < 20: errormessage += "\nAvailable disk space is less than 20%" mem = virtual_memory() mem.total THRESHOLD = 500 * 1024 * 1024 if mem.available < THRESHOLD: errormessage += "\nAvailable memory is less than 500MB" try: host_name = socket.gethostname() host_ip = socket.gethostbyname(host_name) print("Hostname : ", host_name) print("IP : ", host_ip) except: errormessage += "{} cannot be resolved to {}".format( host_name, host_ip) print(errormessage) if len(errormessage) > 0: sender = "*****@*****.**" receiver = "{}@example.com".format(os.environ.get('USER')) subject = errormessage body = "Please check your system and resolve the issue as soon as possible." message = emails.generate(sender, receiver, subject, body, "") emails.send(message)
def main(argv): """Process the JSON data and generate a full report out of it.""" data = load_data("car_sales.json") summary = process_data(data) table_data = cars_dict_to_table(data) para = summary[0] + "\n" + summary[1] + "\n" + summary[2] para_pdf = summary[0] + "<br/>" + summary[1] + "<br/>" + summary[2] reports.generate("/tmp/cars.pdf", "Sales Summary for last month", para_pdf, table_data) sender = "*****@*****.**" receiver = "{}@example.com".format(os.environ.get('USER')) subject = "Sales summary for last month" body = para_pdf message = emails.generate(sender, receiver, subject, "PFA the summary for last month", "/tmp/cars.pdf") emails.send(message) print(para)
def main(argv): """Process the JSON data and generate a full report out of it.""" data = load_data("car_sales.json") summary = process_data(data) print(summary) # TODO: turn this into a PDF report table_data = cars_dict_to_table(data) print(table_data) path = '/tmp/cars.pdf' additional_info = "<br/>".join(summary) title = 'Sales summary for last month' reports.generate(path, title, additional_info, table_data) # TODO: send the PDF report as an email attachment from_text = '*****@*****.**' to_text = '{}@example.com'.format(os.environ.get('USER')) subject_text = 'Sales summary for last month' body_text = "\n".join(summary) message = emails.generate(from_text, to_text, subject_text, body_text, path) emails.send(message)
def main(argv): """Process the JSON data and generate a full report out of it.""" data = load_data("car_sales.json") summary = process_data(data) print(summary) # TODO: turn this into a PDF report filename = "/tmp/cars.pdf" title = "Sales summary for last month" additional_info = "<br/>".join(summary) table_data = cars_dict_to_table(data) reports.generate(filename, title, additional_info, table_data) # TODO: send the PDF report as an email attachment sender = "*****@*****.**" recipient = "{}@example.com".format(os.environ.get('USER')) subject = "Sales summary for last month" body = "\n".join(summary) attachment_path = "/tmp/cars.pdf" message = emails.generate(sender, recipient, subject, body, attachment_path) emails.send(message)
def main(argv): """Process the JSON data and generate a full report out of it.""" data = load_data("../car_sales.json") summary = process_data(data) print(summary) # Turn this summary into a PDF report filename = "cars.pdf" body = summary[0] + '<br/>' + summary[1] + '<br/>' + summary[2] title = "Sales summary for last month" table_data = cars_dict_to_table(data) reports.generate(filename, title, body, table_data) # Send the PDF report as an email attachment sender = "*****@*****.**" recipient = "*****@*****.**" subject = "Sales summary for last month" body = body.replace('<br/>', '\n') a_path = "cars.pdf" message = emails.generate(sender, recipient, subject, body, a_path) emails.send(message)
def main(argv): """Process the JSON data and generate a full report out of it.""" data = load_data("../car_sales.json") summary = process_data(data) table_data = cars_dict_to_table(data) print(summary) # Turn this into a PDF report reports.generate("/tmp/cars.pdf", "A Complete Summary of car sales", summary[0] + "<br/>" + summary[1] + "<br/>" + summary[2], table_data) # Send the PDF report as an email attachment sender = "*****@*****.**" receiver = "{}@example.com".format(os.environ.get('USER')) subject = "Sales summary for last month" body = "A Complete Summary of car sales\n\n" + summary[0] + "\n" + summary[ 1] + "\n" + summary[2] + "\n" message = emails.generate(sender, receiver, subject, body, "/tmp/cars.pdf") emails.send(message)
def main(argv): """Process the JSON data and generate a full report out of it.""" data = load_data("car_sales.json") summary = process_data(data) print(summary) # TODO: turn this into a PDF report table_raw = table[1:] table_sorted = sorted(table_raw, key=lambda x:x[1], reverse=False) #adding the header back to the table table_sorted.insert(0, ["ID", "Car", "Price", "Total Sales"]) report_summary = summary[0] + "<br/>" + summary[1] + "<br/>" + summary[2] + "<br/>" reports.generate("/tmp/cars.pdf", "Title", report_summary , table_sorted) # TODO: send the PDF report as an email attachment sender = "*****@*****.**" receiver = "*****@*****.**" subject = "Sales summary for last month" body = summary[0] + "\n" + summary[1] + "\n" + summary[2] + "\n" package = "/tmp/cars.pdf" message = emails.generate(sender, receiver, subject, body, package) emails.send(message)
def main(argv): summary = [] for root, _, files in os.walk(description_path): for filename in files: if filename.endswith(".txt"): fruit_str = process_file(root, filename) summary.append(fruit_str) summary_str = "<br /><br />".join(summary) reports.generate_report("/tmp/processed.pdf", "Processed Update on {}".format(today), summary_str) # TODO: send the PDF report as an email attachment sender = "*****@*****.**" receiver = "{}@example.com".format(os.environ.get('USER')) subject = "Upload Completed - Online Fruit Store" body = "All fruits are uploaded to our website successfully. A detailed list is attached to this email." message = emails.generate(sender, receiver, subject, body, "/tmp/processed.pdf") emails.send(message)
def main(argv): """Process the JSON data and generate a full report out of it.""" data = load_data("car_sales.json") summary = process_data(data) print(summary) # TODO: turn this into a PDF report report_summary = "" for line in summary: report_summary += line report_summary += '<br/>' reports.generate("/tmp/cars.pdf", "Sales summary for last month", report_summary, cars_dict_to_table(data)) # TODO: send the PDF report as an email attachment sender = "*****@*****.**" recipient = "{}@example.com".format(os.environ.get('USER')) subject = "Sales summary for last month" att_path = "/tmp/cars.pdf" email_summary = "" for line in summary: email_summary += line + '\n' emails.send( emails.generate(sender, recipient, subject, email_summary, att_path))
def main(argv): """Process the JSON data and generate a full report out of it.""" data = load_data("car_sales.json") summary = process_data(data) # TODO: turn this into a PDF report # we'll transform the list into a string ans add <br/> : str_summarybr = "" str_summaryn = "" for elem in summary: str_summarybr += elem+"<br/>" str_summaryn += elem+"\n" reports.generate("cars.pdf", "Sales summary for last month", str_summarybr, cars_dict_to_table(data)) # TODO: send the PDF report as an email attachment sender = "*****@*****.**" recipient = "*****@*****.**" subject = "Sales summary for last month" body = str_summaryn attachment_path = "cars.pdf" emails.send(emails.generate(sender, recipient, subject, body, attachment_path))
def main(argv): """Process the JSON data and generate a full report out of it.""" data = load_data("car_sales.json") summary = process_data(data) print(summary) # Turn this into a PDF report summary_l = "" for elem in summary: summary_l = summary_l + elem + "<br/>" reports.generate("/tmp/cars.pdf", "Cars", summary_l, cars_dict_to_table(data)) # Send the PDF report as an email attachment sender = "*****@*****.**" receiver = "{}@example.com".format(os.environ.get('USER')) subject = "Sales summary for last month" body = "" for elem in summary: body = body + elem + "\n" message = emails.generate(sender, receiver, subject, body, "/tmp/cars.pdf") emails.send(message)
def main(argv): """Process the JSON data and generate a full report out of it.""" data = load_data("car_sales.json") summary = process_data(data) print(summary) table_data=cars_dict_to_table(data) #print(table_data) # TODO: turn this into a PDF report styles = getSampleStyleSheet() report = SimpleDocTemplate("/tmp/cars.pdf") report_title = Paragraph("Sales summary for last month", styles["h1"]) report_summary = Paragraph(' '.join([str(elem) for elem in summary]), styles["Normal"]) table_style = [('GRID', (0,0), (-1,-1), 1, colors.black)] report_table = Table(data=table_data, style=table_style, hAlign="LEFT") report.build([report_title,report_summary, report_table]) # TODO: send the PDF report as an email attachment sender = "*****@*****.**" receiver = "{}@example.com".format(os.environ.get('USER')) subject = "Sales summary for last month" body = ' '.join([str(elem) for elem in summary]) message = emails.generate(sender, receiver, subject, body, "/tmp/cars.pdf") emails.send(message)
def main(argv): """Process the JSON data and generate a full report out of it.""" data = load_data("car_sales.json") summary = process_data(data) summary_with_breaks = "<br/>".join(summary) summary_for_email = "<\n>".join(summary) # print(summary_with_breaks) # TODO: turn this into a PDF report #Convert car data from json/dictionary to two dimensional array (list of lists) table = cars_dict_to_table(data) #print(table) report.generate("/home/<username>/report.pdf", "Car Sales History", summary_with_breaks, table) # TODO: send the PDF report as an email attachment sender = "*****@*****.**" receiver = "*****@*****.**" subject = "Sales summary for last month" body = summary_for_email message = emails.generate(sender, receiver, subject, body, "/home/<username>/report.pdf") emails.send(message)
def main(argv): """Process the JSON data and generate a full report out of it.""" data = load_data("car_sales.json") #TODO Sort the data by total sales sorted_data = sorted(data, key=lambda i: i['total_sales'], reverse=True) # sort by total sales, descending summary = process_data(data) # TODO: turn this into a PDF report table_data = cars_dict_to_table(data) text_summary = '<br/>\n'.join(summary) print(text_summary) reports.generate("/tmp/cars.pdf", "A Complete Summary of Monthly Car Sales", text_summary, table_data) # TODO: send the PDF report as an email attachment sender = "*****@*****.**" receiver = "{}@example.com".format(os.environ.get('USER')) subject = "Sales summary for last month" body = '\n'.join(summary) message = emails.generate(sender, receiver, subject, body, "/tmp/cars.pdf") # creates email emails.send(message)
def main(argv): """Process the JSON data and generate a full report out of it.""" data = load_data("car_sales.json") summary = process_data(data) print(summary) # TODO: turn this into a PDF report reports.generate( 'cars.pdf', 'Car Sales Report', 'Detailed Analysis of Car sales and generation of insights<br/><br/>{}<br/>{}<br/>{}<br/>' .format(summary[0], summary[1], summary[2]), cars_dict_to_table(data)) # TODO: send the PDF report as an email attachment # Generate Email sender = '*****@*****.**' receiver = '{}@example.com'.format(os.environ.get('USER')) subject = 'Sales summary for last month' body = "Detailed Analysis of Car sales and generation of insights'\n'{}'\n'{}'\n'{}'\n'".format( summary[0], summary[1], summary[2]) attachment_path = 'cars.pdf' message = emails.generate(sender, receiver, subject, body, attachment_path) # Send Email emails.send(message)