|
import urllib2 |
|
import prowl |
|
from BeautifulSoup import BeautifulSoup |
|
from random import choice |
|
import time |
|
import pdb |
|
|
|
|
|
user_agents = [ |
|
'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6 (.NET CLR 3.5.30729)', |
|
'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6', |
|
'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.6) Gecko/20091215 Ubuntu/9.10 (karmic) Firefox/3.5.6', |
|
'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.6) Gecko/20091215 Ubuntu/9.10 (karmic) Firefox/3.5.6', |
|
'Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 6.0; en-US)', |
|
'Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 6.0; en-US)', |
|
'Mozilla/4.0 (compatible; MSIE 6.01; Windows NT 6.0)', |
|
'Mozilla/4.0 (compatible; MSIE 6.01; Windows NT 6.0)', |
|
'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/532.5 (KHTML, like Gecko) Chrome/4.0.249.0 Safari/532.5' |
|
] |
|
shares = [ |
|
{'name': 'Vodacom', 'link':'011437/PriceData_VOD.htm'}, |
|
{'name': 'MTN','link':'001305/PriceData_MTN.htm'}, |
|
{'name': 'Anglo Gold','link':'000205/PriceData_ANG.htm'}, |
|
{'name': 'Naspers','link':'000065/PriceData_NPN.htm'}, |
|
] |
|
p = prowl.Prowl() |
|
|
|
for share in shares: |
|
url = 'http://moneyweb.profile.co.za/moneyweb/sharedata/data/' |
|
aheaders = { 'User-Agent' : choice(user_agents) } |
|
url = url + share['link'] |
|
request = urllib2.Request(url, headers=aheaders) |
|
response = urllib2.urlopen(request) |
|
|
|
s = BeautifulSoup(response.read()) |
|
|
|
last_price = s.contents[1].contents[3].contents[1].contents[3].contents[0].contents[0].contents[0] |
|
popen = s.contents[1].contents[3].contents[1].contents[7].contents[0].contents[0] |
|
high = s.contents[1].contents[3].contents[1].contents[7].contents[1].contents[0] |
|
low = s.contents[1].contents[3].contents[1].contents[7].contents[2].contents[0] |
|
volume = s.contents[1].contents[3].contents[1].contents[11].contents[1].contents[0] |
|
prev_close = s.contents[1].contents[3].contents[1].contents[11].contents[2].contents[0] |
|
|
|
message = 'last price: ' + last_price + ', Open: ' + popen + '\nhigh: ' + high + ', low: ' + low + '\nvolume: ' + volume + ',prev close:' + prev_close |
|
print message |
|
print "-"*10 |
|
p.post('Shares',share['name'], message) |
|
time.sleep(60) |