Search code examples
pythonubuntucharacter-encodingcgifeedparser

Python/feedparser script won't display on CGI/ character coding


#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import os
import cgi
import string
import feedparser

count = 0
print "Content-Type: text/html\n\n"
print """<PRE><B>WORK MAINTENANCE/B></PRE>"""


d = feedparser.parse("http://www.hep.hr/ods/rss/radovi.aspx?dp=zagreb")


for opis in d:
    try:
          print """<B>Place/Time:</B> %s<br>""" % d.entries[count].title
          print """<B>Streets:</B> %s<br>""" % d.entries[count].description
          print """<B>Published:</B> %s<br>""" % d.entries[count].date
          print "<br>"
          count+= 1
    except:
        pass

I have a problem with CGI and paython script. Under the terminal script runs just fine except "IndexError: list index out of range", and I put pass for that. But when I run script through CGI I only get WORK MAINTENANCE line and first line from d.entries[count].title repeated 9 times? So confusing...

Also how can I setup support in feedparser for Croation(balkan) letters; č,ć,š,ž,đ ? # -- coding: utf-8 -- is not working and I m running Ubuntu server.

Thank you in advance for help.

Regards.


Solution

  • for opis in d:
        try:
              print """<B>Place/Time:</B> %s<br>""" % d.entries[count].title
    

    You're not using 'opis' in your output.

    Try something like this:

    for entry in d.entries:
        try:
            print """<B>Place/Time:</B> %s<br>""" % entry.title
            ....