def send_activation_code(request): body = JSONParser().parse(request) user = authenticate(username=body['username'], password=body['password']) if user is not None: if user.approved: return JsonResponse(create_response( data=None, success=False, error_code=ResponseCodes.email_already_verified), safe=False) else: activation_key, expiration_time = utils.generate_activation_key_and_expiredate( body['username']) user.activation_key = activation_key user.key_expires = expiration_time user.save() utils.send_email(user.email, activation_key, 'activate') return JsonResponse(create_response(data=None, success=True), safe=False) else: return JsonResponse(create_response( data=None, success=False, error_code=ResponseCodes.invalid_credentials), safe=False)
def main(): # Get project object project = utils.get_project() # Find all project issues issues_stats = list() issues = utils.get_issues(project, {'sort': 'desc'}) # Get issue information for issue in issues: utils.issue_info(issue, issues_stats) # Convert to pandas DataFrame and save it as a CSV file df = pd.DataFrame(issues_stats) df.to_csv('report.csv', encoding='utf-8') # Send report by email today = datetime.date.today() utils.send_email(email_from=config.EMAIL_FROM, email_from_pass=config.EMAIL_FROM_PASS, email_to=config.EMAIL_FROM, subject='Reporte de bugs del {:02d}/{}'.format( today.month, today.year ), attach='report.csv') # Delete CSV file os.remove('report.csv')
async def send_email_in_background(message, subject, from_email, to_email, timeout=0): await asyncio.sleep(timeout) send_email(message, subject, from_email, to_email)
def main(): apt = [] parsed_apt = [] for neigborhood in config.neigborhoods.values(): get_apt_in_neigborhood(apt, neigborhood) parsed_apt.extend(utils.extract_important_info(apt)) print('found {} apartments'.format(len(parsed_apt))) utils.send_email(parsed_apt) print(apt)
def check_rank(self, av_id: int, times=0): rank_list = self.rank_map[av_id] if av_id in self.rank_map else [] changeHeaders({'Referer': self.BASIC_AV_URL % av_id}) if len(rank_list): score = int(rank_list[1]) rank = int(rank_list[0]) url = self.ARCHIVE_STAT_URL % av_id json_req = get_request_proxy(url, 1) if not self.have_error(json_req): if times < 3: self.check_rank(av_id, times + 1) return json_req = json_req['data'] need = [ 'view', 'like', 'coin', 'favorite', 'reply', 'share', 'danmaku' ] data = [json_req[index] for index in need] if not self.check_view(av_id, data[0]): if times < 3: self.check_rank(av_id, times + 1) return if len(rank_list): data = [time_str(), *data, *rank_list[:2], *rank_list[3:5]] else: data = [time_str(), *data] with codecs.open('%s%d.csv' % (history_dir, av_id), 'a', encoding='utf-8') as f: f.write(','.join([str(index) for index in data]) + '\n') if self.check_rank_list(av_id, rank_list): av_id_id = int(av_id) * 10 + int(rank_list[-1]) if av_id_id not in self.rank: self.rank[av_id_id] = [rank_list[0] // 10] else: self.rank[av_id_id].append(rank_list[0] // 10) self.last_rank[av_id_id] = rank_list[0] send_email( '%dday List || Rank: %d Score: %d' % (int(rank_list[-1]), rank, score), '%dday List || Rank: %d Score: %d' % (int(rank_list[-1]), rank, score)) if av_id in self.last_check and self.last_check[av_id] - int( time.time()) > one_day: del self.rank_map[av_id] elif av_id not in self.last_check and int( time.time()) > one_day + self.begin_timestamp: del self.rank_map[av_id] self.last_view[av_id] = data[1]
def have_places_once(self): """ have places """ url = 'http://elective.pku.edu.cn/elective2008/edu/pku/stu/elective/controller/supplement/refreshLimit.do' if not os.path.exists('%scookie' % data_path): print('Brush Cookie not exist!!!') return with open('%scookie' % data_path, 'r') as f: cookie = f.readlines() headers = { 'pragma': 'no-cache', 'X-Requested-With': 'XMLHttpRequest', 'cache-control': 'no-cache', 'Cookie': '', 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8', 'Accept': 'application/json, text/javascript, */*; q=0.01', "Accept-Encoding": "", "Accept-Language": "zh-CN,zh;q=0.9", "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3682.0 Safari/537.36", "Origin": "http://elective.pku.edu.cn", "Referer": "http://elective.pku.edu.cn/elective2008/edu/pku/stu/elective/controller/supplement/SupplyCancel.do", } headers['Cookie'] = cookie[0][:-1] data = { "index": '10', "seq": 'yjkc20141100016542', } ca = get_request_proxy(url, 11, data, header=headers) if not ca: if round(time.time()) - self.laster_timestamp > 60: send_email("Cookie failure", "Cookie failure") return False print(ca['electedNum']) self.laster_timestamp = round(time.time()) return int(ca['electedNum']) < 120
def check_rank_rose(self, av_id, rank_list): ''' check rank rose ''' if self.check_rank_list(av_id, rank_list): rank, score = rank_list[:2] av_id_id = int(av_id) * 10 + int(rank_list[-1]) if av_id_id not in self.rank: self.rank[av_id_id] = [rank_list[0] // 10] else: self.rank[av_id_id].append(rank_list[0] // 10) self.last_rank[av_id_id] = rank_list[0] send_email( '%d day List || Rank: %d Score: %d' % (int(rank_list[-1]), rank, score), '%d day List || Rank: %d Score: %d' % (int(rank_list[-1]), rank, score))
def have_bad_comment(self, req_list: list, av_id: int, pn: int, parent_floor=None): ''' check comment and send warning email if error ''' floor, ctime, like, _, _, uname, sex, content, sign = req_list if not len(re.findall(self.keyword, content)): return True floor = str( floor) if parent_floor is None else '%d-%d' % (parent_floor, floor) url = self.BASIC_AV_URL % av_id if str(av_id) in self.ignore_comment and floor in self.ignore_comment[ str(av_id)]: return True email_content = '%s\nUrl: %s Page: %d #%s,\nUser: %s,\nSex: %s,\nconetnt: %s,\nsign: %s\nlike: %d' % ( ctime, url, pn, floor, uname, sex, content, sign, like) email_subject = '(%s)av_id: %s || #%s Comment Warning !!!' % ( ctime, av_id, floor) print(email_content, email_subject) send_email_time = 0 send_email_result = False while not send_email_result and send_email_time < 4: send_email_result = send_email(email_content, email_subject) send_email_time += 1
def main(): """ Main function is the starting point of the program. Properties from the yaml are loaded in order to be used as configuration to the program. If the dataset and the embeddings files are not already downloaded, property setup_folders should be set to True. The scripts setup.sh or setup.bat are used (based on the operating system) in order to download the necessary files. The next step is to read the csv of the selected dataset and convert the data into input vectors. The recommendation is system is built using two methods: the collaborative and the content-based methods. For the collaborative method, the ratings of a user are used as input vector and they are fed in a kmeans model. On the other hand, for the content-based method, information about the user and the movie are used (associated with each live of the ratings.csv). The rating serves as label to each input vector. Based on the classification property, the labels are either binary (like, dislike) or 5 different classes (representing the possible ratings). The models used for the content-based method are: KNN, Random Forest and Deep Neural Networks. The dataset is split into training and testing datasets. The testing dataset is kept aside, while the training is split into folds for 10-fold cross-validation. Finally, the testing dataset is used as additional validation of the model. The confusion matrices of the folds as well as the one produced by the test dataset are used in order to calculate micro/macro precision, recall, F-measure. The visualization method can be used in order to produce plots of the micro/macro metrics. """ # load properties properties = utils.load_properties() logger = utils.config_logger(properties) logger.info("Configuration file is loaded") if properties["setup_folders"]: logger.info( "Set up folders is true. Glove vectors and datasets will be downloaded" ) utils.setup_folders(properties=properties, logger=logger) # get dataset filenames to read logger.info("Collect the dataset filenames") file_names = utils.get_filenames(properties) # read datasets logger.info("Creating dataframes from the csvs in the selected dataset") dp = DataPreprocessing() dp.read_csv(file_names) csvs = dp.datasets if Methods.collaborative.value in properties["methods"]: run_collaborative(properties=properties, csvs=csvs, logger=logger) if Methods.content_based.value in properties["methods"]: run_content_based(properties=properties, csvs=csvs, logger=logger) if properties["execution_kind"] == "test": run_test(properties=properties, csvs=csvs, logger=logger) utils.send_email(properties=properties, logger=logger)
def contact(): form = ContactForm(request.form) if request.method == 'POST': name = request.form['name'] message = request.form['message'] email = request.form['email'] if form.validate(): send_email(recipients=[email], sender_name=name, body_msg=name + ' has sent a message: ' + message) flash('Thanks for your message, ' + name, category='success') return redirect('/contact') else: flash('Error happened, your message is not sent yet.', category='danger') return render_template('contact.html', title='Contact Us', form=form)
def load_rank(self): ''' load rank ''' assign_1 = self.load_rank_index(1, 1) assign_2 = self.load_rank_index(1, 3) have_assign = assign_1 or assign_2 print(assign_1, assign_2, have_assign) if self.have_assign and not have_assign: send_email('No rank.....No Rank......No Rank.....', 'No rank.....No Rank......No Rank.....') self.have_assign = have_assign print('Rank_map_len:', len(self.rank_map.keys()), 'Empty:', len([1 for ii in self.rank_map.values() if not len(ii)])) youshan = [ ','.join([str(kk) for kk in [ii, *jj]]) for ii, jj in self.rank_map.items() ] with codecs.open(data_dir + 'youshang', 'w', encoding='utf-8') as f: f.write('\n'.join(youshan))
async def post(self, **kw): try: json_data = await self.request.json() except (AssertionError, ValueError): raise NotJSONData restore_password_schema = UserSchema(strict=True, only=('email', )) data = restore_password_schema.load(json_data).data email = data['email'] user = await User.find_one({'email': email}) if user is None: raise NoSuchUser password = generate_password() user.set_password(password) await user.commit() send_email(RESTORE_PASSWORD['mail']['text'].format(code=password), RESTORE_PASSWORD['mail']['subject'], SENDER_EMAIL, email) raise Ok
def forgot_password(request): body = JSONParser().parse(request) if 'recaptcha_token' in body and utils.verify_recaptcha( None, body['recaptcha_token'], 'forgot_password') == ResponseCodes.verify_recaptcha_failed: return JsonResponse(create_response( data=None, success=False, error_code=ResponseCodes.verify_recaptcha_failed), safe=False) username = body['username'] try: user = User.objects.get( Q(username__iexact=username) | Q(email__iexact=username)) activation_key, expiration_time = utils.generate_activation_key_and_expiredate( user.username) user.forgot_password_key = activation_key user.forgot_password_key_expires = expiration_time user.save() utils.send_email(user.email, activation_key, 'validateForgotPassword') except Exception as e: log(traceback.format_exception(None, e, e.__traceback__), 'e') return JsonResponse(create_response(data=None, success=True), safe=False)
def have_places(self): """ brush class """ version = begin_time() have_places = False while not have_places: if self.have_places_once(): send_email('大数据专题', '大数据专题 有名额啦 有名额啦') send_email('大数据专题', '大数据专题 有名额啦 有名额啦') send_email('大数据专题', '大数据专题 有名额啦 有名额啦') have_places = True time.sleep(random.randint(10, 20)) end_time(version)
def send_order(order, webinar_string, params): order_info = { "first_name": order["first_name"], "last_name": order["last_name"], "id": order["id"], "webinar_string": webinar_string, } with open("email_template.html", "rb") as f: html = f.read().decode("UTF-8") template = Template(html) email_message = template.render(**order_info) contents = [email_message] attachments = [] if "files" in order: attachments = order["files"] subject = f"Заказ №{order['id']}" return send_email( params=params, to_email=order["email"], subject=subject, contents=contents, attachments=attachments, )
def create_user_profile(cls, **kwargs): """ Create user profile by provided user_email, user_password, user_mobile, user_nick REQUIREMENT PARAM: - user_mobile/user_email, at least one param is required - user_password - user_nick - register_ip - sex - province (this is important) - city (important info) - district (should be provided) OPTIONAL PARAM: - another param is optional """ if 'user_mobile' in kwargs.keys(): user_mobile = kwargs.get('user_mobile') else: user_mobile = None if 'user_email' in kwargs.keys(): user_email = kwargs.get('user_email') else: user_email = None if user_mobile is None and user_email is None: return dict(msg="Please provide user_mobile/user_email, at least one!", msg_cn="请用正确的邮箱或电话注册!", warn="OK") # if user_mobile is not None: # user_obj = UserProfile(user_mobile=user_mobile, # user_password=kwargs.get('user_password'), # user_nick=kwargs.get('user_nick'), # register_ip=kwargs.get('register_ip'), # sex=kwargs.get('sex'), # province=kwargs.get('province'), # city=kwargs.get('city'), # register_time=datetime.datetime.utcnow().replace(tzinfo=utc), # last_login_time=datetime.datetime.utcnow().replace(tzinfo=utc), # district=kwargs.get('district')) # user_obj.save() # return dict(msg="Success register in mobile phone number") if user_email is not None and cls.check_email(user_email): valid_code = utils.random_bits(128) user_obj = UserProfile(user_email=user_email, user_password=kwargs.get('password'), register_ip=kwargs.get('register_ip'), last_login_ip=kwargs.get('register_ip'), sex=kwargs.get('gender'), valid_code=valid_code, city=kwargs.get('city_name')) user_obj.save() # send valid code msg = utils.html_template_wrapper("templates/mail/valid_template.html", "{{ link }}", settings.SITE_ADDRESS+"/activeAccount"+\ "?validCode="+str(valid_code)+\ "&user_email="+user_email) # print msg # pool = Pool(processes=1) # pool.apply_async(utils.send_email, [(user_email, "Account Active Link From" + settings.SITE_NAME)]) # TODO here should add another asynchronize procedure [send active email] utils.send_email(user_email, subject="Account Active Link From" + settings.SITE_NAME, html_str=msg) return dict(msg="Success register in email, please check your email to active user!", msg_cn="注册成功,请查收邮箱激活用户!", result="OK") else: return dict(msg="Fail in register (email have been registered before), please contact the admin!", msg_cn="注册失败 (邮箱已注册),请联系管理员!", result=None)
else: error_messages.append("Connection refused for query vot: %s" % query_votazione) else: error_messages.append("Connection refused for query seduta vot: %s" % query_seduta_votazioni) write_file(output_path+ seduta_file_pattern+ seduta['numero']+".json", total_result, fields=None, print_metadata=False, Json=True ) else: error_messages.append("Connection refused for query seduta: %s" % query_seduta) else: print "nessuna nuova seduta" exit(1) else: error_messages.append("Connection refused for query sedute: %s" % query_sedute) # se ci sono stati errori manda una singola email con tutti gli errori if len(error_messages)>0: error_message='<BR>'.join(error_messages) send_email(smtp_server, notification_system,notification_list,"Sparql Senato: http error",error_message)
def register(request): # Get form values body = JSONParser().parse(request) if 'recaptcha_token' in body and utils.verify_recaptcha( None, body['recaptcha_token'], 'signup') == ResponseCodes.verify_recaptcha_failed: return JsonResponse(create_response( data=None, success=False, error_code=ResponseCodes.verify_recaptcha_failed), safe=False) first_name = '' last_name = '' linkedin_auth_code = None google_access_token = None if 'first_name' in body: first_name = body['first_name'] if 'last_name' in body: last_name = body['last_name'] if 'linkedin_auth_code' in body: linkedin_auth_code = body['linkedin_auth_code'] if 'google_access_token' in body: google_access_token = body['google_access_token'] user_type, new = UserType.objects.get_or_create(name__iexact='Employer') username = body['username'] email = body['email'] password = body['password'] password2 = body['password2'] if '@' in username: return JsonResponse(create_response( data=None, success=False, error_code=ResponseCodes.invalid_username), safe=False) # Check if passwords match if password == password2: # Check username if User.objects.filter(username__iexact=username).exists(): success = False code = ResponseCodes.username_exists else: if User.objects.filter(email__iexact=email).exists(): success = False code = ResponseCodes.email_exists else: # Looks good user = User.objects.create_user(username=username, password=password, email=email, first_name=first_name, user_type=user_type, last_name=last_name, approved=False, activation_key=None, key_expires=None) user.save() if linkedin_auth_code is None and google_access_token is None: activation_key, expiration_time = utils.generate_activation_key_and_expiredate( body['username']) user.activation_key = activation_key user.key_expires = expiration_time user.save() utils.send_email(user.email, activation_key, 'activate') post_data = { 'client_id': body['client_id'], 'client_secret': body['client_secret'], 'grant_type': 'password', 'username': username, 'password': password } response = requests.post( 'http://localhost:8001/auth/token', data=json.dumps(post_data), headers={'content-type': 'application/json'}) json_res = json.loads(response.text) if 'error' in json_res: success = False code = ResponseCodes.couldnt_login else: success = True code = ResponseCodes.success json_res['user_type'] = UserTypeSerializer( instance=user.user_type, many=False).data json_res[ 'signup_flow_completed'] = user.signup_flow_completed return JsonResponse(create_response(data=json_res, success=success, error_code=code), safe=False) else: post_data = { 'client_id': body['client_id'], 'client_secret': body['client_secret'], 'grant_type': 'convert_token' } if linkedin_auth_code is not None: post_data['backend'] = 'linkedin-oauth2' post_data['token'] = get_access_token_with_code( body['linkedin_auth_code']) else: post_data['backend'] = 'google-oauth2' post_data['token'] = body['google_access_token'] response = requests.post( 'http://localhost:8001/auth/convert-token', data=json.dumps(post_data), headers={'content-type': 'application/json'}) jsonres = json.loads(response.text) log(jsonres, 'e') if 'error' in jsonres: success = False code = ResponseCodes.invalid_credentials else: social_user = UserSocialAuth.objects.get( extra_data__icontains=post_data['token']) if social_user.user.email != user.email: social_user.user.delete() social_user.user = user social_user.save() success = True code = ResponseCodes.success user = AccessToken.objects.get( token=jsonres['access_token']).user jsonres['user_type'] = UserTypeSerializer( instance=user.user_type, many=False).data jsonres[ 'signup_flow_completed'] = user.signup_flow_completed user.approved = True user.save() return JsonResponse(create_response(data=jsonres, success=success, error_code=code), safe=False) else: success = False code = ResponseCodes.passwords_do_not_match return JsonResponse(create_response(data=None, success=success, error_code=code), safe=False)
# then checkout proceed_to_checkout_button = WebDriverWait(driver, 5).until( EC.presence_of_element_located( (By.NAME, "proceedToALMCheckout-VUZHIFdob2xlIEZvb2Rz"))) proceed_to_checkout_button.click() continue_button = WebDriverWait(driver, 5).until( EC.presence_of_element_located((By.ID, "a-autoid-0"))) continue_button.click() subs_continue_button = WebDriverWait(driver, 7).until( EC.presence_of_element_located((By.ID, "subsContinueButton"))) subs_continue_button.click() # Check if there are slots no_slot_pattern = "No delivery windows available. New windows are released" + \ " throughout the day." no_slot_signal = WebDriverWait(driver, 5).until( EC.presence_of_element_located( (By.XPATH, "/html/body/div[5]/div[1]/div/div[2]/div/div/div/div/div[1]/" + "div[4]/div[2]/div/div[3]/div/div/div/h4"))) if (no_slot_signal.text == no_slot_pattern): print("NO SLOTS!") send_email("Looks like no slots available right now :(") else: print('SLOTS OPEN!') send_email("Looks like there is a slot! Go order now :)")
def add(files, time_uploaded, email): # should also check for torch availability here # https://stackoverflow.com/questions/44617476/how-to-execute-celery-tasks-conditionally-python counter = 0 file_paths = [] filenames = [] if checkGPU(): formatted_time = str(int(time_uploaded)) print("this is formatted", formatted_time) usr_dir = img_folder + email + '/' usr_img_dir = img_folder + email + '/' + formatted_time usr_input_img_dir = usr_img_dir + '/input' + '/' usr_transfer_img_dir = usr_img_dir + '/transfer' + '/' usr_output_img_dir = usr_img_dir + '/output' + '/' for file in files: file_data = file[0]['base64String'] file_type = file[0]['type'] time_uploaded = file[0]['timeUploaded'] file_name = file[0]['fileName'] print("this is file_type", file_type) img = stringToImage(file_data, file_type) img = toRGB(img) height = img.shape[0] width = img.shape[1] # resize image if necessary if height > max_height: img = rescaleImg(img, height, width, max_height) height = img.shape[0] width = img.shape[1] print("this is img", img) # img here is a numpy array now, save it create_dir(img_folder) if counter == 0: print("this is input") print("this is filename", file_name) create_dir(usr_dir) create_dir(usr_input_img_dir) create_dir(usr_transfer_img_dir) create_dir(usr_output_img_dir) # save original image it its own directory usr_input_img = usr_img_dir + '/input' + '/' + file_name file_paths.append(usr_input_img) saveImg(img, usr_input_img) filenames.append(file_name) else: usr_transfer_img = usr_transfer_img_dir = usr_img_dir + '/transfer' + '/' + file_name file_paths.append(usr_transfer_img) saveImg(img, usr_transfer_img) filenames.append(file_name) counter += 1 # outside the for loop, compare two folders # compareFolders(usr_input_img_dir, usr_transfer_img_dir) start_time = time.clock() print("this is before seg model") print("this is file_paths", file_paths) output_name = filenames[0].rsplit( '.', 1)[0] + '_' + filenames[1].rsplit('.', 1)[0] + '.png' st = styleModule.Style_Transfer(usr_input_img, usr_transfer_img, usr_output_img_dir, output_name) cache = st.process() end_time = time.clock() - start_time headers = {'Content-type': 'application/json'} params = { 'output_image': cache['output'], 'plot_image': cache['plot'], 'input_image': usr_input_img, 'transfer_image': usr_transfer_img, 'time_required': end_time, 'time_uploaded': time_uploaded, 'email': email } print("this is params", params) r = requests.post(url9, json=params, headers=headers) link = r.content.decode("utf-8") print(r.status_code) print('this is response', r) print("this is content", link) send_email(email, link) else: add.apply_async(countdown=120)
def test_send_email(self): properties = load_test_properties() logger = utils.config_logger(properties=properties) result = utils.send_email(properties=properties, logger=logger) self.assertEqual(result, ResultStatus.success.value)