def send_email_report(config, local_repo, email, skip, filter, from_email, to_email, subject, component): """Send an email report based on git commit history""" failed_tests = get_all_failed_tests() author_tests = {} git_blame = () if component is None: with click.progressbar(failed_tests, label='Searching failed tests') as bar: for test in bar: if skip not in test and email is not None and str( filter) not in test: test_name = str(test).split('.')[-1] if local_repo is None: repo_path = config.repo_path + "/".join( test.split('.')[:2]) git_blame = get_test_blame_with_author( test, test_name, repo_path, email, filter) elif local_repo is not None: git_blame = get_test_blame_with_author( test, test_name, local_repo, email, filter) if git_blame[0] not in author_tests: author_tests[git_blame[0]] = [git_blame[1]] else: author_tests[git_blame[0]].append(git_blame[1]) else: with click.progressbar(failed_tests, label='Searching failed tests') as bar: for test in bar: if skip not in test and str(filter) not in test: test_name = str(test).split('.')[-1] repo_path = config.repo_path + "/".join( test.split('.')[:2]) test_path = check_test_path(test_name=test_name, test_path=repo_path, filter=None) if isinstance(test_path, list): test_path = remove_duplicate_test(test_path, test) author_details = get_author_details(component) for author, tags in author_details.items(): for tag in tags: if tag.lower() in test_path.lower(): if author not in author_tests: author_tests[author] = [test] else: author_tests[author].append(test) break content = build_content(author_tests) send_email(from_email=from_email, to_email=to_email, content=content, subject=subject) if not len(author_tests) == 0: echo_success("Email Report Sent Successfully! ") else: echo_success("No Tests Found!")
def send_json(credential_path, content, subject = 'clean-lines', email_content = ""): credentials = load_credentials(credential_path) f = credentials['email'] destination_list = credentials['dest'] if len(destination_list) == 0: destination_list.append(f) p = credentials['pass'] host = credentials['host'] port = credentials['port'] mime_content = MIMEApplication(content, "json") html = MIMEText(email_content, "html") for t in destination_list: print('Sending mail to {}'.format(t)) send_email(f, t, subject, p, host, port, mime_content, [html,])
def main(): if not restic_util.is_running(): email_output = '' for backup_set in config.backup_sets: email_output = (email_output + '\nResult of backing up ' + backup_set[1] + ' to repo ' + backup_set[0] + ':\n' + restic_util.init_and_backup(backup_set[0], backup_set[1]) + restic_util.repo_snapshots(backup_set[0]) + restic_util.check_integrity(backup_set[0])) print(email_output) if config.send_gmail: email_util.send_email(email_output) else: print('Another Restic process is running, aborting.')
def main(): # sender info sender = SEND_EMAIL password = SEND_PWD # receiver's list receiver = RECEIVE_EMAIL sql = EXE_SQL # create data # my_data = get_datas(sql) my_data = get_datas_pool(sql) # create field # my_field = get_fields(sql) my_field = get_fields_pool(sql) # get yesterday's date str yesterdaystr = getYesterday() # file name my_file_name = FILE_NAME + yesterdaystr + FILE_SUFFIX # file path file_path = FILE_PATH if not os.path.exists(file_path): os.makedirs(file_path) # create excel get_excel(my_data, my_field, file_path + my_file_name) email_to = ','.join(receiver) # email subject email_subject = FILE_NAME + yesterdaystr # email content email_content = EMAIL_CONTENT # attachment path attach_path = file_path + my_file_name # attachment name attach_name = my_file_name # create email msg = create_email(sender, email_to, email_subject, email_content, attach_path, attach_name) # send email send_email(sender, password, receiver, msg)
def submit_sign(): submit_url = 'https://gdou.cpdaily.com/wec-counselor-sign-apps/stu/sign/submitSign' wid = get_stu_sign_info() data = { "signInstanceWid": wid, "longitude": longitude, "latitude": latitude, "isMalposition": 1, "abnormalReason": abnormalReason, "signPhotoUrl": "", "position": position } headers['Cpdaily-Extension'] = create_cpdaily_extension( data['longitude'], data['latitude'], username) response = requests.post(submit_url, json=data, headers=headers) if response.json()['message'] == 'SUCCESS': print('result-签到成功') email_util.send_email(email, '签到成功', '今日签到已完成!') else: print('result-%s' % response.json()) email_util.send_email(email, '签到失败', '签到失败,详细信息:%s' % response.json()['message'])
def sendImage(self, msg): file = self.photo_path / (msg['file_name'] + msg['extension']) if msg['server'] == 'telegram': self.bot.sendPhoto(chat_id=self.chat_id, photo=open(file, 'rb'), caption='A photo has been taken from your [' + self.location + '] at ' + msg['date'] + ' ' + msg['time'], timeout=100) elif msg['server'] == 'email': self.mail_body['subject'] = '[Front Door] ' + \ msg['date'] + ' ' + msg['time'] self.mail_body['message'] = 'A photo has been taken from your [' +\ self.location +\ '] at '+msg['date'] + ' '+msg['time'] self.attachement['file_name'] = msg['file_name'] + msg['extension'] send_email(self.mail_server, self.mail_body, self.attachement) logging.info('Send photo') os.remove(file) logging.info('Delete photo')
def msg_process(msg): msg_topic = msg.topic() try: m = pickle.loads(msg.value()) event = json.loads(m) #deserialize = lambda v: json.loads(v.decode('utf-8')) print("Topic:", msg_topic) print("received event:", event) if msg_topic == "python_topic": print("Sending Email to: {}".format(event["data"]["email"])) email_body = "Welcom to the My App! The OTP is: {}. Cheers,Pritesh".format(event["data"]["otp"]) if send_email(event["data"]["email"], msg=email_body): print("Email sent successfully") c.commit() else: print("Failed to send email") elif msg_topic == "send_sms": send_sms('Hi there! Pritesh is here!', event["data"]["mobile"]) #send_sms(msg.value()) c.commit() except Exception as e: print("Errpor:", e)
def get_stu_sign_info(): try: response = requests.post( 'https://gdou.cpdaily.com/wec-counselor-sign-apps/stu/sign/getStuSignInfosInOneDay', json={}, headers=headers) except requests.exceptions.SSLError as e: print('result-获取信息失败') email_util.send_email(email, '签到失败', '签到失败:获取信息失败') exit(0) json = response.json() if json['datas']['signedTasks']: print('result-今日已签到,不再重复提交签到') email_util.send_email(email, '签到失败', '签到失败:今日您已完成签到,不再重复提交签到') exit(0) elif json['datas']['unSignedTasks']: return json['datas']['unSignedTasks'][0]['signInstanceWid'] else: email_util.send_email(email, '签到失败', '签到失败:未获取到签到信息') exit(0)
now_days = pd.to_datetime(datetime.datetime.now()) created_days = pd.to_datetime(df[from_col], format='%Y-%m-%dT%H:%M:%S.%fZ') time_delta = now_days - created_days time_delta_as_days = round(time_delta / np.timedelta64(1, "D")) df[column_name] = time_delta_as_days.astype(int) return df def fix_pricing(price): if pd.isna(price): return '-' price = int(price) price = '{:,}'.format(price) price = price.replace(',', '.') return str(price) def add_boliga_url(estate_id): if str(estate_id) == '0': return '' return f'https://www.boliga.dk/bolig/{estate_id}' if __name__ == "__main__": df_forsale = prepare_forsale() df_sold = prepare_sold() html_forsale = get_html_df(df_forsale, 'For Sale Estates') html_sold = get_html_df(df_sold, 'Sold Estates') email_body = '<br><br>'.join([html_forsale, html_sold]) send_email(email_body)
def send_email_report(config, local_repo, email, skip, filter, from_email, to_email, subject, component, with_link, with_graph, dynamic_graph): """Send an email report based on git commit history""" echo_skip(custom_fig.renderText('tESTBLAME!!')) failed_tests = get_all_failed_tests() author_tests = {} bar_chart = [] pie_chart = [] git_blame = () repo_path = local_repo if component is None: with click.progressbar(failed_tests, label='Searching failed tests') as bar: for test in bar: if skip not in test and email is not None and str( filter) not in test: test_name = str(test).split('.')[-1] if local_repo is None: repo_path = config.repo_path + "/".join( test.split('.')[:2]) git_blame = get_test_blame_with_author( test, test_name, repo_path, email, filter) elif local_repo is not None: git_blame = get_test_blame_with_author( test, test_name, local_repo, email, filter) if git_blame[0] not in author_tests: author_tests[git_blame[0]] = [git_blame[1]] else: author_tests[git_blame[0]].append(git_blame[1]) else: with click.progressbar(failed_tests, label='Searching failed tests') as bar: for test in bar: if skip not in test and str(filter) not in test: test_name = str(test).split('.')[-1] if local_repo is None: repo_path = config.repo_path + "/".join( test.split('.')[:2]) test_path = check_test_path(test_name=test_name, test_path=repo_path, filter=None) if isinstance(test_path, list): test_path = remove_duplicate_test(test_path, test) if with_graph is not None: bar_chart.append(".".join(test.split('.')[2:4])) pie_chart.append(test.split('.')[2]) author_details = get_author_details(component) for author, tags in author_details.items(): for tag in tags: if tag.lower() in test_path.lower(): if author not in author_tests: author_tests[author] = [test] else: author_tests[author].append(test) break if with_link is not None: content = build_content(author_tests, get_jenkins_url_map(), with_link) else: content = build_content(author_tests) if with_graph is not None: bar_chart = dict(Counter(bar_chart)) pie_chart = dict(Counter(pie_chart)) # delete_all_earlier_charts() content = building_graph(content, bar_chart, pie_chart, dynamic_graph=dynamic_graph) for author, tests in author_tests.items(): echo_error("==" * 55) echo_error("{: ^50s}".format(author)) echo_error("==" * 55) echo_error("\n".join(tests)) send_email(from_email=from_email, to_email=to_email, content=content, subject=subject) if len(author_tests) == 0: echo_success("No Tests Found!")
# only run code if not already run today with open(config.path_to_code + "done_dates.txt") as f: done_dates = f.read().split("/") date_today = datetime.today().strftime('%d.%m.%Y') if not date_today in done_dates: # run code try: first_email = move_outs_this_week() second_email = booking_gap_analysis() # Send Emails - each to Muddi and myself recipient = config.recipient_email subject = "Bettenwechsel diese Woche" content = first_email send_email(recipient, subject, content) recipient = config.my_email send_email(recipient, subject, content) recipient = config.recipient_email subject = "Einfache Auslastungsanalyse - Ferienwohnungen" content = second_email send_email(recipient, subject, content) recipient = config.my_email send_email(recipient, subject, content) # write execution to recording file with open(config.path_to_code + "done_dates.txt", "a") as f: f.write(date_today + "/") except Exception as e:
def main(): date_time = datetime.now().strftime("%m-%d-%Y_%H.%M.%S") # initialize the CLI parser parser = GooeyParser( description="Cisco Unified Communications Manager Tool") cucm_group = parser.add_argument_group(title="cucm connection") file_group = parser.add_argument_group(title="output file") email_group = parser.add_argument_group( title="optional email parameters", description="send the output to an email address", ) cucm_group.add_argument( "--address", "-a", action="store", dest="cucm_address", help="specify cucm address", default="ucm1.presidio.cloud", required=True, ) cucm_group.add_argument( "--version", "-v", action="store", dest="cucm_version", choices=["8.5", "10.0", "10.5", "11.0", "11.5", "12.0", "12.5"], help="specify cucm AXL version", required=False, default="11.0", ) cucm_group.add_argument( "--username", "-u", action="store", dest="cucm_username", help="specify ucm account username with AXL permissions", required=True, default="Administrator", ) cucm_group.add_argument( "--password", "-p", action="store", dest="cucm_password", help="specify ucm account password", required=True, default="Dev@1998", widget="PasswordField", ) file_group.add_argument( "--out", "-o", action="store", dest="filename", help='filename of export file (.csv format) - default="export.csv"', required=False, default="export.csv", ) file_group.add_argument( "--timestamp", "-t", action="store_true", dest="timestamp", help="append filename with timestamp", ) cucm_group.add_argument( "--export", "-e", action="store", dest="cucm_export", choices=[ "users", "phones", "translations", "sip-trunks", "registered-phones" ], help="specify what you want to export", required=False, default="users", ) email_group.add_argument( "--smtpserver", "-s", action="store", dest="smtpserver", required=False, help="smtp server name or ip address", ) email_group.add_argument( "--mailto", "-m", action="store", dest="mailto", required=False, help="send output to mail recipient", ) # update variables from cli arguments cli_args = parser.parse_args() filename = cli_args.filename # print(cli_args) # store the UCM details cucm_address = cli_args.cucm_address cucm_username = cli_args.cucm_username cucm_password = cli_args.cucm_password cucm_version = cli_args.cucm_version # initialize Cisco AXL connection ucm_axl = axl( username=cucm_username, password=cucm_password, cucm=cucm_address, cucm_version=cucm_version, ) # TODO: Add RIS connection as separate credentials # ucm_ris = ris( # username=cucm_username, # password=cucm_password, # cucm=cucm_address, # cucm_version=cucm_version, # ) if cli_args.cucm_export == "users": output = cucm.export_users(ucm_axl) if len(output) > 0: saved_file = write_csv(filename=filename, cli_args=cli_args, content=output) else: print(f"status: no {cli_args.cucm_export} found...") print(f"status: elapsed time -- {datetime.now() - start_time}\n") elif cli_args.cucm_export == "phones": output = cucm.export_phones(ucm_axl) if len(output) > 0: saved_file = write_csv(filename=filename, cli_args=cli_args, content=output) else: print(f"status: no {cli_args.cucm_export} found...") print(f"status: elapsed time -- {datetime.now() - start_time}\n") elif cli_args.cucm_export == "translations": output = cucm.export_translations(ucm_axl) if len(output) > 0: saved_file = write_csv(filename=filename, cli_args=cli_args, content=output) else: print(f"status: no {cli_args.cucm_export} found...") print(f"status: elapsed time -- {datetime.now() - start_time}\n") elif cli_args.cucm_export == "sip-trunks": output = cucm.export_siptrunks(ucm_axl) if len(output) > 0: saved_file = write_csv(filename=filename, cli_args=cli_args, content=output) else: print(f"status: no {cli_args.cucm_export} found...") print(f"status: elapsed time -- {datetime.now() - start_time}\n") else: print(f"exporting {cli_args.cucm_export} is not yet supported") return # send email if selected if cli_args.mailto and cli_args.smtpserver: response = send_email( smtp_server=cli_args.smtpserver, send_to_email=cli_args.mailto, fileToSend=saved_file, ) print( f"status: mail sent to {cli_args.mailto} via {cli_args.smtpserver} at {date_time} - {saved_file}" ) elif cli_args.mailto and not cli_args.smtpserver: print(f"status: mail unable to send. no smtp server was defined") elif cli_args.smtpserver and not cli_args.mailto: print(f"status: mail unable to send. no mailto address was defined")