コード例 #1
0
def SendHtmlStatusMail():

    subject = "BucketList Website - Monitoring Report"
    endTime = str(datetime.datetime.now())

    # Create the body of the message (a plain-text and an HTML version).
    text = "Report Available only in HTML."

    html = """\
            <html>
              <head><font size = 5 color="blue"><b>BucketList - Service Monitoring</b></font></head>
                <body>
                  <p>
                    <font size = 4><b><u>Monitoring Interval</b></u></font><br><br>
                    <font size = 3>Start Time : <b>{startTime}</b></font><br>
                    <font size = 3>End Time   : <b>{endTime}</b></font><br>
                  </p>
                  <p>
                    <font size = 4><b><u>Monitoring Stats</b></u></font><br><br>
                    <font size = 3>Total GET Queries : <b>{tGET}</b></font><br>
                    <font size = 3>Successful GET Queries : <b>{sGET}</b></font><br>
                    <font size = 3>Failed GET Queries : <b>{fGET}</b></font><br><br>
                  </p>
                </body>
            </html>
            """.format(startTime=startTime,
                       endTime=endTime,
                       tGET=(successfulGET+failedGET),
                       sGET=successfulGET,
                       fGET=failedGET)

    sendmail.sendemail(subject, html, text)
コード例 #2
0
def register():
    if request.method == 'POST':
        name = request.form['uname']
        mail = request.form['mail']
        pwd = request.form['pwd']
        cpwd = request.form['confirmpwd']
        if not re.match(r'[^@]+@[^@]+\.[^@]+', mail):
            msg = 'Invalid email address !'
            return render_template('index.html', signupmsg=msg)
        if pwd != cpwd:
            msg = 'Please enter correct confirm password'
            return render_template('index.html', signupmsg=msg)
        # check account is exists or not
        cursor = mysql.connection.cursor()
        cursor.execute('SELECT * FROM customerdeatils WHERE email LIKE % s',
                       [mail])
        existing_user = cursor.fetchone()
        cursor.close()
        #exits
        if existing_user:
            msg = 'Account already exists please login.'
            return render_template('index.html', signupmsg=msg)
        # not exists
        # send mail
        sendemail(mail, 'Account_creation')
        cursor = mysql.connection.cursor()
        cursor.execute('INSERT INTO customerdeatils VALUES(null,% s,% s,% s)',
                       (name, mail, pwd))
        mysql.connection.commit()
        cursor.close()
        msg = 'Your registration successfully completed.'
    return render_template('index.html', signupmsg=msg)
コード例 #3
0
def SendHtmlUnavailableAlertMail():

    subject = "BucketList Website Unavailable"

    text = "BucketList Website GET API Failed - SITE UNAVAILABLE"

    html = """\
            <html>
              <head><b><font size = 5 color="black">BucketList Website Status: </font><font size = 5 color="red">UNAVAILABLE</font></b></head>
                <body>
                  <p>
                    <font size = 3>Downtime - Start Time: <b>{startTime}</b></font><br>
                  </p>
                </body>
            </html>
            """.format(startTime=alertTime)

    sendmail.sendemail(subject, html, text)
コード例 #4
0
def complaint():
    if request.method == 'POST':
        complaint_name = request.form['complaint_name']
        name = request.form['name']
        mail = request.form['email']
        against_person = request.form['against_person']
        date = request.form["date"]
        des = request.form['complaint_des']
        cursor = mysql.connection.cursor()
        if not name == session["username"] or not mail == session["mail"]:
            msg = "please don't change username and mail."
            return render_template('home.html', msg=msg)
        cursor.execute(
            "INSERT INTO complaints VALUES(NULL,% s,% s,% s,% s,% s,% s,% s)",
            (complaint_name, name, mail, against_person, des, date, '0'))
        mysql.connection.commit()
        cursor.close()
        sendemail(mail, 'complaint_creation')
        msg = 'Complaint registerd you check out complaints section.'
        return render_template('home.html', msg=msg)
コード例 #5
0
def checkWebList(weblist):
    for webrecord in weblist:  #Loop through each record in database
        pprint.pprint(webrecord)
        currWebHash = getCurrentWebsiteHash(
            webrecord['website'])  #Get the current websites latest hash code
        if currWebHash != webrecord['lasthashcode']:
            print('Website ' + webrecord['website'] +
                  ' has changed email to ' + webrecord['emailaddress'])
            #call the subroutine after find the hashcode has changed
            sendmail.sendemail(webrecord['emailaddress'], 'Website changed',
                               webrecord['website'] + ' changed')
            try:
                #If there is a change, print out the change, but also update the database so that next time
                #the message wont get triggered again
                dbCur.execute("update webcheckerdb set lasthashcode ='" +
                              str(currWebHash) + "' where id = '" +
                              str(webrecord['id']) + "'")
                dbConn.commit()
                print('Website hash updated for next time')
            except:
                print("error during update: " + str(traceback.format_exc()))
