Skip to content

Instantly share code, notes, and snippets.

@dword4
Created February 9, 2015 05:50
Show Gist options
  • Save dword4/2f1c7c31553d349529b6 to your computer and use it in GitHub Desktop.
Save dword4/2f1c7c31553d349529b6 to your computer and use it in GitHub Desktop.
simple script to build URLs for the next few days
#!/usr/bin/python
import datetime
import calendar
day = datetime.date.today().strftime("%d")
month = datetime.date.today().strftime("%m")
year = datetime.date.today().strftime("%Y")
strip_month = datetime.date.today().strftime("%-m")
"""
day = datetime.date(2015,2,27).strftime("%d")
month = datetime.date(2015,2,27).strftime("%m")
year = datetime.date(2015,2,27).strftime("%Y")
strip_month = datetime.date(2015,2,27).strftime("%-m")
strip_month = datetime.date.today().strftime("%-m")
"""
num_days = calendar.monthrange(int(year),int(strip_month))[1]
future = int(day) + 4
if future <= num_days:
print "future date is still within this month"
next_days = []
for i in range(1,6):
if i == 1:
next_days.append('http://biz.yahoo.com/research/earncal/today.html')
else:
d = int(day) + i
next_days.append('http://biz.yahoo.com/research/earncal/'+str(year)+str(month)+str(d)+'.html')
if future > num_days:
next_days = []
print "looks like we overlap into the next month"
days_left = future - num_days
days_before = 5 - days_left
month_current = []
# first lets do the current month
for i in range(int(day), int(num_days)+1):
month_current.append(i)
# we need to remove the first item in this list, its going to be the today.html file
del(month_current[0])
# now to build the second list
month_next = []
for ii in range(1, int(days_left)+1):
month_next.append(ii)
# now its time to put the two lists together in a sensible way
# first the current month
next_days.append('http://biz.yahoo.com/research/earncal/today.html')
for item in month_current:
url = 'http://biz.yahoo.com/research/earncal/'+str(year)+str(month)+str(item)+'.html'
next_days.append(url)
for item2 in month_next:
test_month = int(month) + 1
if test_month < 10 and item2 < 10:
# we need to add a leading zero
next_month = int(month) + 1
url = 'http://biz.yahoo.com/research/earncal/'+str(year)+'0'+str(next_month)+'0'+str(item2)+'.html'
next_days.append(url)
if test_month > 10 and item2 < 10:
# only the day needs leading zeros
next_month = int(month) + 1
url = 'http://biz.yahoo.com/research/earncal/'+str(year)+str(next_month)+'0'+str(item2)+'.html'
next_days.append(url)
if test_month < 10 and item2 > 10:
# month needs leading zeros, days does not
next_month = int(month) + 1
url = 'http://biz.yahoo.com/research/earncal/'+str(year)+'0'+str(next_month)+str(item2)+'.html'
next_days.append(url)
print next_days
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment