Example #1
0
def write_to_ineffective_services_owners(services_info,
                                         fake_email_sending=False):
    for service in services_info:
        data_str = ''
        is_ineffective = False

        cpu_ratio = service[8]
        if cpu_ratio <= 0.75:
            is_ineffective = True
            cpu_quote = service[2]
            cpu_usage_list = service[4]
            cpu_required_quote = service[6]
            data_str += "Квота на использование CPU: {}, " \
               "фактическое использование во " \
               "времени {}. Рекомендуемая квота " \
               "соcтавляет {}.".format(
             cpu_quote, cpu_usage_list, cpu_required_quote
            )

        memory_ratio = service[9]
        memory_required_quote = service[7]
        if memory_ratio <= 0.75:
            is_ineffective = True
            memory_quote = service[3]
            memory_usage_list = service[5]
            data_str += "\nКвота на использование Memory: {}, " \
            "фактическое использование во " \
            "времени {}. Рекомендуемая квота " \
            "составляет {}.".format(
             memory_quote, memory_usage_list, memory_required_quote
            )

        if is_ineffective:
            service_name = service[0]
            msg = "Добрый день!\n\n" \
               "Меня зовут Максим. Я являюсь техническим менеджером" \
               " во внутреннем облаке Яндекса. В мои задачи входит оптимизация " \
               "процесса использования ресурсов сервисами в этом облаке.\n\n" \
               "Ваш сервис {} находится в рамках предоставляемых ему квот, " \
               "однако эти квоты слишком велики (они не используются " \
               "в полной мере). Такие выводы были сделаны в результате " \
               "анализа данных о работе сервиса.\n\n" \
               "Данные следующие:\n{}\n\n" \
               "Пожалуйста, оптимизируйте использование ресурсов сервиса " \
               "(например, масштабируйте его), чтобы текущие квоты были " \
               "сохранены. Произвести оптимизацию можно в течение трех рабочих" \
               " дней. По истечении трех дней, в случае, если оптимизация " \
               "не будет произведена, будут назначены новые, рекомендуемые " \
               "для работы сервиса, квоты (квоты будут ограничены).\n\n" \
               "Спасибо за внимание и понимание!\n" \
               "Хорошего дня!\n" \
               "С уважением, Максим.".format(service_name, data_str)

            email_handler = EmailHandler()

            owners = service[1]

            if not fake_email_sending:
                for owner in owners:
                    email_handler.send_email(owner, msg.encode('utf-8'))
Example #2
0
def reset_password():
    if request.method == 'GET':

        email = request.args.get("email")
        code = request.args.get("code")

        if email:
            eh = EmailHandler(email)
            code = eh.send_reset_link()
            udao = UserDAO()
            udao.update_password_reset_link(email, code)
        elif code:
            return render_template("resetpassword.html",
                                    signedIn = request.cookies.get("signedIn"),
                                    code = code)

        return render_template("resetpassword.html",
                                signedIn = request.cookies.get("signedIn"),
                                code = None)
    elif request.method == 'POST':
        password = request.form['pass']
        code = request.args.get("code")
        udao = UserDAO()
        ldao = LogDAO()
        success = udao.reset_password(code, password)

        if success:
            ldao.add_log(request, request.cookies.get("user"), ldao.REQUEST_PASSWORD_RESET, 1)
            return redirect("/?alert=Successfully changed password!|Password has been changed for the specified account, sign in with your new details|alert-suc")
        
        ldao.add_log(request, request.cookies.get("user"), ldao.REQUEST_PASSWORD_RESET, 1)
        return redirect("/?alert=Password change unsuccessful!|Some of the details you input must have been inccorect.|alert-fail")
