I am trying to parse the title tag in an RSS 2.0 feed into three different variables for each entry in this feed. Using ElementTree, I already parsed RSS to print each heading [minus final]] using the code below:
feed = getfeed("http://www.tourfilter.com/dallas/rss/by_concert_date") for item in feed: print repr(item.title[0:-1])
I include this because, as you can see, item.title is the repr () data type that I know little about.
The specific repr(item.title[0:-1]) print ed in the interactive window looks like this:
'randy travis (Billy Bobs 3/21' 'Michael Schenker Group (House of Blues Dallas 3/26'
The user selects a group, and I hope, after parsing each item.title into 3 variables (one for the group, location and date ... or maybe an array or I donβt know ...) select only those that are related to selected group. Then they go to Google for geocoding, but that's a different story.
I have seen some regex examples and I read about them, but it seems very complicated. It? I thought maybe someone here would have an idea of ββhow to do this in a reasonable way. Should I use the re module? Does it matter that the output is currently repr() s? Is there a better way? I thought I would use such a loop (and this is my pseudo-python, just the notes I write):
list = bandRaw, venue, date, latLong
for item in feed:
parse item.title for bandRaw, venue, date
if bandRaw == str (band)
send venue name + ", Dallas, TX" to google for geocoding
return lat, long
list = list + return character + bandRaw + "," + venue + "," + date + "," + lat + "," + long
else
In the end, I need the selected entries in the .csv file (comma-delimited) to look like this:
band,venue,date,lat,long randy travis,Billy Bobs,3/21,1234.5678,1234.5678 Michael Schenker Group,House of Blues Dallas,3/26,4321.8765,4321.8765
Hope this is not too much to ask. I will study this on my own, just thought that I should publish here to make sure that it was answered.
So the question is, what is the best way to parse each repr(item.title[0:-1]) in feed into 3 separate values, which I can then merge into a CSV file?