Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- #import packages into python
- import MySQLdb as db
- import PythonMagick
- import os
- #create variable to connect to the server
- HOST = "foo"
- PORT = 3306
- USER = "bar"
- PASSWORD = "baz"
- DB = "bang"
- #create variables for Python PythonMagick
- img = PythonMagick.Image()
- img.density("300")
- counter = 0
- #Attempt to connect to the database
- try:
- connection = db.Connection(host=HOST, port=PORT,
- user=USER, passwd=PASSWORD, db=DB)
- dbhandler = connection.cursor()
- #run query to withdraw items from the table
- dbhandler.execute("SELECT products.filename, type_names.type_name FROM products INNER JOIN type_names ON products.type_id = type_names.id")
- #store all of the items in results variable
- result = dbhandler.fetchall()
- #use for look to look process each of the querie entries. Convert entries with
- #pdf extensions to png or jpg
- for item in result:
- #extract the filename from the database
- fileN = item[counter]
- if fileN.startswith("http://"):
- path = "/home/bar/website_files/"
- full_path = os.path.join(path, fileN)
- print full_path
- else:
- print "URL: " + fileN
- except Exception as e:
- print (e)
- finally:
- connection.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement