Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    29
    Rep Power
    0

    Help with RSS feeds


    I get the error message:

    ##### here is the error message ##########
    File "qbo_rss_dev2.py", line 25, in <module>
    fo.write( feed.entries[1].description);
    IndexError: list index out of range

    When i try to make an RSS feed reader for my robot.

    My code is:

    #!/usr/bin/python
    import feedparser
    import subprocess
    import sys


    rss_url = "short-funny-jokes.com"
    feed = feedparser.parse( rss_url )
    posts = []
    #encoding="iso-8859-1"

    for i in range(1,len(feed['entries'])):
    posts.append({
    'title': feed['entries'][i].title,
    'description': feed['entries'][i].summary,
    'url': feed['entries'][i].link,
    'content': feed['entries'][i].link,
    })

    #print feed.entries[1].title
    # add a file to your directory and relist its path here
    fo = open("http://www.jokesareawesome.com/rss/random/", "wb")
    #fo.write( feed.entries[1].title);
    fo.write(" ")
    fo.write( feed.entries[1].description);
    fo.close()
    subprocess.call('echo ''|festival --tts qbo_rss.txt', shell=True)
    subprocess.call('python qbo_rss_dev2.py', shell=True)


    **Note: I have tried 20 different feeds and they all do the same thing.

    Any body know what is going on? I am retired and just playing with Python and my robot. I wish for it to do RSS feeds and say the joke, etc.
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,711
    Rep Power
    480
    In this loop (please observe the pretty and useful indentation)
    Code:
    for i in range(1,len(feed['entries'])):
        posts.append({
    	'title': feed['entries'][i].title,
    	'description': feed['entries'][i].summary,
    	'url': feed['entries'][i].link,
    	'content': feed['entries'][i].link,
    	})
    the data is stored into a list object named posts. Never again in your program do you use posts!

    Interesting, but possibly irrelevant. I don't have the feedparser module to work with. Maybe later I'll look for it. I expected to see a read function call, like
    feed.read()
    but again, it depends quite a bit on the code of feedparser.
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    29
    Rep Power
    0

    Help with RSS feeds


    yeh, I am not a very good programmer right now. I am going forward slowly.

    I thank you for any help given. i will think about what you said.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    29
    Rep Power
    0

    Help with RSS feeds


    Oh, I wanted to say that it IS formatted with indentions in the program. Just when I cut and pasted it, it lost it's format.
  8. #5
  9. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,711
    Rep Power
    480
    A smart person like you would observe my signature and follow the useful instructions about code posts.
    [code]Code tags[/code] are essential for python code and Makefiles!
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    29
    Rep Power
    0
    Right. use the code posts to post code. sorry.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    29
    Rep Power
    0

    rss for jokes


    I had beat my head into the ground trying to figure this one out. I am going to post two programs. one of them works, the other does not. this is the one that does NOT work.

    Code:
    #!/usr/bin/python 
    import feedparser
    import subprocess
    
    
    rss_url = "http://www.jokesareawesome.com/rss/randomjoke"
    feed = feedparser.parse( rss_url )
    posts = []
    
    for i in range(0,len(feed['entries'])):
        posts.append({
            'title': feed['entries'][i].title,
            'description': feed['entries'][i].summary,
            'url': feed['entries'][i].link,
        })
    
    print feed.entries[1].title
    # add a file to your directory and relist its path here
    fo = open("/home/qbobot/Documents/qbo_rss.txt", "wb")
    fo.write( feed.entries[1].title);
    fo.write("    ")
    fo.write( feed.entries[1].description);
    fo.close()
    subprocess.call('echo ''|festival --tts qbo_rss.txt', shell=True)
    This is the one that works for weather only. Not jokes. i am trying to get jokes.
    Code:
    #!/usr/bin/python 
    import feedparser
    import subprocess
    
    
    rss_url = "http://www.rssweather.com/zipcode/37138/rss.php"
    feed = feedparser.parse( rss_url )
    posts = []
    
    for i in range(0,len(feed['entries'])):
        posts.append({
            'title': feed['entries'][i].title,
            'description': feed['entries'][i].summary,
            'url': feed['entries'][i].link,
        })
    
    print feed.entries[1].title
    # add a file to your directory and relist its path here
    fo = open("/home/qbobot/Documents/qbo_rss.txt", "wb")
    fo.write( feed.entries[1].title);
    fo.write("    ")
    fo.write( feed.entries[1].description);
    fo.close()
    subprocess.call('echo ''|festival --tts qbo_rss.txt', shell=True)
    I get INDEX OUT OF RANGE error.

    Thanks in Advance for any help.

    Mel
  14. #8
  15. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,711
    Rep Power
    480
    Please give some help here. Make it easy for people reading your posts.

    Which line gives the index error?

    Please tell us that the only difference between the two programs is the value of the rss_url .

    Your loop can be simplified to
    Code:
    for entry in feed['entries']:
        posts.append({
            'title': entry.title,
            'description': entry.summary,
            'url': entry.link,
        })
    Now look. In your program carefully looped from 0 to len(feed['entries']) . Then, on the line where your program fails you carelessly assume that an index [1] is available. Well it isn't!

    I don't know what a site with and RSS feed should look like. I do know that the two web pages have different characteristics. It should be obvious which is weather and which the jokes.
    Code:
    http://www.rssweather.com/zipcode/37138/wx.php?utm_source=rss&utm_medium=rssThe weather information for this RSS feed is taken from the National Weather Service (http://weather.noaa.gov/), and powered by HamWeather (http://www.hamweather.com/).
    Using the Feeds
    
    Request Frequency - The feeds are updated once per hour. More frequent requests may result in your access being limited.
    Web Site Usage - If you are using the feed on your web site, you are required to maintain a link to rssWeather.com and hamweather.com
    ]]>60HamWeather (http://www.hamweather.com/)enhttp://www.rssweather.com/zipcode/37138/wx.php?utm_source=rss&utm_medium=rssCurrent ConditionsWed, 16 Oct 2013 20:53:00 -050069F OVERCASTOVERCASTOVERCAST 69F Humidity:68% Wind Speed:9 MPH Wind Direction:S (180) Barometer: 30.02 in. Dewpoint:58F Heat Index:69F Wind Chill:69F Visibility:10 mi]]>C-2053 CDT TUE OCT 15 2013Weather Forecasthttp://www.rssweather.com/zipcode/37138/wx.php?utm_source=rss&utm_medium=rssCloudy. Showers. Mainly after midnight. Lows in the lower 60s. Light south winds. Chance of rain 80 percent. Tue, 15 Oct 2013 19:33:00 -0500F-KBNA-733 PM CDT TUE OCT 15 2013-REST OF TONIGHTWeather Forecasthttp://www.rssweather.com/zipcode/37138/wx.php?utm_source=rss&utm_medium=rssCloudy. Showers in the morning. Then a chance of showers in the afternoon. Highs in the mid 60s. Light west winds becoming northwest around 5 mph in the afternoon. Chance of rain 80 percent. Tue, 15 Oct 2013 19:33:00 -0500F-KBNA-733 PM CDT TUE OCT 15 2013-WEDNESDAYWeather Forecasthttp://www.rssweather.com/zipcode/37138/wx.php?utm_source=rss&utm_medium=rssCooler. Mostly cloudy with a chance of showers. Lows around 50. Light north winds. Chance of rain 40 percent. Tue, 15 Oct 2013 19:33:00 -0500F-KBNA-733 PM CDT TUE OCT 15 2013-WEDNESDAY NIGHTWeather Forecasthttp://www.rssweather.com/zipcode/37138/wx.php?utm_source=rss&utm_medium=rssMostly cloudy with a chance of showers. Highs in the mid 60s. Northwest winds 5 to 10 mph. Chance of rain 30 percent. Tue, 15 Oct 2013 19:33:00 -0500F-KBNA-733 PM CDT TUE OCT 15 2013-THURSDAYWeather Forecasthttp://www.rssweather.com/zipcode/37138/wx.php?utm_source=rss&utm_medium=rssPartly cloudy. Lows in the mid 40s. Light north winds. Tue, 15 Oct 2013 19:33:00 -0500F-KBNA-733 PM CDT TUE OCT 15 2013-THURSDAY NIGHTWeather Forecasthttp://www.rssweather.com/zipcode/37138/wx.php?utm_source=rss&utm_medium=rssPartly sunny. Highs around 70. Tue, 15 Oct 2013 19:33:00 -0500F-KBNA-733 PM CDT TUE OCT 15 2013-FRIDAY
    Code:
    Jokesareawesome.com
    home latest browse random top 100 browse tags search rss feeds sign up login
    Joke RSS feeds
    
    We offer many ways for you to syndicate our joke content. We currently have 3 RSS feeds and are planning on adding more.
    
    Random Joke - Random joke from our database
    Top Rated Jokes - A feed of our top rated jokes.
    Latest Jokes - The latest jokes added to our ever growing database
    You can use these feeds with any RSS Reader. I recommend SharperReader for windows and Vienna for OSX.
    
    A nata2.com project. copyight 2006. This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike2.5 License.
    Choose the right web site!
    [code]Code tags[/code] are essential for python code and Makefiles!
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    29
    Rep Power
    0

    Index Error.


    The line that it messed up on was:

    print feed.entries[1].title.

    sorry. I thought that it was probably obvious to you guys where it was. Bad thinking on my part. I will answer the rest after I get over my FLU.
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    29
    Rep Power
    0

    Hasn't Anyone done JOKES on RSS before


    It would seem that Somebody has encountered a program that did RSS jokes. I am not particular (although I prefer clean funny short jokes.)

    I just figured that with this many people someone had got the RSS thread to work for joke of the day or something. I have wracked my brain trying to figure it out and search the web for weeks. I just want my virtual assistant robot to have a sense of humor.

    I am no expert at Python. I am trying to learn. This was supposed to be the place. Is there another place that is more Elementary for me to learn python? I feel like my questions are irritating you.

    Thanks for the idea of not using an Index. But, it gave me an error message saying that it was waiting for an argument. But, your tip on my other question worked good.
  20. #11
  21. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,711
    Rep Power
    480
    Please show exactly how using an index in the for loop "it gave me an error message saying that it was waiting for an argument".

    Yes, I can run diff. I can (and this I did) use the emacs emerge-files command to compare the two versions. Why should we have to when you could just state the difference is only the URL?
    [code]Code tags[/code] are essential for python code and Makefiles!
  22. #12
  23. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    29
    Rep Power
    0
    I should have done that. I did not think to do that.
  24. #13
  25. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,711
    Rep Power
    480
    Please show exactly how using an index in the for loop "it gave me an error message saying that it was waiting for an argument".

    Reference the Today 09:12 AM post.
    [code]Code tags[/code] are essential for python code and Makefiles!
  26. #14
  27. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    29
    Rep Power
    0

    Here is my program


    Code:
    #!/usr/bin/python 
    import feedparser
    import subprocess
     
    rss_url = "http://www.jokesareawesome.com/rss/tagged/randomjoke"
    feed = feedparser.parse( rss_url )
    posts = []
     
    for entry in feed['entries']:
        posts.append({
            'title': entries.title,
            'description': entries.summary,
            'url': entries.link,
        })
     
    print feed.entries.title
    # add a file to your directory and relist its path here
    fo = open("/home/qbobot/Documents/qbo_rss.txt", "wb")
    fo.write( feed.entries.title);
    fo.write("    ")
    fo.write( feed.entries.description);
    fo.close()
    subprocess.call('echo ''|festival --tts qbo_rss.txt', shell=True)
  28. #15
  29. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    29
    Rep Power
    0

    Here are my error messages


    qbobot@qbopro-robot:~/Documents$ python jokes.py
    Traceback (most recent call last):
    File "jokes.py", line 16, in <module>
    print feed.entries.title
    AttributeError: 'list' object has no attribute 'title'
    qbobot@qbopro-robot:~/Documents$
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo