Skip to content

Instantly share code, notes, and snippets.

@guziy
Created January 5, 2012 03:38
Show Gist options
  • Save guziy/1563587 to your computer and use it in GitHub Desktop.
Save guziy/1563587 to your computer and use it in GitHub Desktop.
pdf using python
__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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment