Skip to content

Instantly share code, notes, and snippets.

@oiva
Last active January 5, 2016 17:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oiva/344879e376f86d2ba000 to your computer and use it in GitHub Desktop.
Save oiva/344879e376f86d2ba000 to your computer and use it in GitHub Desktop.
Talonmiesvuorot taulukkoon
#!/usr/bin/python
from datetime import datetime, timedelta
houses = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J']
# start from house number x + 1
start_index = 2
num_houses = len(houses)
start_of_year = datetime(2015, 12, 28)
calendar_base = 'http://calendar-events.herokuapp.com/api/invite?summary=' +\
'Talonmiesvuoro&url=http%3A%2F%2Fhosmarinmaki.fi&tzid=Europe/Helsinki'
print "<table><tbody><tr><th>Talonmies</th><th>Viikko</th><th>Pvm</th>" +\
"<th>Lis&auml;&auml; kalenteriin</th></tr>"
for i in range(1, 28):
house = houses[(start_index + i - 1) % num_houses]
date1 = start_of_year + timedelta(days=(i - 1) * 14)
date2 = start_of_year + timedelta(days=i * 14 - 1)
date3 = date2 + timedelta(days=1) # for end time
# generate link to .ics
start = date1.strftime("%Y-%m-%dT%H:%M:%S")
end = date3.strftime("%Y-%m-%dT%H:%M:%S")
calendar_link = calendar_base + '&start=' + start + '&end=' + end
class_name = ''
if i % 2 == 1:
class_name = ' class="odd"'
start_week = date1.isocalendar()[1]
end_week = date2.isocalendar()[1]
print ("<tr%s>\n\t<td>%s</td>\n\t<td>%s-%s</td>\n\t<td>" +
"%s - %s</td>\n\t<td><a href='%s'>.ics</a></td>\n</tr>")\
% (class_name, house, start_week, end_week,
date1.strftime('%d.%m.'),
date2.strftime('%d.%m.'),
calendar_link)
# empty lines every 5 rows
if (i - 1) % 5 == 0 and i > 1:
print "<tr><td colspan='3'>&nbsp;</td></tr>"
print '</tbody></table>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment