codekasten/WKNcharts/getWKNcharts.py

66 lines
1.6 KiB
Python
Raw Normal View History

2006-06-07 11:03:58 +02:00
#!/usr/bin/env python
__version__ = "0.2b"
__author__ = "age"
__date__ = "02006-04-25"
import urllib
from optparse import OptionParser
class WKNCharts:
'''fetches images from stocks'''
def __init__(self):
self.wkn_dict = {}
def readwkndictfromfile(self, filename):
'''reads lines like "wkn name\n" from a file and fills a dictionary'''
wknfile = open(filename,"r")
for line in wknfile:
'remove CRLF and split the line in two parts on spacer'
tmp = line.strip("\n").split(" ")
if tmp[0] and tmp[1]: self.wkn_dict[tmp[0]] = tmp[1]
wknfile.close()
def getchart(self, wkn):
'''fetches the images via http'''
host = "http://gfx.finanztreff.de/charts/cc_gatrixx.gfx?"
params = urllib.urlencode({
'string':wkn,
'b':400,
'h':240,
'out':"png",
'zeit':300,
'typ':0,
'boerse':1,
'land':276,
'seite':"kurse",
'herkunft':123
})
print "ich hole jetzt \"%s\":" % self.wkn_dict[wkn]
print host + params
try:
f = urllib.urlopen(host + params)
png = open(self.wkn_dict[wkn]+".png", "w")
png.write(f.read())
png.close()
except IOError, e:
print e
def getallcharts(self):
for wkn in self.wkn_dict.keys():
self.getchart(wkn)
if __name__ == "__main__":
parser = OptionParser()
parser.add_option("-f", "--file", dest="filename",
help="read WKNS from FILE", metavar="FILE")
(options, args) = parser.parse_args()
wkn = WKNCharts()
wkn.readwkndictfromfile(options.filename)
#for i in wkn.wkn_dict.keys():
#print "%s \t %s" % (i, wkn.wkn_dict[i])
wkn.getallcharts()
#wkn.addwkn(wkn, name)
#wkn.delwkn(wkn)