Skip to content

Instantly share code, notes, and snippets.

@vlazzle
Created October 9, 2010 00:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vlazzle/617753 to your computer and use it in GitHub Desktop.
Save vlazzle/617753 to your computer and use it in GitHub Desktop.
from urllib import urlopen
from xml.dom import minidom
import re
REGIONAL_REPORT_FEED = 'http://www.surfline.com/rss/region.cfm?id=2958'
GOOD_WORDS = re.compile(r'good|epic|solid|fun', re.IGNORECASE)
HEIGHTS = re.compile(r'\d+')
GOOD_HEIGHT = 4
def is_of_interest(title):
location, report = title.split(':', 1)
return good_qualitative(report) or good_quantitative(report)
def good_qualitative(report):
return GOOD_WORDS.search(report) is not None
def good_quantitative(report):
for height in HEIGHTS.findall(report):
if int(height) >= GOOD_HEIGHT:
return True
return False
def send_highlights(highlights):
# TODO send email or text message
print highlights
def main():
titles = []
doc = minidom.parse(urlopen(REGIONAL_REPORT_FEED))
for item_node in doc.getElementsByTagName('item'):
title_node = item_node.getElementsByTagName('title')[0]
titles.append(title_node.childNodes[0].nodeValue)
interesting_titles = "\n".join([t for t in titles if is_of_interest(t)])
send_highlights(interesting_titles)
if __name__ == '__main__':
main()
@sirpengi
Copy link

sirpengi commented Oct 9, 2010

filter(is_of_interest, titles) <==> [t for t in titles if is_of_interest(t)]

although list comprehensions are quite sexy

@vlazzle
Copy link
Author

vlazzle commented Oct 9, 2010

They are sexy, since they combine map and filter functionality. But I find multiple calls to map and filter more readable than nested list comprehensions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment