Untitled
unknown
python
3 years ago
4.0 kB
8
Indexable
import ezgmail
import os
import datetime
from datetime import date
from datetime import datetime
from datetime import timedelta
import time
import weathertesting4email
import calendar
import math
today = datetime.now()
yesterday = today - timedelta(days=1)
tomorrow = today + timedelta(days=1)
year = today.year
month = today.month
day = today.day
hour = today.hour
minute = today.minute
second = today.second
unix = time.time()
currentdate = datetime.today()
monthname = currentdate.strftime("%B")
weekdayname = calendar.day_name[datetime.today().weekday()]
def ordinal(n):
if str(n)[-1] == '1':
return str(n) + 'st'
elif str(n)[-1] == '2':
return str(n) + 'nd'
elif str(n)[-1] == '3':
return str(n) + 'rd'
else:
return str(n) + 'th'
if day < 10:
day2 = "0{}".format(day)
else:
day2 = day
if hour < 10:
hour2 = "0{}".format(hour)
else:
hour2 = hour
if minute < 10:
minute2 = "0{}".format(minute)
else:
minute2 = minute
if second < 10:
second2 = "0{}".format(second)
else:
second2 = second
#print(year,month,day,hour,minute,second)
yeartom = tomorrow.year
monthtom = tomorrow.month
daytom = tomorrow.day
yearyest = yesterday.year
monthyest = yesterday.month
dayyest = yesterday.day
todayformatted = "{}/{}/{}".format(year,month,day)
yestformatted = "{}/{}/{}".format(yearyest,monthyest,dayyest)
tomformatted = "{}/{}/{}".format(yeartom,monthtom,daytom)
todayform2 = "{}-{}-{} {}:{}:{}".format(year,month,day2,hour2,minute2,second2)
#os.chdir('credentials.json')
#ezgmail.init()
#ezgmail.send(sender, recipient, subject, body, attachments=None, sender=None, cc=None, bcc=None, mimeSubtype='plain', _threadId=None)
recipient = 'email@email.com'
subject = "Weather: {}".format(todayformatted)
body = ("""
Quick Temps:
7 \t 8 \t 9 \t 10 \t 11 \t 12 \t 1 \t 2 \t 3
{} \t {} \t {} \t {} \t {} \t {} \t {} \t {} \t {} \t {}
---------------------------------------------
{}
-----------------
{}
-----------------
{}
-----------------
{}
-----------------
{}
-----------------
{}
-----------------
{}
-----------------
{}
-----------------
{}
-----------------
Other info:
It is {} the {} of {}, {}
UNIX TIMESTAMP {}
""".format(
weathertesting4email.name7temp,
weathertesting4email.name8temp,
weathertesting4email.name9temp,
weathertesting4email.name10temp,
weathertesting4email.name11temp,
weathertesting4email.name12temp,
weathertesting4email.name13temp,
weathertesting4email.name14temp,
weathertesting4email.name15temp,
weathertesting4email.body7,
weathertesting4email.body8,
weathertesting4email.body9,
weathertesting4email.body10,
weathertesting4email.body11,
weathertesting4email.body12,
weathertesting4email.body13,
weathertesting4email.body14,
weathertesting4email.body15,
weekdayname,
ordinal(day),
monthname,
year,
int(unix)))
cc = None
bcc = None
ezgmail.send(recipient,subject,body)
sentThreads = ezgmail.search("is:sent")
mailsent = sentThreads[0]
mailmessages = mailsent.messages
mailtimestamp = mailsent.messages[0].timestamp
#mailtimestamprl = datetime.fromtimestamp(mailtimestamp)
#print(sentThreads)
#print(mailsent)
#print(mailmessages)
print(mailtimestamp)
#print(todayform2)
mailtimestamp = str(mailtimestamp)
mailsecond = mailtimestamp[17:19]
if mailsecond == "00":
mailsecond = int(0)
else:
if mailsecond[0:1].find("0") != -1:
mailsecond2 = mailsecond[0:1]
mailsecond2 = int(mailsecond2)
else:
mailsecond = int(mailsecond)
#print(mailsecond)
#print(abs(second-mailsecond))
if abs(second-mailsecond) <= 10:
print("sent")
else:
print("no send")
#if ezgmail.send(recipient, subject, body) == True:
# print("yes")
#print(ezgmail.send(recipient, subject, body))
#def sendmail(recipient,subject,body,cc,bcc):
# ezgmail.send(recipient, subject, body, cc=cc, bcc=bcc)
# if
Editor is loading...