コード例 #6
0
def SendHtmlResumedAlertMail():

    currentTime = str(datetime.datetime.now())

    subject = "BucketList Website Healthy"

    text = "BucketList Website up & running"

    html = """\
            <html>
              <head><b><font size = 5 color="black">BucketList Website Status: </font><font size = 5 color="green">HEALTHY</font></b></head>
                <body>
                  <p>
                    <font size = 3>Downtime - Start Time: <b>{startTime}</b></font><br>
                    <font size = 3>Downtime - End Time: <b>{endTime}</b></font><br>
                  </p>
                </body>
            </html>
            """.format(startTime=alertTime, endTime=currentTime)

    sendmail.sendemail(subject, html, text)
コード例 #7
0
def google_signup_authorized():
    resp = google.authorized_response()
    if resp:
        session['google_token'] = (resp['access_token'], '')
        # fetch client information
        p_json = json.dumps(google.get('userinfo').data)
        # extract json file
        ex_json = json.loads(p_json)
        # random 6 digit password creation
        password = randint(10**5, 10**6)

        name = ex_json['name']
        mail = ex_json['email']
        # check account is already register or not
        cursor = mysql.connection.cursor()
        cursor.execute('SELECT * FROM customerdeatils WHERE email LIKE % s',
                       [mail])
        existing_user = cursor.fetchone()
        cursor.close()
        # exists
        if existing_user:
            msg = 'Account already exists please login.'
            return render_template('index.html', signupmsg=msg)
        # doesn't exist
        cursor = mysql.connection.cursor()
        cursor.execute('INSERT INTO customerdeatils VALUES(null,% s,% s,% s)',
                       (name, mail, password))
        mysql.connection.commit()
        cursor.close()
        # send mail
        sendemail(mail, 'Account_creation')
        msg = 'Your registration successfully completed. password is {} please go to login'.format(
            str(password))
        return render_template('index.html', signupmsg=msg)
    else:
        msg = "Invalid response from google please try again"
        return render_template('index.html', signupmsg=msg)
コード例 #8
0
plt.savefig(__file__ + ".png", dpi=800)

#code to access the database where all email addresses are stored
urlparse.uses_netloc.append("postgres")
url = urlparse.urlparse(os.environ["DATABASE_URL"])
dbConn = psycopg2.connect(database=url.path[1:],
                          user=url.username,
                          password=url.password,
                          host=url.hostname,
                          port=url.port)
dbCur = dbConn.cursor(cursor_factory=RealDictCursor)

#drafting the body of the email
body = ("Hi, \ncnlbot here bringing you today's list of flights from " +
        labels[0] + " to " + labels[-1] + ": \n\n" + str(flights) + "\n\n")

#extracting all email addresses from database
rows = []
try:
    dbCur.execute(
        "select * from flightforecastemailsdb")  #Get all records from database
    rows = dbCur.fetchall()
except:
    print("error during select: " + str(traceback.format_exc()))

#sending email to all addresses
for address in rows:
    pprint.pprint(address)
    sendmail.sendemail(address['emailaddress'], "Today's list of flights",
                       body)
コード例 #9
0
        totaltime = end - start
        listtime.append(totaltime)
        listbool.append("False")
        listans.append(Quiz.quiz)
        listquestions.append(Quiz.correct)
    iterable += 1

now = datetime.date.today()

subject = username + "'s quiz for " + str(now)
body = ""
# for i in listquestions:
#     for x in listtime:
#         for z in listbool:
for (i, x, z, m) in zip(listquestions, listtime, listbool, listans):
    body += f"{i}: input: {m}, in {x:0.2f} seconds, {z}.\n"

print(subject)
print(body)

sendemail(subject , body)

# sendemail(f"{username}'s quiz today:", finalans)

