Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
WeatherBot/testing.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
71 lines (54 sloc)
2.18 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import * | |
# https://docs.python.org/3/library/datetime.html#strftime-and-strptime-format-codes | |
# datetime documentation | |
def dateconversion(day): | |
if day == "monday": | |
day = 0 | |
elif day == 'tuesday': | |
day = 1 | |
elif day == 'wednesday': | |
day = 2 | |
elif day == 'thursday': | |
day = 3 | |
elif day == 'friday': | |
day = 4 | |
elif day == 'saturday': | |
day = 5 | |
elif day == 'sunday': | |
day = 6 | |
today = date.today()#Defines today | |
current = date.weekday(today) | |
count = 0 | |
while current != day: #figures out what day of the weak they are asking for and how many days that is in the future | |
current = current+1 | |
if current == 7: | |
current = 0 | |
count = count + 1 | |
daydate = int((datetime.strftime(date.today(), "%d"))) #gets day | |
month = int((datetime.strftime(date.today(), "%m"))) #gets month | |
year = int((datetime.strftime(date.today(), "%y"))) #gets year | |
realday = int(daydate) + count # adds on current day to what day user wants | |
months31 = [0,2,4,6,7,9,11] # list of months with 31 days | |
months30 = [3,5,8,10] # list of months with 30 days | |
check = year/4 #returns a value that could give a decimal | |
if check == int(year/4): #accounts for leap years hopefully | |
if month == 2: | |
if realday > 29: | |
realday = realday - 29 | |
month = month + 1 | |
if month in months30: #accounts for change of month | |
if realday > 30: | |
realday = realday - 30 | |
month = month + 1 | |
if month in months31: #accounts for change of month with 31 days | |
if realday > 31: | |
realday = realday - 30 | |
month = month + 1 | |
if month == 11: | |
year = year+1 | |
month = 1 | |
year = year + 2000 #converts year from last two digits to full year | |
dt = datetime(year, month, realday) # copied from https://www.tutorialspoint.com/How-to-convert-Python-date-to-Unix-timestamp#:~:text=You%20can%20use%20the%20datetime,epoch%20for%20that%20datetime%20object. | |
unixdate = dt.replace(tzinfo=timezone.utc).timestamp() | |
print(year, month, realday) | |
return(unixdate) # end of copy | |