Stand With Ukraine

Wednesday, May 19, 2010

Cleaning Timetable

So I moved to another apartment - multi 3, and we had to decide how to divide our cleaning responsibilities fair and square. For this purpose and for fun I have created a pdf file using python and reportlab(http://www.reportlab.com/) library. Here is the code:
__author__="san"
__date__ ="$18-May-2010 11:48:34 PM$"
from datetime import datetime
from reportlab.platypus import *
from reportlab.platypus.tables import *
from datetime import timedelta
from datetime import *
from reportlab.lib.styles import *
from reportlab.lib.units import *
def main(places):
doc = SimpleDocTemplate('gfe.pdf')
data = [
['P1','_____'],
['P2','_____'],
['P3','_____'],
]
elements = []
styles = getSampleStyleSheet()
end_date = datetime(year = 2010,month = 8, day = 15)
start_date = datetime(year = 2010,month = 5, day = 16)
d = start_date
dt = timedelta(days = 7)
week_number = 1
while d < end_date:
d += dt
insert_in_data(data, places)
cycle(places)
t = Table(data, rowHeights = 13.5)
t.setStyle(TableStyle([
('INNERGRID', (0,0), (-1,-1), 0.25, colors.black),
('BOX', (0,0), (-1,-1), 0.25, colors.black),
]))
elements.append(t)
p = Paragraph(d.strftime("%B %d ----") + '- end of week %d' % week_number, styles['Normal'] )
elements.append(p)
week_number += 1
doc.build(elements)
def insert_in_data(data, the_places):
for i, place in enumerate( the_places ):
if len(data[i]) > 2:
data[i].pop(1)
data[i].insert(1, place)
def cycle(the_list):
tail = the_list.pop()
the_list.insert(0,tail)
if __name__ == "__main__":
places = ['Salle de bain', 'Cuisine', 'Place de sejour']
main(places)
print "Hello World"
view raw pdf_python.py hosted with ❤ by GitHub

So like this we will change the place and of course after the end of the week all the blanks should be checked)).And the screenshot of the result: