Advertisement
Guest User

Untitled

a guest
Dec 4th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.33 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. #import packages into python
  4. import MySQLdb as db
  5. import PythonMagick
  6. import os
  7.  
  8. #create variable to connect to the server
  9. HOST = "foo"
  10. PORT = 3306
  11. USER = "bar"
  12. PASSWORD = "baz"
  13. DB = "bang"
  14.  
  15. #create variables for Python PythonMagick
  16. img = PythonMagick.Image()
  17. img.density("300")
  18.  
  19. counter = 0
  20.  
  21. #Attempt to connect to the database
  22. try:
  23.     connection = db.Connection(host=HOST, port=PORT,
  24.                                user=USER, passwd=PASSWORD, db=DB)
  25.  
  26.     dbhandler = connection.cursor()
  27.  
  28.     #run query to withdraw items from the table
  29.     dbhandler.execute("SELECT products.filename, type_names.type_name FROM products INNER JOIN type_names ON products.type_id = type_names.id")
  30.  
  31.     #store all of the items in results variable
  32.     result = dbhandler.fetchall()
  33.  
  34.     #use for look to look process each of the querie entries. Convert entries with
  35.     #pdf extensions to png or jpg
  36.     for item in result:
  37.  
  38.             #extract the filename from the database
  39.             fileN = item[counter]
  40.  
  41.             if fileN.startswith("http://"):
  42.               path = "/home/bar/website_files/"
  43.               full_path = os.path.join(path, fileN)
  44.               print full_path
  45.  
  46.             else:
  47.               print "URL: " + fileN
  48.  
  49. except Exception as e:
  50.     print (e)
  51.  
  52. finally:
  53.     connection.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement