Scusate... mi è partito il messaggio senza allegato... eccolo...
2008/6/15 Zanon Samuele <[EMAIL PROTECTED]>:
> -MySQL
> -utf-8
> -in teoria si
> -In allegato trovato lo script....
>
> Come toverete nello script, che le stringhe di testo estratte dal database
> ho provato a fare un encode in utf-8 tramite il metodo .encode delle
> stringhe.
>
> provate a vedere se c'è un errore o qualcosa per poter sistemare la cosa...
> grazie mille
>
> Il 15 giugno 2008 20.45, Carlo C8E Miron <[EMAIL PROTECTED]> ha scritto:
>
> Ciao fratello!
>>
>> 2008/6/15 Alberto Berti <[EMAIL PROTECTED]>:
>> >>>>>> "Carlo" == Carlo C8E Miron <[EMAIL PROTECTED]> writes:
>> > Carlo> Mah, io mi inginocchierei sui ceci e proverei a
>> > Carlo> chiederglielo per favore...
>> > esagerato, pare che bastino una decina di offerte votive al dio
>> serpente...
>>
>> Potrebbe bastare, a patto che l'OP provveda anche le seguenti
>> informazioni, senza le quali anche Sua Mostruosita` FSM non potrebbe
>> aiutarlo:
>>
>> - che database usa;
>> - che encoding usa il db;
>> - se il contenuto del db corrisponde all'encoding di cui al punto
>> precedente;
>> - non che serva a questo punto, ma lo script promesso poteva anche
>> allegarlo ad una delle due mail, eh...
>>
>> Ramen,
>> (c)
>> --
>> Carlo C8E Miron
>> Open Source Solution Architect
>>
>> <http://www.linkedin.com/in/carlomiron>
>> <http://pycon.it/> <http://stacktrace.it/> <http://pydinner.org/>
>> _______________________________________________
>> Python mailing list
>> [email protected]
>> http://lists.python.it/mailman/listinfo/python
>>
>
>
>
> --
> Zanon Samuele
> mailto:[EMAIL PROTECTED]
>
--
Zanon Samuele
mailto:[EMAIL PROTECTED]
#!/usr/bin/env python
import os
import time
import random
import string
import MySQLdb
from reportlab.platypus import *
from reportlab.lib.styles import *
from reportlab.rl_config import defaultPageSize
from reportlab.lib.units import inch, cm
from reportlab.lib import colors
PAGE_HEIGHT = defaultPageSize[0]
PAGE_WIDTH = defaultPageSize[1]
StandardStyle = ParagraphStyle('Standard', None)
StandardStyle.fontName = 'Times-Roman'
StandardStyle.fontSize = 10
StandardStyle.textColor = colors.black
StandardStyle.spaceAfter = 5
StandardStyle.backColor = colors.whitesmoke
TitleStyle = ParagraphStyle('Title', StandardStyle)
TitleStyle.fontName = 'LettErrorRobot-Chrome'
TitleStyle.fontName = 'Times-Bold'
TitleStyle.fontSize = 24
TitleStyle.spaceAfter = 30
TitleStyle.align = "CENTER"
BoldStyle = ParagraphStyle('Bold', StandardStyle)
BoldStyle.fontName = 'Times-Bold'
def DefaultReportTableStyle(header_fontsize=10, cell_fontsize=8):
return TableStyle ([\
('FONTNAME', (0,0), (-1,0), "Times-Bold"),\
('FONTSIZE', (0,0), (-1,0), 10),\
('TEXTCOLOR', (0,0), (-1,0), colors.darkred),\
('BACKGROUND', (0,0), (-1,0), colors.lightyellow),\
('FONTNAME', (0,1), (-1,-1), "Times-Roman"),\
('FONTSIZE', (0,1), (-1,-1), 8),\
('TEXTCOLOR', (0,1), (-1,-1), colors.black),\
('ALIGN', (0,0), (-1,-1), "CENTER"),\
('VALIGN', (0,1), (0,-1), 'TOP'),\
('VALIGN', (0,0), (-1,0), 'BOTTOM'),\
('LEFTPADDING', (0,0), (-1,-1), 3),\
('RIGHTPADDING', (0,0), (-1,-1), 3),\
('TOPPADDING', (0,0), (-1,-1), 1),\
('BOTTOMPADDING', (0,0), (-1,-1), 1),\
('GRID', (0,0), (-1,-1), 0.5, colors.black)
])
class FirstPageTemplate(PageTemplate):
def __init__(self, id, pageSize=defaultPageSize):
self.pageWidth = pageSize[0]
self.pageHeight = pageSize[1]
frame1 = Frame(inch, inch, self.pageWidth - 2*inch, self.pageHeight - 2*inch, id='FirstPage')
PageTemplate.__init__(self, id, [frame1])
def afterDrawPage(self, canvas, doc):
canvas.setAuthor("")
canvas.setTitle("")
canvas.setSubject("")
canvas.saveState()
#top line
canvas.setLineWidth(1)
#bottom line
canvas.setLineWidth(0.5)
canvas.line(inch, inch, doc.pagesize[0]-inch, inch)
canvas.setFont('Times-Roman', 8)
canvas.drawCentredString(PAGE_WIDTH / 2.0, inch*0.75, "- %d -" % doc.page)
canvas.drawRightString(PAGE_WIDTH - inch, inch*0.75, doc.report_timestamp)
#help line for punching
canvas.setLineWidth(0.3)
canvas.line(20, doc.pagesize[1] / 2, 25, doc.pagesize[1]/2)
canvas.restoreState()
class OtherPagesTemplate(PageTemplate):
def __init__(self, id, pageSize=defaultPageSize):
self.pageWidth = pageSize[0]
self.pageHeight = pageSize[1]
frame1 = Frame(inch, inch, self.pageWidth - 2*inch, self.pageHeight - 2*inch, id='OtherPages')
PageTemplate.__init__(self, id, [frame1])
def afterPageDraw(self, canvas, doc):
canvas.saveState()
#document title
canvas.setFont('Times-Bold', 12)
#current report title
canvas.setFont('Times-Bold', 8)
#top line
canvas.setLineWidth(1)
canvas.line(inch, inch, doc.pagesize[0]-inch, inch)
canvas.setFont('Times-Roman', 8)
canvas.drawCentredString(PAGE_WIDTH/2.0, inch*0.75, "- %d -" % doc.page)
canvas.drawRightString(PAGE_WIDTH - inch, inch*0.75, doc.report_timestamp)
#help line for punching
canvas.setLineWidth(0.3)
canvas.line(20, doc.pagesize[1] / 2, 25, doc.pagesize[1]/ 2)
canvas.restorestate()
class SipdamsDocTemplate(BaseDocTemplate):
def afterInit(self):
self.addPageTemplates(FirstPageTemplate('First', self.pagesize))
self.addPageTemplates(OtherPagesTemplate('Later', self.pagesize))
#Connessione al database
conn = MySQLdb.connect(host="localhost", user="root", passwd="t34ikiql", db="coro")
cursore = conn.cursor()
cursore.execute('SELECT * FROM contatti ORDER BY nome, cognome')
def main():
NOW = time.strftime("%d/%m/%y %H.%M.%S", time.localtime(time.time()))
output_filename = "Coristi.pdf"
doc = SipdamsDocTemplate(output_filename)
doc.report_timestamp = NOW
Report = []
p = Paragraph("Piccolo Coro di San Francesco", TitleStyle)
Report.append(p)
Report.append(NextPageTemplate('Later'))
d = []
d.append(["Nome", "Cognome", "Indirizzo", "Citta", "Cell", "Tel", "GG-MM di nascita", "E-mail"])
for record in cursore.fetchall():
str1 = record[1].encode('utf-8')
str2 = record[2].encode('utf-8')
str3 = record[3].encode('utf-8')
str4 = record[4].encode('utf-8')
str5 = record[5].encode('utf-8')
str6 = record[6].encode('utf-8')
str7 = record[7].encode('utf-8')
str8 = record[8].encode('utf-8')
str9 = record[9].encode('utf-8')
str10 = record[10].encode('utf-8')
str11 = record[11].encode('utf-8')
d.append([str1, str2, str3, str4, str5 + "." + str6, str7 + "." + str8, str9 + "-" + str10, str11])
tblstyle = DefaultReportTableStyle()
tblstyle.add('BACKGROUND', (0,0), (-1,0), colors.orange)
tbl = Table(d, colWidths=None, rowHeights=None, style=tblstyle, splitByRow=1, repeatRows=1, repeatCols=0)
tbl.hAlign = "CENTER"
Report.append(tbl)
print "Creazione Report"
doc.build(Report)
main()
_______________________________________________
Python mailing list
[email protected]
http://lists.python.it/mailman/listinfo/python