Created
October 9, 2010 00:32
-
-
Save vlazzle/617753 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
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
filter(is_of_interest, titles) <==> [t for t in titles if is_of_interest(t)]
although list comprehensions are quite sexy