From my other post I am making a simple program that creates an RSS feed with Python. Now when I run my program so far, I get errors. It says "something is not defined". The word something is replaced by the name of the function I'm trying to use. my article function when ran, comes up with "article is not defined" etc.
Here's my code: What is wrong with it?
Here's my code: What is wrong with it?
Code:
#!/usr/bin/env python import ftplib import getpass def mainfeed(): name=raw_input("Name of Feed: ") desc=raw_input("Description of Feed: ") url=raw_input("Location of Website: ") again() def again(): again=raw_input("Would you like to add an article to the feed? Y/N: ") if again == "Y": article() elif again =="N": writeb() else: print again + """is not a valid option. You must select either 'Y' or 'N'""" fail() def fail(): again() def article(): aname=raw_input("Name of Article: ") adesc=raw_input("Description of Article: ") aurl=raw_input("Location of Article: ") finish() def finish(): print "Saving parameters to rss-feed.xml...please wait..." print "Finished" writea() def writea(): file_name = "rss-feed.xml" 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'.join(outlist)) f.close() ftpqe() def writeb(): file_name = "rss-feed.xml" 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(' </channel>') outlist.append('</rss>') f.write('\n'.join(outlist)) f.close() ftpqe() def ftpqe(): ftpq=raw_input("Do you want to upload your XML file to your website via FTP? Y/N: ") if ftpq == "Y": ftp() elif ftpq =="N": end() else: print again + """is not a valid option. You must select either 'Y' or 'N'""" fail2() def fail2(): ftpqe() def ftp(): server=raw_input("Server name: ") login=raw_input("Enter your login: ") password = getpass.unix_getpass("Enter your password: ") ftplib.FTP(server,login,password) f = open('rss-feed.xml','rb') s.storbinary('STOR rss-feed.xml', f) f.close() s.quit() print "Your file has been uploaded" end() def end(): print "Thank you" mainfeed()
Comment