Guest User

Untitled

a guest
Aug 2nd, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. from dotenv import *
  2. from sqlalchemy import *
  3. from sqlalchemy.sql import text as txt
  4. from sqlalchemy.pool import NullPool
  5. from PIL import Image
  6. import io
  7. import os
  8.  
  9.  
  10.  
  11.  
  12. class dataserver:
  13.  
  14. username = 'drgg'
  15. userpass = 'melica'
  16. host = '192.168.0.254'
  17. port = 1521
  18. database = 'prod'
  19.  
  20. def __init__(self):
  21. self.url = 'oracle+cx_oracle://{}:{}@{}:{}/{}'.format(self.username, self.userpass, self.host, self.port, self.database)
  22. self.engine = create_engine(self.url, poolclass=NullPool)
  23. self.conexion = self.engine.connect()
  24. self.metadata = MetaData(bind=self.engine)
  25. # self.metadata.reflect(bind=self.engine, schema='farma')
  26.  
  27. def select(self, sql,*args, **kwargs):
  28. return self.conexion.execute(sql, *args, **kwargs)
  29.  
  30. def gettable(self, tablename):
  31. return self.metadata.tables[tablename]
  32.  
  33. def select_many(self, sql, *args, **kwargs):
  34. return self.conexion.execute(txt(sql), *args, **kwargs)
  35.  
  36.  
  37. if __name__ == '__main__':
  38. sizes = [900,217,245,315,69]
  39. image_path = os.path.join(os.path.dirname(__file__),'imagenes')
  40. print image_path
  41. no_image = 0
  42. afectados = 0
  43. # os.path.makedirs(image_path, exist_ok=True)
  44. d = dataserver()
  45. datos = d.select_many('select PROD_CODIGO, IMAG_CODIGO, IMAG_OBJETO from IMAGENES where rownum < 10')
  46. print "Iniciando exportacion, aguarde...\r"
  47. for item in datos:
  48. for s in sizes:
  49. filename = "{0}_{1}x{1}.jpg".format(item.imag_codigo, s)
  50. # print filename
  51. if item.imag_objeto:
  52. image = Image.open(io.BytesIO(item.imag_objeto))
  53. image = image.resize((s,s), Image.ANTIALIAS)
  54. image.save(filename, "JPEG")
  55. afectados+=1
  56. else:
  57. no_image+=1
  58.  
  59. # image = Image.open(io.BytesIO(item.imag_codigo))
  60. #image.save(os.path.join(image_path, str(item.prod_codigo),'.jpg'))
  61. print "Fin de exportacion"
  62. print "{} afectado(s) {} no contienen imagenes".format(afectados, no_image)
Add Comment
Please, Sign In to add comment