#Fun with web scraping and text to speech
Recently I discovered the OSX say
command. This command is pretty funny to play around with.
Open up a terminal and type the following command:
say "I cant let you do that dave"
This is fun to play with but let's see if we can make it into something useful aswell. I'm also interested in the aussie shares market (www.asx.com.au) so let's see if we can make it read out something useful like the latest breaking news for some shares that we are interested in. ASX provides a way to search for company announcements at various timeframes here: http://www.asx.com.au/asx/statistics/announcements.do For example, Here's a search for BHP for the whole of 2013: http://www.asx.com.au/asx/statistics/announcements.do?by=asxCode&asxCode=bhp&timeframe=Y&year=2013
We can use python and the BeautifulSoup library to scrape the results from this page.
import os
import urllib2
from bs4 import BeautifulSoup
symbol = 'bhp'
soup = BeautifulSoup(urllib2.urlopen('http://www.asx.com.au/asx/statistics/announcements.do?by=asxCode&asxCode=' + symbol + '&timeframe=Y&year=2013').read())
table = soup.table
if table is not None:
for row in table.findAll('tr'):
cols = row.findAll('td')
if len(cols) > 0:
os.system('say ' + symbol + '. ' + cols[2].string)
After running the above code you should hear osx speak out all the headlines for BHP for the year 2013. This is pretty fun but very quickly gets annoying as there's a bit too much information overload. A much better behaviour would be if it only read out the latest news items as they became available on the market. Also bhp is not the only company on the asx so it'd be great if you could pass in a list of companies you want to hear about. I've already written the code for this and you can find it on github: www.github.com/AshyIsMe/asxnewsreader (This one also supports linux and windows so long as you install espeak: http://espeak.sourceforge.net/)