How do I compile my Python program to a .jar with Jython?

How can I create an automated Python program to fix formatting in a HTML file every week?

  • I'm pretty new to programming. I have to generate a HTML file for a mailout of new products every week from a database in work. When I generate the mailout the formatting of it is all wrong and it I have to run through about 10 steps to fix it and it takes me about an hour to do. I can't change the formatting of the file before the software generates it (long story). Would it be possible to write some sort of C or Python program (or any sort of program) that I could copy the unedited HTML code into and it will fix it to the correct formatting but still have the new products? Basically I am just wondering how id write a simple program in C or Python that I could manually paste in the unedited HTML and the program would generate a file with the correct formatting. Thanks

  • Answer:

    These kinds of tasks are often time consuming to write, but worth it if you can be free of an unpleasant task. Python will serve you well here.  Read in the file that is produced from your database, and then scan through it in memory, making the changes that you would normally make yourself, then write it back out to a new file. Once this works, you can schedule your program to run after the first file is produced. If you are on some form of UNIX, the scheduler is called 'cron' as Matthew pointed out, on Windows it is the 'Task Schedluer', and on the Mac it's 'launchd'.

Sean Vikoren at Quora Visit the source

Was this solution helpful to you?

Other answers

Do not write this in C. My first option would be to try to make use of text-transforming tools (such as perl, sed, tr, awk). If the changes you need to make are complex then a second option would be to program a solution in Python (or Perl or another high-level language). If you're using Python *and* the source document is valid HTML (before your attempt to change it) then you could parse the source document with an HTML parser like http://www.crummy.com/software/BeautifulSoup/bs4/doc/, modify the document from Python, and then write out the modified version.

Jarmo Dee

This is what http://en.wikipedia.org/wiki/Cron jobs are for :D

Matthew Bradberry

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.