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 = {}
|
2006-06-09 09:20:21 +02:00
|
|
|
self.times = [300]
|
2006-06-07 11:03:58 +02:00
|
|
|
|
|
|
|
def readwkndictfromfile(self, filename):
|
|
|
|
'''reads lines like "wkn name\n" from a file and fills a dictionary'''
|
2006-06-14 01:13:52 +02:00
|
|
|
try:
|
|
|
|
wknfile = open(filename,"r")
|
|
|
|
except IOError, e:
|
|
|
|
print e
|
2006-06-07 11:03:58 +02:00
|
|
|
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()
|
2006-06-09 09:20:21 +02:00
|
|
|
|
|
|
|
def readwkndictfromstring(self, wknstring):
|
|
|
|
'''takes the given string into a "wkn name" dictionary'''
|
|
|
|
tmp2 = wknstring.splitlines()
|
|
|
|
print len(tmp2)
|
|
|
|
for i in tmp2:
|
|
|
|
tmp = i.split()
|
|
|
|
if tmp[0] and tmp[1]: self.wkn_dict[tmp[0]] = tmp[1]
|
2006-06-07 11:03:58 +02:00
|
|
|
|
2006-06-09 09:20:21 +02:00
|
|
|
def getchart(self, wkn, time, width=400, height=240):
|
2006-06-07 11:03:58 +02:00
|
|
|
'''fetches the images via http'''
|
|
|
|
host = "http://gfx.finanztreff.de/charts/cc_gatrixx.gfx?"
|
|
|
|
params = urllib.urlencode({
|
|
|
|
'string':wkn,
|
2006-06-09 09:20:21 +02:00
|
|
|
'b':width,
|
|
|
|
'h':height,
|
2006-06-07 11:03:58 +02:00
|
|
|
'out':"png",
|
2006-06-09 09:20:21 +02:00
|
|
|
'zeit':time,
|
2006-06-07 11:03:58 +02:00
|
|
|
'typ':0,
|
|
|
|
'boerse':1,
|
|
|
|
'land':276,
|
|
|
|
'seite':"kurse",
|
|
|
|
'herkunft':123
|
|
|
|
})
|
2006-06-14 01:13:52 +02:00
|
|
|
print "ich hole jetzt \"%s\" %i:" % (self.wkn_dict[wkn], time)
|
|
|
|
print host + params
|
|
|
|
###self.gui.add_log("%s %s" % (host, params))
|
2006-06-07 11:03:58 +02:00
|
|
|
try:
|
|
|
|
f = urllib.urlopen(host + params)
|
2006-06-09 09:20:21 +02:00
|
|
|
png = open("images/"+self.wkn_dict[wkn]+str(time)+".png", "w")
|
2006-06-07 11:03:58 +02:00
|
|
|
png.write(f.read())
|
|
|
|
png.close()
|
2006-06-10 14:18:28 +02:00
|
|
|
import time
|
|
|
|
time.sleep(2)
|
2006-06-07 11:03:58 +02:00
|
|
|
except IOError, e:
|
2006-06-09 14:05:30 +02:00
|
|
|
print e
|
2006-06-09 09:20:21 +02:00
|
|
|
|
|
|
|
def set_times(self, times):
|
|
|
|
self.times = times
|
2006-06-07 11:03:58 +02:00
|
|
|
|
2006-06-14 01:13:52 +02:00
|
|
|
def getallchartsnogui(self) :
|
|
|
|
for wkn in self.wkn_dict.keys():
|
|
|
|
for time in self.times:
|
|
|
|
self.getchart(wkn, time)
|
|
|
|
print "Download fertig"
|
|
|
|
return
|
|
|
|
|
2006-06-10 14:18:28 +02:00
|
|
|
def getallcharts(self, gui) :
|
2006-06-09 09:20:21 +02:00
|
|
|
self.gui = gui
|
2006-06-07 11:03:58 +02:00
|
|
|
for wkn in self.wkn_dict.keys():
|
2006-06-10 14:18:28 +02:00
|
|
|
self.gui.add_log("hole: %s (%s)" % (self.wkn_dict[wkn], wkn))
|
2006-06-09 09:20:21 +02:00
|
|
|
for time in self.times:
|
|
|
|
self.getchart(wkn, time)
|
2006-06-09 14:05:30 +02:00
|
|
|
print "Download fertig"
|
2006-06-09 09:20:21 +02:00
|
|
|
return
|
2006-06-07 11:03:58 +02:00
|
|
|
|
|
|
|
|
|
|
|
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])
|
2006-06-14 01:13:52 +02:00
|
|
|
wkn.getallchartsnogui()
|
2006-06-07 11:03:58 +02:00
|
|
|
#wkn.addwkn(wkn, name)
|
|
|
|
#wkn.delwkn(wkn)
|