Example #3
0
def interest_post():
	if session.get('logged_in') is None:
		return redirect(url_for('PetCare.login'))
	accountDao = AccountDao()
	postDao = PostDao()
	postOwnerId = postDao.add_interest(request.form['postId'], session['logged_in'].rstrip())
	if postOwnerId:
		postOwnerEmail = accountDao.get_account_email(postOwnerId)
		userEmail = accountDao.get_account_email(session['logged_in'].rstrip())
		EmailHandler.send_interest(postOwnerId, postOwnerEmail, session['logged_in'].rstrip(), userEmail)
	return redirect(url_for('PetCare.list_posts'))
Example #4
0
def register():
	if request.method == 'GET':
		return render_template('register.html', error=None)
	accountInfo = Entities.make_account_info(request)
	if not accountInfo:
		return render_template('register.html', error="Required Informaion Missing")
	accountDao = AccountDao()
	isNewAccount = accountDao.add_account(accountInfo)
	if not isNewAccount:
		return render_template('register.html', error="User Account Existed Already")
	EmailHandler.send_authentication(accountInfo['email'], accountInfo['id'], accountInfo['code'])
	return redirect(url_for('PetCare.login'))
Example #5
0
def match():
	if session.get('logged_in') is None:
		return redirect(url_for('PetCare.login'))
	accountDao = AccountDao()
	postId = accountDao.get_account_post(session['logged_in'].rstrip())
	if postId is not None:
		postDao = PostDao()
		if postDao.add_match(postId, request.form['userId']):
			careGiverEmail = accountDao.get_account_email(request.form['userId'])
			userEmail = accountDao.get_account_email(session['logged_in'].rstrip())
			EmailHandler.send_approval(careGiverEmail, postId, userEmail)
	return redirect(url_for('PetCare.profile', userId=request.form['userId']))
Example #6
0
    def setup(self):
        self.git_repo_dir = tempfile.mkdtemp()

        ## mock of tinys3.Connection
        self.mock_s3 = mock.Mock()

        ## mock of geopy.geocoders.OpenCage
        self.mock_geocoder = mock.Mock()

        ## mock of lib.git.Git
        self.mock_git = mock.Mock()
        self.mock_git.repo_path = self.git_repo_dir
        self.mock_git.lock = mock.MagicMock()

        self.handler = EmailHandler(self.mock_s3,
                                    "img/email",
                                    self.mock_geocoder,
                                    self.mock_git,
                                    commit_changes=True)
Example #7
0
def account_settings(user):
    if request.method == 'GET':
        udao = UserDAO()
        valid_key = udao.check_user_session_key(user, request.cookies.get("session_key"))

        if valid_key:
            alertParam = request.args.get("alert")
            alert = None

            if alertParam:
                alertData = urllib.parse.unquote(alertParam)
                alertData = alertData.split("|")
                alert = Alert(alertData[0], alertData[1], alertData[2])
            
            u = udao.get_user(user)

            if u.email_auth == 1 and u.can_edit_settings == 0 and not alertParam:
                eh = EmailHandler(u.email)
                code = eh.send_settings_code()
                if code:
                    udao.set_user_settings_code(u.id, code)

            return render_template("settings.html",
                                    signedIn = request.cookies.get("signedIn"),
                                    user = request.cookies.get("user"),
                                    alert = alert,
                                    userobj = u)
        else:
            return "Not Your Page to Edit"
    elif request.method == 'POST':
        inputted_code = request.form['email_auth']
        udao = UserDAO()
        actual_code = udao.get_user_settings_code(user)

        if inputted_code == actual_code:
            udao.allow_edit_settings(user)
            return redirect(f"/account/{user}/settings")
        return redirect(f"/account/{user}/settings?alert=Incorrect Code!|Try inputting the code again.|alert-fail")
Example #8
0
def sendEmail():
	c = CitiesHandler()
	cityTempDiffs = c.generateTempDiffs()
	eh = EmailHandler()
	eh.generateMessages(cityTempDiffs)
	eh.sendEmailHelper()
	def get_email(self, recipient, msgbody):
		eh = EmailHandler()
		return eh.sendEmail(recipient, msgbody)
Example #10
0
from EmailHandler import EmailHandler

