@sfusgsGeo-tweet my quake…@ayman • yahoo! researchhttp://en.wikipedia.org/wiki/File:San_francisco_1906_earthquake.jpg
Zync • Y! Messenger
FireEagle
FireEagle@ayman
http://bit.ly/statler
shake and rumble in 2GA
http://earthquake.usgs.gov/earthquakes/recenteqsus/Quakes/nc71336726.php
Click through maps…
A Want Ad
USGS lists every quake
http://earthquake.usgs.gov/earthquakes/catalogs/
http://earthquake.usgs.gov/earthquakes/catalogs/
Trust me, it is just XML
Yahoo! Search goes to YDN
Google Search goes to YDN
Bing goes to YDN
Using ElementTree
The flow was simpleCRON this::cUrl XML feed from USGSfind local quakesbit.ly the quake permalinkif not duplicaterecord this quaketweet this quake
def fetch_quakes():def fetch_quakes():api = bitly.Api(login=’ABCDEF', apikey=’12345678901234567890')rss = parse(urllib.urlopen(USGS_URL)).getroot()    quakes = []    for element in rss.findall('{%s}entry' % USGS_NS):        title = element.findtext('{%s}title' % USGS_NS)       if (title.find("San Francisco Bay") > -1):            point = element.findtext('{%s}point' % GEORSS_NS)            points = point.split(None, 1)            link = element.find('{%s}link' % USGS_NS)href = 'http://earthquakes.usgs.gov%s' % link.get('href')href = api.shorten(href)          if (is_duplicate(href) is False):f = open(‘urls.txt', 'a')f.write('%s\n' % href)f.close()                summary = element.findtext('{%s}summary' % USGS_NS)                summary = summary.split("<br>")[1]                summary = summary.replace(' at epicenter</p><p>', ' ')                summary = strip_tags(summary)quakes.append({'title': element.findtext('{%s}title' % USGS_NS),                               'link' : href,                               'updated' : element.findtext('{%s}updated' % USGS_NS),                               'long' : points[1],                               'lat' : points[0],                               'elev' : element.findtext('{%s}elev' % GEORSS_NS),                               'summary' : summary})    return quakes
def is_duplicate(url):def is_duplicate(url):    from subprocess import callif(os.path.exists(‘urls.txt') is False):        call(['/usr/bin/touch', ‘urls.txt'])r = call(['/bin/fgrep',url,              ‘urls.txt'])    if (r == 0):        return True    else:        return False
def send_tweet(t):def send_tweet(t):    import httplib2    username = ’ABCDEFG'    password = ’12345678901234567890'msg = ('%s %s %s' % (t['title'], t['link'], t['summary']))    http = httplib2.Http()http.add_credentials(username, password)    response = http.request(        "http://twitter.com/statuses/update.xml",        "POST",urllib.urlencode({"status": msg,                           "lat": t['lat'],                           "long": t['long']})    )SEE: http://code.google.com/p/httplib2/ps: you shouldn’t store your passwords like that…this is just an illustration
fin
Crunched
USGS on Open Gov’t
Open Questions?How can other local sources be disseminated?How can mass media be filtered so it can be consumed in a similar manner?Can we collect information around the news? For example, find all the tweets that relate to a particular quake.Thanks, @ayman.

SFUSGS

  • 1.
    @sfusgsGeo-tweet my quake…@ayman• yahoo! researchhttp://en.wikipedia.org/wiki/File:San_francisco_1906_earthquake.jpg
  • 2.
    Zync • Y!Messenger
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
    Trust me, itis just XML
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
    The flow wassimpleCRON this::cUrl XML feed from USGSfind local quakesbit.ly the quake permalinkif not duplicaterecord this quaketweet this quake
  • 19.
    def fetch_quakes():def fetch_quakes():api= bitly.Api(login=’ABCDEF', apikey=’12345678901234567890')rss = parse(urllib.urlopen(USGS_URL)).getroot() quakes = [] for element in rss.findall('{%s}entry' % USGS_NS): title = element.findtext('{%s}title' % USGS_NS) if (title.find("San Francisco Bay") > -1): point = element.findtext('{%s}point' % GEORSS_NS) points = point.split(None, 1) link = element.find('{%s}link' % USGS_NS)href = 'http://earthquakes.usgs.gov%s' % link.get('href')href = api.shorten(href) if (is_duplicate(href) is False):f = open(‘urls.txt', 'a')f.write('%s\n' % href)f.close() summary = element.findtext('{%s}summary' % USGS_NS) summary = summary.split("<br>")[1] summary = summary.replace(' at epicenter</p><p>', ' ') summary = strip_tags(summary)quakes.append({'title': element.findtext('{%s}title' % USGS_NS), 'link' : href, 'updated' : element.findtext('{%s}updated' % USGS_NS), 'long' : points[1], 'lat' : points[0], 'elev' : element.findtext('{%s}elev' % GEORSS_NS), 'summary' : summary}) return quakes
  • 20.
    def is_duplicate(url):def is_duplicate(url): from subprocess import callif(os.path.exists(‘urls.txt') is False): call(['/usr/bin/touch', ‘urls.txt'])r = call(['/bin/fgrep',url, ‘urls.txt']) if (r == 0): return True else: return False
  • 21.
    def send_tweet(t):def send_tweet(t): import httplib2 username = ’ABCDEFG' password = ’12345678901234567890'msg = ('%s %s %s' % (t['title'], t['link'], t['summary'])) http = httplib2.Http()http.add_credentials(username, password) response = http.request( "http://twitter.com/statuses/update.xml", "POST",urllib.urlencode({"status": msg, "lat": t['lat'], "long": t['long']}) )SEE: http://code.google.com/p/httplib2/ps: you shouldn’t store your passwords like that…this is just an illustration
  • 22.
  • 23.
  • 24.
  • 25.
    Open Questions?How canother local sources be disseminated?How can mass media be filtered so it can be consumed in a similar manner?Can we collect information around the news? For example, find all the tweets that relate to a particular quake.Thanks, @ayman.

Editor's Notes

  • #2 Use d to be you could look out the window…
  • #6 I’m from Y!R MESS IEG.
  • #10 Toms first quake.