Passion/Programming

오늘의 나의 펀드 가격

sunshout 2007. 3. 31. 01:33
from BeautifulSoup import BeautifulSoup
import urllib

MYCODE = 'KR5206655114'
MYCOUNT = 1000
URL = 'http://bank.naver.com/fund/fund_detail.nhn?fund_cd=%(fundcode)s'


def iterfunds(code):
    f = urllib.urlopen(URL % {'fundcode': code})
    soup = BeautifulSoup(f)
    for inc in soup('td', {'class': 'pd03_num'}):
        current_price = inc.contents[0]
    return current_price

def getAsset(mycount,mycode):
    cv = iterfunds(mycode)
    print "Current value : " + cv
    print "My asset      : " + str(mycount * float(cv))

if __name__ == '__main__':
    print getAsset(MYCOUNT,MYCODE)