# EXPECTED OUTPUT
# subject: 'ddodo quix today'
# body: 
# "13*39: answer 3, in 18 seconds,  FALSE"
# "3+5: answer 8, in 2 seconds, TRUE"
# "5-2: answer 3, in 10 seconds TRUE"
# "this.correct : 2/3, total time: 30 seconds"
コード例 #10
0
def SendHtmlStatusMail():

    global statusStartTime
    global prevStatusStartTime
    global statsEndTime
    subject = "Alauda API - Monitoring Report"
    statusEndTime = str(datetime.datetime.now())
    ResetCounters()

    # Create the body of the message (a plain-text and an HTML version).
    text = "Report Available only in HTML."

    html = """\
            <html>
              <head><font size = 5 color="blue"><b>Alauda API Monitoring</b></font></head>
                <body>
                  <p>
                    <font size = 4><b><u>Monitoring Interval</b></u></font><br><br>
                    <font size = 3>Start Time : <b>{startTime}</b></font><br>
                    <font size = 3>End Time   : <b>{endTime}</b></font><br>
                  </p>
                  <p>
                    <font size = 4><b><u>Create Service API</b></u></font><br><br>
                    <font size = 3>Total : <b>{tCreate}</b></font><br>
                    <font size = 3>Success : <b>{sCreate}</b></font><br>
                    <font size = 3>Failure : <b>{fCreate}</b></font><br><br>
                    <font size = 3>Time Taken (Service state Running) : <b>{aCreateList}</b></font><br><br>
                    <font size = 3>Time Taken (Service endpoint up) : <b>{bCreateList}</b></font><br><br>                   
                  </p>
                  <p>
                    <font size = 4><b><u>Destroy Service API</b></u></font><br><br>
                    <font size = 3>Total : <b>{tDestroy}</b></font><br>
                    <font size = 3>Success : <b>{sDestroy}</b></font><br>
                    <font size = 3>Failure : <b>{fDestroy}</b></font><br><br>
                    <font size = 3>Time Taken (seconds) : <b>{aDestroyList}</b></font><br><br>
                  </p>
                  <p>
                    <font size = 4><b><u>Stop Service API</b></u></font><br><br>
                    <font size = 3>Total : <b>{tStop}</b></font><br>
                    <font size = 3>Success : <b>{sStop}</b></font><br>
                    <font size = 3>Failure : <b>{fStop}</b></font><br><br>
                    <font size = 3>Time Taken (seconds) : <b>{aStopList}</b></font><br><br>
                  </p>
                  <p>
                    <font size = 4><b><u>Start Service API</b></u></font><br><br>
                    <font size = 3>Total : <b>{tStart}</b></font><br>
                    <font size = 3>Success : <b>{sStart}</b></font><br>
                    <font size = 3>Failure : <b>{fStart}</b></font><br><br>
                    <font size = 3>Time Taken (seconds) : <b>{aStartList}</b></font><br><br>
                  </p>
                  <p>
                    <font size = 4><b><u>Update Service API</b></u></font><br><br>
                    <font size = 3>Total : <b>{tUpdate}</b></font><br>
                    <font size = 3>Success : <b>{sUpdate}</b></font><br>
                    <font size = 3>Failure : <b>{fUpdate}</b></font><br><br>
                    <font size = 3>Time Taken (seconds) : <b>{aUpdateList}</b></font><br><br>
                  </p>
                </body>
            </html>
            """.format(startTime=statusStartTime,
                       endTime=statusEndTime,
                       tCreate=prevCreateServiceCallCount,
                       sCreate=prevCreateServiceCallSuccess,
                       fCreate=prevCreateServiceCallFailure,
                       aCreateList=str(prevCreateServiceTimes),
                       bCreateList=str(prevEndpointUpTime),
                       tDestroy=prevDestroyServiceCallCount,
                       sDestroy=prevDestroyServiceCallSuccess,
                       fDestroy=prevDestroyServiceCallFailure,
                       aDestroyList=str(prevDestroyServiceTimes),
                       tStop=prevStopServiceCallCount,
                       sStop=prevStopServiceCallSuccess,
                       fStop=prevStopServiceCallFailure,
                       aStopList=str(prevStopServiceTimes),
                       tStart=prevStartServiceCallCount,
                       sStart=prevStartServiceCallSuccess,
                       fStart=prevStartServiceCallFailure,
                       aStartList=str(prevStartServiceTimes),
                       tUpdate=prevUpdateServiceCallCount,
                       sUpdate=prevUpdateServiceCallSuccess,
                       fUpdate=prevUpdateServiceCallFailure,
                       aUpdateList=str(prevUpdateServiceTimes))

    sendmail.sendemail(subject, html, text)
    prevStatusStartTime = statusStartTime
    statusStartTime = str(datetime.datetime.now())