Thank you, Massimo,

After reading a lot more about feedparser and xlml,
I began going through xlml examples but figured that feedparser was already
doing most of what I needed, so I found this on stackoverflow,
http://stackoverflow.com/questions/11157894/less-painful-way-to-parse-a-rss-feed-with-lxml

and read more docs on feedparser entries.

and reading the html "view source" of the rss feed from rss_aggregator, I 
found that 'title' and 'summary' contained what I needed.

With feedparser selections, I can display the current weather from NOAA 
page. 

The only problem is that I don't understand how to reformat so uuencoded? 
details don't get left in the view. I've made attempts to translate or 
reformat or use helpers but so not getting the plain string that I want to 
view.

To get a current weather report from NOAA and display it, here is my 
solution.

1. http://w1.weather.gov/xml/current_obs/ Go here and select airport 
location closest
 to desired destination
2. select state Illinois, Find, Select Chicago Midway Airport, select RSS 
3. copy the feed uri path from the uri window,
 feed://w1.weather.gov/xml/current_obs/KMDW.rss
This will go into the feedparser.py function.

rename rss_aggregator() in feedparser.py to weatherfeed()

def weatherfeed():
    import datetime
    import gluon.contrib.rss2 as rss2
    import gluon.contrib.feedparser as feedparser
    # get the location closest to desired location first
    # and enter rss path below
    d = feedparser.parse('feed://w1.weather.gov/xml/current_obs/KMDW.rss')
    #this returns items but they are unicode values
    #wdict = d
    #print "wdict contains",wdict
    #print "wdict is type",type(wdict)
    #print "title",wdict['feed']['title']
    for entry in d['entries']:
      #print "feed title", d['feed']['title']
      #print "title type", type(d['feed']['title'])
      #print "bozo", d.bozo
      #print "headers" , d.headers.get('Content-type')
      strt_summary =  entry.get('summary', '')
      t_summary = str(strt_summary)
      strt_conditions = entry.get('title', '')
      t_conditions = str(strt_conditions)
      print "t_conditions", t_conditions
      #typesummary = type(t_summary)
      print "t_conditions", t_conditions
      #typesummary = type(t_summary)
    #return dict(t_conditions=t_conditions,t_summary=t_summary)
    return (t_conditions,t_summary)

I left in my commented print statements so other people trying it out can 
see contents of the lists and dictionaries.


For the default/index.html view

<h4> NOAA Weather Service</h4>
{{=LOAD('default','weatherfeed')}}
<!--{{=(XML(LOAD('default','weatherfeed')))}} has extra chars -->
<!--{{=(XML(unicode(LOAD('default','weatherfeed'))))}}  this has extra 
chars -->
{{pass}}
</h4>

This contains almost what I need but I can't figure out how to get the 
unicode or extra chars out. I could use "tr" or some regexp but is there a 
simpler way to do it with a helper?


thanks,
Margaret

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to