tags:

views:

32

answers:

0

Hi all. So building on my question posted here http://stackoverflow.com/questions/3951716/using-python-to-write-to-html-file-with-mysql-data-as-source I have worked out how to do that although a bit different to the answers. Now my question is related to how to create html files from the data stored in MySQL, using the Category names from the database as parameters of the create_clouds function, to generate the html file name an add that categories data to it. Not sure if I have explained that very well and sorry for the crazy title. Not sure if any of this is clear enough.

Anyway here is my code so far. I no it is not great:

import MySQLdb 

db_connection = MySQLdb.connect(host='localhost', user='root', passwd='') 

cursor = db_connection.cursor()

cursor.execute('USE inb104')

def create_clouds(actors, movies, tv, sports, games, activities, musicians, books): 

# Need to use these category names from my database as parameters
# and get the data from each category using something like below     

    cursor.execute("SELECT Value FROM popularity WHERE Category = 'movies'")

    result = cursor.fetchall()

    convert = str(result)

    return convert


htmlFilenames = 'test.html' # Use parameters somehow to generate file names  

htmlFile = open(htmlFilenames, 'w') # Create files

htmlFile.write(create_clouds()) # Write to files. 

htmlFile.close()

As you can see I am pretty lost with this. I no it must be obvious but I just can't see it. Any help at all would be greatly appreciated.