if __name__ == '__main__':
    emls = EmailHandler("01", "2021-03-20 0:0:0")
    emls.getExercises()

Example #11
0

# eh, I threw this in here for the sake of having another performance metric -
# maybe we don't need it, or maybe I'll make a StatHandler class to hold it
def precision(y_true, y_pred):
    true_positives = K.sum(K.round(K.clip(y_true * y_pred, 0, 1)))
    predicted_positives = K.sum(K.round(K.clip(y_pred, 0, 1)))
    precision = true_positives / (predicted_positives + K.epsilon())
    return precision


# Basic initialization of some of the handlers...
now = datetime.now()
date_string = now.strftime('%Y-%m-%d_%H_%M')
dataHandler = DataHandler()
emailHandler = EmailHandler()
hardwareHandler = HardwareHandler()
timer = TimerModule()
mode = 'T2' # Flair, T1, T2, or T1c
# Creating the model on the CPU
with tf.device('/cpu:0'):
    input_img = shape=(dataHandler.n, dataHandler.n, 1)
    model = Sequential()
    model.add(Conv2D(150, (3, 3), input_shape=input_img, padding='same'))
    model.add(PReLU())
    model.add(Conv2D(125, (5, 5), padding='same'))
    model.add(PReLU())
    model.add(MaxPooling2D(pool_size=(2, 2)))
    model.add(Flatten())
    model.add(Dense(520))
    model.add(PReLU())
