Python html output (first attempt), several questions (code included)
<p>While I have been playing with python for a few months now (just a hobbyist), I know very little about web programming (a little html, zero javascript, etc).  That said, I have a current project that is making me look at web programming for the first time.  This led me to ask:</p>

<p><a href="http://stackoverflow.com/questions/731470/whats-easiest-way-to-get-python-script-output-on-the-web">http://stackoverflow.com/questions/731470/whats-easiest-way-to-get-python-script-output-on-the-web</a></p>

<p>Thx to the answers, I made some progress.  For now, I'm just using python and html.  I can't post my project code, so I wrote a small example using twitter search (pls see below).</p>

<p>My questions are:</p>

<p>(1) am I doing anything terribly stupid?  I feel like WebOutput() is clear but inefficient.  If I used javascript, I'm assuming I could write a html template file and then just update the data.  yes?  better way to do this?</p>

<p>(2) at what point would a framework be appropriate for an app like this?  overkill?</p>

<p>Sorry for the basic questions - but I don't want to spend too much time going down the wrong path.</p>

<pre><code>import simplejson, urllib, time

#query, results per page 
query = "swineflu"
rpp = 25
jsonURL = "http://search.twitter.com/search.json?q=" + query + "&amp;rpp=" + str(rpp)

#currently storing all search results, really only need most recent but want the data avail for other stuff
data = []

#iterate over search results
def SearchResults():
    jsonResults = simplejson.load(urllib.urlopen(jsonURL))
    for tweet in jsonResults["results"]:
     try:
      #terminal output
      feed = tweet["from_user"] + " | " + tweet["text"]
      print feed
      data.append(feed)
     except:
      print "exception??"

# writes latest tweets to file/web
def WebOutput():
    f = open("outw.html", "w")
    f.write("&lt;html&gt;\n")
    f.write("&lt;title&gt;python newb's twitter search&lt;/title&gt;\n")
    f.write("&lt;head&gt;&lt;meta http-equiv='refresh' content='60'&gt;&lt;/head&gt;\n")
    f.write("&lt;body&gt;\n")
    f.write("&lt;h1 style='font-size:150%'&gt;Python Newb's Twitter Search&lt;/h1&gt;")
    f.write("&lt;h2 style='font-size:125%'&gt;Searching Twitter for: " + query + "&lt;/h2&gt;\n")
    f.write("&lt;h2 style='font-size:125%'&gt;" + time.ctime() + " (updates every 60 seconds)&lt;/h2&gt;\n")

    for i in range(1,rpp):
     try:
      f.write("&lt;p style='font-size:90%'&gt;" + data[-i] + "&lt;/p&gt;\n")
     except:
      continue

    f.write("&lt;/body&gt;\n")
    f.write("&lt;/html&gt;\n")
    f.close()

while True:
    print ""
    print "\nSearching Twitter for: " + query + " | current date/time is: " + time.ctime()
    print ""
    SearchResults()
    WebOutput()
    time.sleep(60)
</code></pre>
