RSS Feed Generator help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bhass
    New Member
    • Dec 2008
    • 11

    RSS Feed Generator help

    I'm trying to make a basic RSS feed generator. I'm still a newb and I really need help. My aim is to have the user input all their desired settings then create an XML file in the same directory with all of their RSS settings.

    First I'd like it to ask the user how many articles it wants to put in the RSS feed. So it can loop the adding articles bit that many times. Then after the user inputting all their desired options, for it to display, then save.

    So far I have this, which is absolute rubbish. It looks horrendous and I think it is...How can I go about doing what I actually want to do?

    Code:
    #!/usr/bin/env python
    print "Welcome please fill in these details about your websites feed:"
    name=raw_input("Name of Feed:")
    desc=raw_input("Description of Feed:")
    url=raw_input("Location of Website:")
    print "Your websites details have been temporarilly stored for this session, now fill in your articles details:"
    aname=raw_input("Name of Article to Syndicate:")
    adesc=raw_input("Description of Article to Syndicate:")
    aurl=raw_input("URL of Article:")
    print "Your article details have been filled in, please wait..."
    print "Your XML code for this Feed is:"
    print """<?xml version="1.0" encoding="ISO-8859-1" ?> \n
    <rss version="0.91">\n"""
    print """<channel>\n
    <title>"""
    print name
    print """</title> \n
    <link>"""
    print url
    print """</link>
    \n <description>"""
    print desc
    print """</description> \n
    <item><title>"""
    print aname
    print """</title">\n 
    <link>"""
    print aurl
    print """</link>\n <description>"""
    print adesc
    print """</description>\n
    </item>\n
    </channel>\n
    </rss>"""
  • micmast
    New Member
    • Mar 2008
    • 144

    #2
    you could export it to a file

    another option would be to add a front end to the program with QT, gtk or something.
    Last edited by micmast; Dec 23 '08, 10:46 AM. Reason: typos

    Comment

    • bhass
      New Member
      • Dec 2008
      • 11

      #3
      Originally posted by micmast
      you could export it to a file

      another option would be to add a front end to the program with QT, gtk or something.
      I'm quite stuck on actually how to get all the settings inside the XML tags and then make it a variable it so I can export it. How can I do it?

      Comment

      • micmast
        New Member
        • Mar 2008
        • 144

        #4
        you could do something like this

        [code=python]
        file = open("output.xm l","w");
        file.write("<?x ml version=\"1.0\" encoding=\"ISO-8859-1\" ?>")
        file.write("<rs s version=\"0.91\ ">\n<channel>\n <title>"+str(na me)+"</title>");
        ...
        [/code]

        Comment

        • bhass
          New Member
          • Dec 2008
          • 11

          #5
          Originally posted by micmast
          you could do something like this

          [code=python]
          file = open("output.xm l","w");
          file.write("<?x ml version=\"1.0\" encoding=\"ISO-8859-1\" ?>")
          file.write("<rs s version=\"0.91\ ">\n<channel>\n <title>"+str(na me)+"</title>");
          ...
          [/code]
          Thanks loads! :)
          I shall do

          Comment

          • bhass
            New Member
            • Dec 2008
            • 11

            #6
            One more question, is there a command that can delete the contents of a chosen file

            Comment

            • bvdet
              Recognized Expert Specialist
              • Oct 2006
              • 2851

              #7
              The following will effectively delete the contents of a disc file:
              [code=Python]>>> f = open(file_name, 'w')
              >>> f.close()[/code]

              Comment

              • bvdet
                Recognized Expert Specialist
                • Oct 2006
                • 2851

                #8
                You can compile a list of strings using string formatting and write them to file with one write statement. Example:
                [code=Python]f = open(file_name, 'w')

                outlist = ['<?xml version="1.0" encoding="ISO-8859-1" ?>', '<rss version="0.91"> ',]
                outlist.append( ' <channel>\n <title>%s</title>' % name)
                outlist.append( ' <link>%s</link>' % url)
                outlist.append( ' <description>%s </description>' % desc)
                outlist.append( ' <item>\n <title>%s</title>' % aname)
                outlist.append( ' <link>%s</link>' % aurl)
                outlist.append( ' <description>%s </description>' % adesc)
                outlist.append( ' </item>')
                outlist.append( ' </channel>')
                outlist.append( '</rss>')

                f.write('\n'.jo in(outlist))
                f.close()[/code]

                Comment

                • bhass
                  New Member
                  • Dec 2008
                  • 11

                  #9
                  Thanks! This has really helped me :)

                  Comment

                  • bvdet
                    Recognized Expert Specialist
                    • Oct 2006
                    • 2851

                    #10
                    You are welcome, bhass. Thanks to micmast for contributing.

                    -BV

                    Comment

                    Working...