Example #12
0
class TestEmailHandler:
    FIXTURE_DIR = os.path.abspath(os.path.join(__file__,
                                               "../../test-fixtures"))

    def setup(self):
        self.git_repo_dir = tempfile.mkdtemp()

        ## mock of tinys3.Connection
        self.mock_s3 = mock.Mock()

        ## mock of geopy.geocoders.OpenCage
        self.mock_geocoder = mock.Mock()

        ## mock of lib.git.Git
        self.mock_git = mock.Mock()
        self.mock_git.repo_path = self.git_repo_dir
        self.mock_git.lock = mock.MagicMock()

        self.handler = EmailHandler(self.mock_s3,
                                    "img/email",
                                    self.mock_geocoder,
                                    self.mock_git,
                                    commit_changes=True)

    def teardown(self):
        shutil.rmtree(self.git_repo_dir)

    def test_parseMessage(self):
        self.mock_s3.list.return_value = []

        lat, lon = 42.347011111111115, -71.09632222222221
        location = geopy.location.Location("the park",
                                           geopy.location.Point(lat, lon, 0))
        self.mock_geocoder.reverse.return_value = location

        self.mock_s3.upload.return_value = None

        with gzip.open(os.path.join(self.FIXTURE_DIR, "photo-1.msg.gz"),
                       "r") as ifp:
            post_path = self.handler.process_stream(ifp)

        eq_(post_path, "2015-07-05-fenway-fireworks.md")
        post_fn = os.path.join(self.git_repo_dir, "_posts", "blog", post_path)

        self.mock_s3.list.assert_called_once_with(
            "img/email/2015-07-05-fenway-fireworks/IMG_5810.JPG")
        eq_(self.mock_s3.upload.call_args[0][0],
            "img/email/2015-07-05-fenway-fireworks/IMG_5810.JPG")
        eq_(self.mock_s3.upload.call_args[1]["content_type"], "image/jpeg")

        self.mock_git.clean_sweep.assert_called_once_with()
        self.mock_git.add_file.assert_called_once_with(post_fn)
        self.mock_git.commit.called_once_with(
            "Brian Lalor", "*****@*****.**",
            "Sun, 5 Jul 2015 07:28:43 -0400", "Fenway fireworks")
        self.mock_git.push.called_once_with()

        ## bet those float comparisons will bite me later!
        self.mock_geocoder.reverse.assert_called_once_with([lat, lon],
                                                           exactly_one=True)

        frontmatter, body = parse_post(post_fn)
        # {'author': '*****@*****.**',
        #  'categories': 'blog',
        #  'date': '2015-07-05T07:28:43-04:00',
        #  'images': [OrderedDict([('path', 'img/email/2015-07-05-fenway-fireworks/IMG_5810.JPG'), ('exif', OrderedDict([('cameraMake', 'Apple'), ('cameraModel', 'iPhone 6'), ('cameraSWVer', '8.4'), ('dateTimeOriginal', '2015-07-03T23:39:33'), ('lensModel', 'iPhone 6 back camera 4.15mm f/2.2'), ('location', OrderedDict([('latitude', 42.347011111111115), ('longitude', -71.09632222222221)]))]))])],
        #  'layout': 'post',
        #  'tags': ['photo'],
        #  'title': 'Fenway fireworks'}
        eq_(frontmatter["author"], "*****@*****.**")
        eq_(frontmatter["categories"], "blog")
        ok_("photo" in frontmatter["tags"])

        eq_(len(frontmatter["images"]), 1)
        img = frontmatter["images"][0]
        eq_(img["exif"]["location"]["latitude"], lat)
        eq_(img["exif"]["location"]["longitude"], lon)
        eq_(img["exif"]["location"]["name"], location.address)

    def test_parseMessagePreservingEmoji(self):
        msg = MIMEText(u"""Foo 👍🔫""".encode("utf-8"), "plain", "UTF-8")

        msg["Message-ID"] = "7351da42-12a8-41a1-9b60-25ee7b784720"
        msg["From"] = "Brian Lalor <*****@*****.**>"
        msg["To"] = "photos@localhost"
        msg["Subject"] = "just some text"
        msg["Date"] = formatdate(1436782211)

        post_path = self.handler.process_message(msg)

        eq_(post_path, "2015-07-13-just-some-text.md")
        post_fn = os.path.join(self.git_repo_dir, "_posts", "blog", post_path)

        _, body = parse_post(post_fn)
        eq_(body, u"\nFoo 👍🔫")

    def test_handleNoPhotos(self):
        msg = MIMEText("""Just a test; no photos.""")
        msg["Message-ID"] = "7351da42-12a8-41a1-9b60-25ee7b784720"
        msg["From"] = "Brian Lalor <*****@*****.**>"
        msg["To"] = "photos@localhost"
        msg["Subject"] = "just some text"
        msg["Date"] = formatdate(1436782211)

        post_path = self.handler.process_message(msg)

        eq_(post_path, "2015-07-13-just-some-text.md")
        post_fn = os.path.join(self.git_repo_dir, "_posts", "blog", post_path)

        ok_(not self.mock_s3.list.called)
        ok_(not self.mock_geocoder.reverse.called)

        frontmatter, body = parse_post(post_fn)
        # {'author': '*****@*****.**',
        #  'categories': 'blog',
        #  'date': '2015-07-05T07:28:43-04:00',
        #  'layout': 'post',
        #  'tags': ['photo'],
        #  'title': 'Fenway fireworks'}
        eq_(frontmatter["author"], "*****@*****.**")
        ok_("photo" not in frontmatter["tags"])
        ok_("images" not in frontmatter)

    def test_stripSignature(self):
        msg = MIMEText("""some text ramble ramble bla bla bla

-- 
Nobody
[email protected]
""")

        msg["Message-ID"] = "7351da42-12a8-41a1-9b60-25ee7b784720"
        msg["From"] = "Brian Lalor <*****@*****.**>"
        msg["To"] = "photos@localhost"
        msg["Subject"] = "just some text"
        msg["Date"] = formatdate(1436782211)

        post_path = self.handler.process_message(msg)

        eq_(post_path, "2015-07-13-just-some-text.md")
        post_fn = os.path.join(self.git_repo_dir, "_posts", "blog", post_path)

        _, body = parse_post(post_fn)
        ok_(body.startswith("\nsome text ramble ramble"))
        ok_("-- \nNobody\[email protected]" not in body, "found signature")

    def test_stripSignature2(self):
        msg = MIMEText("""some text ramble ramble bla bla bla

Sent from my iPhone""")

        msg["Message-ID"] = "7351da42-12a8-41a1-9b60-25ee7b784720"
        msg["From"] = "Brian Lalor <*****@*****.**>"
        msg["To"] = "photos@localhost"
        msg["Subject"] = "just some text"
        msg["Date"] = formatdate(1436782211)

        post_path = self.handler.process_message(msg)

        eq_(post_path, "2015-07-13-just-some-text.md")
        post_fn = os.path.join(self.git_repo_dir, "_posts", "blog", post_path)

        _, body = parse_post(post_fn)
        ok_(body.startswith("\nsome text ramble ramble"))
        ok_("Sent from my iPhone" not in body, "found signature")

    def test_addTagsFromMsg(self):
        msg = MIMEText("""tags: foo, baz bap
some text ramble ramble bla bla bla
""")

        msg["Message-ID"] = "7351da42-12a8-41a1-9b60-25ee7b784720"
        msg["From"] = "Brian Lalor <*****@*****.**>"
        msg["To"] = "photos@localhost"
        msg["Subject"] = "just some text"
        msg["Date"] = formatdate(1436782211)

        post_path = self.handler.process_message(msg)

        eq_(post_path, "2015-07-13-just-some-text.md")
        post_fn = os.path.join(self.git_repo_dir, "_posts", "blog", post_path)

        frontmatter, body = parse_post(post_fn)
        ok_("foo" in frontmatter["tags"])
        ok_("baz bap" in frontmatter["tags"])

        ok_(body.startswith("\nsome text ramble ramble"))

    def test_addTagsFromMsgUppercase(self):
        msg = MIMEText("""Tags: foo, baz bap""")

        msg["Message-ID"] = "7351da42-12a8-41a1-9b60-25ee7b784720"
        msg["From"] = "Brian Lalor <*****@*****.**>"
        msg["To"] = "photos@localhost"
        msg["Subject"] = "just some text"
        msg["Date"] = formatdate(1436782211)

        post_fn = os.path.join(self.git_repo_dir, "_posts", "blog",
                               self.handler.process_message(msg))

        frontmatter, body = parse_post(post_fn)
        ok_("foo" in frontmatter["tags"])
        ok_("baz bap" in frontmatter["tags"])

    def test_extractsGPSTimestamp(self):
        self.mock_s3.list.return_value = []
        self.mock_geocoder.reverse.return_value = None
        self.mock_s3.upload.return_value = None

        with gzip.open(os.path.join(self.FIXTURE_DIR, "photo-1.msg.gz"),
                       "r") as ifp:
            post_path = self.handler.process_stream(ifp)

        post_fn = os.path.join(self.git_repo_dir, "_posts", "blog", post_path)

        frontmatter, body = parse_post(post_fn)
        # {'author': '*****@*****.**',
        #  'categories': 'blog',
        #  'date': '2015-07-05T07:28:43-04:00',
        #  'images': [OrderedDict([('path', 'img/email/2015-07-05-fenway-fireworks/IMG_5810.JPG'), ('exif', OrderedDict([('cameraMake', 'Apple'), ('cameraModel', 'iPhone 6'), ('cameraSWVer', '8.4'), ('dateTimeOriginal', '2015-07-03T23:39:33'), ('lensModel', 'iPhone 6 back camera 4.15mm f/2.2'), ('location', OrderedDict([('latitude', 42.347011111111115), ('longitude', -71.09632222222221)]))]))])],
        #  'layout': 'post',
        #  'tags': ['photo'],
        #  'title': 'Fenway fireworks'}
        eq_(len(frontmatter["images"]), 1)
        img = frontmatter["images"][0]
        eq_(img["exif"]["dateTimeOriginal"], "2015-07-03T23:39:33")
        eq_(img["exif"]["dateTimeGps"], "2015-07-04T03:39:33+00:00")