123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- def crear_transcripcion(id):
-
- from connect import connection
- import sqlalchemy as db
- from flask import jsonify
-
-
- ###### headers
- headers={}
- headers.update({"1":"Codigo"})
- headers.update({"2":"Curso"})
- headers.update({"3":"Nota"})
- headers.update({"4":"Creditos"})
-
- ###### estudiante
-
- query = 'SELECT nombres, apellidos, email, fecha_nacimiento, direccion1, direccion2, ciudad, pais, zipcode,\
- telefono1, telefono2\
- FROM usuarios u, estudiantes m \
- WHERE u.id = '+id+ ' AND u.id = m.user_id'
- result_db = connection.execute(query).fetchall()
-
- q = result_db
- q = q[0]
-
- estudiante={}
- estudiante.update({"nombres":str(q[0])})
- estudiante.update({"apellidos":str(q[1])})
- estudiante.update({"email":str(q[2])})
- estudiante.update({"fecha_nacimiento":str(q[3])})
- estudiante.update({"direccion1":str(q[4])})
- estudiante.update({"direccion2":str(q[5])})
- estudiante.update({"ciudad":str(q[6])})
- estudiante.update({"pais":str(q[7])})
- estudiante.update({"zipcode":str(q[8])})
- estudiante.update({"telefono1":str(q[9])})
- estudiante.update({"telefono2":str(q[10])})
-
- ###### semestres
-
- q = result_db
- semestres={}
-
- semestre = ('1', '2', '3', '4', )
- clases = ('ingles', 'espa~Nol', 'arte', 'mate', )
- for num in semestre:
- cursos = {}
- for clase in clases:
- curso = {}
- curso.update({"codigo":'33'})
- curso.update({"Nota":'A'})
- curso.update({"Creditos":'3'})
- curso.update({"nombre":clase})
- cursos.update({clase:curso})
- semestres.update({"semestre "+num:cursos})
-
-
- result = {}
- result.update({"headers":headers})
- result.update({"estudiante":estudiante})
- result.update({"semestres":semestres})
-
- # print(result)
-
- #####################################################################
- #####################################################################
- #####################################################################
-
-
- # https://www.blog.pythonlibrary.org/2018/06/05/creating-pdfs-with-pyfpdf-and-python/
- from fpdf import FPDF, HTMLMixin
-
- class HTML2PDF(FPDF, HTMLMixin):
- pass
-
- html = '''<h1 align="center">PyFPDF HTML Demo</h1>
- <p>This is regular text</p>
- <p>You can also <b>bold</b>, <i>italicize</i> or <u>underline</u>
- '''
- pdf = HTML2PDF()
- pdf.add_page()
- pdf.write_html(html)
- # pdf.output('html2pdf.pdf')
-
- ##########
-
- # pdf = FPDF()
- # pdf.add_page()
- pdf.set_font("Arial", size=12)
- pdf.cell(200, 10, txt="Welcome to Python!", ln=1, align="C")
- pdf.cell(200, 10, txt="Welcome to Python!", ln=1, align="C")
- pdf.cell(200, 10, txt="Welcome to Python!", ln=1, align="C")
- pdf.rect(20, 20, 100, 50)
-
- ###########
- spacing=1
- data = [['First Name', 'Last Name', 'email', 'zip'],
- ['Mike', 'Driscoll', 'mike@somewhere.com', '55555'],
- ['John', 'Doe', 'jdoe@doe.com', '12345'],
- ['Nina', 'Ma', 'inane@where.com', '54321']
- ]
-
- # pdf = FPDF()
- pdf.set_font("Arial", size=12)
- # pdf.add_page()
-
- col_width = pdf.w / 4.5
- row_height = pdf.font_size
- for row in data:
- for item in row:
- pdf.cell(col_width, row_height*spacing,
- txt=item, border=1)
- pdf.ln(row_height*spacing)
-
-
- ###########
-
- pdf.output("simple_demo.pdf")
-
-
-
- #####################################################################
- #####################################################################
- #####################################################################
-
- return jsonify(result)
|