0% found this document useful (0 votes)
10 views3 pages

Aprial29 Py

Uploaded by

beherasuprabath
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views3 pages

Aprial29 Py

Uploaded by

beherasuprabath
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

#OTP generation using python --> random,time modules

import random
import time
#generate a random number
#b = random.randint(1000,9999)
#print(b) #it returns a single object for every execution
#we want to generate 5 random numbers at a time
#We wanted to understand how much time the program is taking for excution
'''start = time.time() #standard time as epoch time from 1970 Jan 1st
#print(start)
for i in range(5):
#print(b)
print(random.randint(1000,9999))
time.sleep(2) #sleep() will give a halt duration for given number of seconds
end = time.time()
#print(end-start) #this will generate the time taken for script execution
'''
#here we are sending an automated email using Python -->Gmail
#First we need to create Gmail App password -->Two Step Verification
#Google Account -->Click on Security tab -->Switch on 2-Step Verfctn
#Once 2step verifctn is done ->Search for App passwords in top search bar
#then create your new app password
#we use smtplib(simple mail transfer protocol)
import smtplib
#first we will connect to Gmail Server
'''server = smtplib.SMTP('smtp.gmail.com',587)
#print(server)
#start the server
server.starttls()
#we will login to the gmail (username,app pwd)
server.login('[email protected]','hoam vmae oqwy cthy')
#you give away your msg
msg = "Hey guys this is my first mail using Python hurraayyyyy"
#send the mail
server.sendmail('[email protected]',
'[email protected]',msg)
print("Message sent")

#Now let us link OTP Generation and Email Automation together to send otp to
#mail
import random,smtplib,math
#using random and math module to generate random number
#digits variable with all possible number
digits = "0123456789"
#now we will create an output OTP variable
OTP = ""
#usng floor() and random() functions let us generate otp
for i in range(6):
#we need to update OTP variable
OTP += digits[math.floor((random.random()*10))]
#print(OTP)
msg = "Your OTP is \t" + OTP + "use it careful"
#print(msg)
#now link your mail code
server = smtplib.SMTP('smtp.gmail.com',587)
server.starttls()
server.login('[email protected]','hoam vmae oqwy cthy')
#give sender and receiver mail ids
sender = "[email protected]"
rece = input("Enter the mail to send otp")
server.sendmail(sender,rece,msg)
#print("OTP sent")
a = input("Enter the OTP received")
if a == OTP:
print("OTP is success")
else:
print("Fail sarigaa chuduu")

#Task-1:create a function to send automated email with otp,where if otp is


#success
#make user play number game,if otp is failure user should calculate
#his/her BMI. --> [email protected]
'''
#time,datetime modules -->helps to get time,date,datetime along with time differnce
import time
#get current date and time using time module
'''b = time.localtime()
print(b)
#print(type(b))
#we want date only
d = b.tm_mday
m = b.tm_mon
y = b.tm_year
#print(f'Today is {d}-{m}-{y}')
h = b.tm_hour
m=b.tm_min
#print(f'Time is {h}:{m}')

#we can use ctime() in time module directly it returns string


q = time.ctime()
print(q)
print(type(q))'''

#datetime module -->date,time,datetime,timedelta --->strftime (String Formatting)

import datetime
#print(dir(datetime)) #returns all methods from module
#we want to get date object using datetime
from datetime import * #returns all functions from module internally
d = datetime.now() #returns datetime format
#print(d)
#print(type(d))
t = datetime.today()
#print(t)
#if we want only specific date
d = date(2024,6,27) #present,past,future any date
#print(d)
f = date.today()
#print(f)
#String Formatting -->converting datetime to string format
'''
%d -->day of the month,%b -->shortcut name for month,%B -->full name of mnth
%y -->two digit year,%Y -->four digit year,%a -->shortcut name for day of the
week %A -->full name for day of the week %j -->day number of the year
'''
d = f.strftime("The day is %A and we are in %B of %j day of year")
#print(d)
#Task-2 --> Take 3 inputs from user such as d,m,y -->convert to date format and
#give which month,what is the day of the week name,day number of the year and
#full 4 digit year

#timedelta() -->handles time difference


g = timedelta()
#print(g)
r = datetime(2024,4,29,12,20)
print(r)
h = timedelta(days=5,hours=2)
print(h)
print("The Future date will be",r+h)

#submit on [email protected] with subject as name,rollno,branch


#pip install opencv-contrib-python
#pip install imutils

You might also like