From 5beaa74ea0b74cf47140403ccd5839f72788c01b Mon Sep 17 00:00:00 2001 From: age Date: Wed, 7 Jun 2006 09:03:58 +0000 Subject: [PATCH] init --- WKNcharts/TODO | 4 + WKNcharts/WknCharts.py | 25 ++ WKNcharts/filechooser.py | 46 +++ WKNcharts/filechooser.pyc | Bin 0 -> 1820 bytes WKNcharts/getWKNcharts.py | 65 +++++ WKNcharts/wknGUI.py | 43 +++ WKNcharts/wknGUI.pyc | Bin 0 -> 2319 bytes WKNcharts/wkncharts.glade | 496 ++++++++++++++++++++++++++++++++ WKNcharts/wkncharts.glade.bak | 497 +++++++++++++++++++++++++++++++++ WKNcharts/wkncharts.gladep | 11 + WKNcharts/wkncharts.gladep.bak | 11 + WKNcharts/wkns.txt | 2 + WKNcharts/wkns.txt.orig | 11 + gallery.py | 142 ++++++++++ normalizer.py | 114 ++++++++ 15 files changed, 1467 insertions(+) create mode 100644 WKNcharts/TODO create mode 100755 WKNcharts/WknCharts.py create mode 100644 WKNcharts/filechooser.py create mode 100644 WKNcharts/filechooser.pyc create mode 100755 WKNcharts/getWKNcharts.py create mode 100644 WKNcharts/wknGUI.py create mode 100644 WKNcharts/wknGUI.pyc create mode 100644 WKNcharts/wkncharts.glade create mode 100644 WKNcharts/wkncharts.glade.bak create mode 100644 WKNcharts/wkncharts.gladep create mode 100644 WKNcharts/wkncharts.gladep.bak create mode 100644 WKNcharts/wkns.txt create mode 100644 WKNcharts/wkns.txt.orig create mode 100755 gallery.py create mode 100755 normalizer.py diff --git a/WKNcharts/TODO b/WKNcharts/TODO new file mode 100644 index 0000000..491a304 --- /dev/null +++ b/WKNcharts/TODO @@ -0,0 +1,4 @@ +[.] eingelesenen srcfile Namen, aus dem Textfeld wieder auslesen + * mehrere intervalle holen (30, 300, 10000, 30000) + * dateinamen besser vergeben + * datum einbringen diff --git a/WKNcharts/WknCharts.py b/WKNcharts/WknCharts.py new file mode 100755 index 0000000..78b16bc --- /dev/null +++ b/WKNcharts/WknCharts.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python +__version__="0.3" +__author__="AGE" +__date__="02006-06-07" + + +class WknCharts: + import sys + def __init__(self): + try: + import pygtk + pygtk.require("2.0") + import gtk + from gtk import glade + except: + print "dumme fehlermeldung" + sys.exit(1) + + import wknGUI + wg = wknGUI.WknGUI(gtk) + gtk.main() + +if __name__ == "__main__": + wc = WknCharts() + diff --git a/WKNcharts/filechooser.py b/WKNcharts/filechooser.py new file mode 100644 index 0000000..ee8668f --- /dev/null +++ b/WKNcharts/filechooser.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python + +class FileChooserDialog: + 'does what it sounds like ;)' + def __init__(self): + return + + def getfilename(self): + 'returns name of the choosen file or empty string' + import gtk + # der Filedialog ist erst ab pygtk2.4 drin + if gtk.pygtk_version < (2,3,90): + print "Du brauchst mindestens PyGtk 2.3.90" + raise SystemExit + + dialog = gtk.FileChooserDialog("Datei oeffnen..", + None, + gtk.FILE_CHOOSER_ACTION_OPEN, + (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, + gtk.STOCK_OPEN, gtk.RESPONSE_OK)) + dialog.set_default_response(gtk.RESPONSE_OK) + + filter = gtk.FileFilter() + filter.set_name("Alle Dateien") + filter.add_pattern("*") + dialog.add_filter(filter) + + filter = gtk.FileFilter() + filter.set_name("Text") + filter.add_mime_type("text/txt") + filter.add_mime_type("text/asc") + filter.add_pattern("*.txt") + filter.add_pattern("*.asc") + dialog.add_filter(filter) + + response = dialog.run() + if response == gtk.RESPONSE_OK: + filename = dialog.get_filename() + #print "hier haste den Dateinamen: ", filename + elif response == gtk.RESPONSE_CANCEL: + #print "die feige sau bricht einfach ab.." + filename = "" + dialog.destroy() + + return filename + diff --git a/WKNcharts/filechooser.pyc b/WKNcharts/filechooser.pyc new file mode 100644 index 0000000000000000000000000000000000000000..c012e44733b596313e636af2fad679c5dfdf5445 GIT binary patch literal 1820 zcmb_dOK;mo5T2#vhh#fef}juNvPCay4pPvfK!O}vS5_WKAQ_e~(PhDkONp^a3fxs2 z0ya?8{Tuz0{RRDID6eUKN)(he4R?rd?Igv)$h<0xob*+^RNkP3QsNp!8~N>PH+Q8y}XQrw{TMENnPXop_D@&Wy>C{v`^4i>xQ zo8q%0bXVw}(0!pTiko!Pq-&TpDLL32-fSQac}~|2x@u5zkD@&i1%zXY_A3Ei9oGMg zORILdPf>eYIH(1HArObGkdG?iBV-5R9DzLGAcW3UHMXDo|x|_ z;enyaAXsE_UxS>k_0L7Po-Lf$Sc1qpZ-IGMzVw&++unD*XHOhQJPo}~bZ+A~vstg_ z4smv}L=aKHh1c(~EZv3u;AL4nn7-c@LN{}~I*)sNTycDcBkJ-8=Qz8$zjQ}6LAS^ieog=gm&I*cN-3O#gHr7Ul3xfLv?NotKRS5}%-tTREWgYiV> zfP|M7SdLK(dk}cIMP7C}kNSG3JN}XRR;pWtvdL|{E_f31iPs8OkGyX)yjI`GnnS(KD9<7%aBKN|WD4&6^ x?5aym2C8y#zSH!-R6zM(X2Bov50Voj{tcvRp?v@V literal 0 HcmV?d00001 diff --git a/WKNcharts/getWKNcharts.py b/WKNcharts/getWKNcharts.py new file mode 100755 index 0000000..633e407 --- /dev/null +++ b/WKNcharts/getWKNcharts.py @@ -0,0 +1,65 @@ +#!/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) diff --git a/WKNcharts/wknGUI.py b/WKNcharts/wknGUI.py new file mode 100644 index 0000000..77514d4 --- /dev/null +++ b/WKNcharts/wknGUI.py @@ -0,0 +1,43 @@ +#/usr/bin/env python +__version__="0.3" +__author__="AGE" +__date__="02006-06-07" + +class WknGUI: + """ + This is a GTK-Frontend for getWKNcharts.py + """ + import sys + + def __init__(self, gtk): + self.gladefile = "wkncharts.glade" + self.gtk = gtk + self.gladefile = "wkncharts.glade" + self.wkngui = self.gtk.glade.XML(self.gladefile) + actions = { "on_read_srcfile_clicked": self.clicked_read_srcfile, + "on_choose_srcfile_clicked": self.clicked_choose_srcfile, + "on_window1_destroy": self.exit + } + self.wkngui.signal_autoconnect (actions) + + def clicked_read_srcfile(self, widget): + file = self.wkngui.get_widget("tf_srcfile").get_text() + + + def clicked_choose_srcfile(self, widget): + import filechooser + fcd = filechooser.FileChooserDialog() + filename = fcd.getfilename() + if filename: + self.outputfield = self.wkngui.get_widget("tf_srcfile") + self.textbuffer = self.outputfield.get_buffer() + self.textbuffer.set_text(filename) + else: + self.outputfield = self.wkngui.get_widget("tf_srcfile") + self.textbuffer = self.outputfield.get_buffer() + self.textbuffer.set_text("keine Datei ausgewaehlt") + + def exit(self, widget): + print "ciao ciao" + self.sys.exit(1) + diff --git a/WKNcharts/wknGUI.pyc b/WKNcharts/wknGUI.pyc new file mode 100644 index 0000000000000000000000000000000000000000..479303d1104586b94dda92dfeb05ebdfb805b888 GIT binary patch literal 2319 zcmb_cZEqVz5S}~RN$jLTR0V{JkUtuv#sS2OluEobG_6|v0g3|tvO4b8=auc<=yqM# zQu!3b&)~20KlK;z%-s1dNt+MI_l0Ey_Cd%V399Soi4g3;BM3`lH`x{_~@wukP{xYtKSw zGkf~$pq(r z-^V}cpFVqX?_uF=&^GH&T+z>UID0Zmr%4g~;rY7P9i=gJ*zq>r2Y5ZaVCyf56ll2+ zf2tiK6O(C?X|s%p=%SSA&=j}8UEbZH*8Mg-=Jl?uOX)qV|13p1WP0>6X7wl|<=?+_aMdTV zr(c-hcOjFc!8q$ZJLpYrletQk!KKbxorVFMY#d~cUAm+=z!nMdUt%?!x`iGlxgPqp zO^4@&%Zp^OFg72aufx>YVO{qjLI4C&e!mAzrHnN}sROJ%6N+>JhM*XUrB2s%E( zqAWX50GOb9z`_L)sw!1v$&v4YhRLQJQradQ?t?0iEC*1kmC5iChnNleMG$$e$hBmM zb}7yk6bXE{PR30oW$<~9iXuq|(a-9QK{pe4{UJu>^O#=T*``R}Ue!n&2tkG z^mHBuf&}gmPHlsg4A?k*#1KGVp`+fYBhRYTB(Bc{Lcl!-+BBDNYcCr- zZ3cXObKG>#{}MabR;+A{P}GSAoZ@P@FdUSU3M#d5*%G5$$skiIb1BvvhgoSejJBGu zO<=OxqOzQsT?(r>+27#+9MXz%)0O fx>pXbU(^U!`P + + + + + + True + window1 + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + False + True + False + True + False + False + GDK_WINDOW_TYPE_HINT_NORMAL + GDK_GRAVITY_NORTH_WEST + + + + + True + True + True + True + GTK_POS_TOP + False + False + + + + True + False + 0 + + + + True + True + 0 + + + + True + Wertpapierkennnummer + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + 0 + False + False + + + + + + True + Aktien/Fond Name + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + 0 + False + False + + + + + 0 + False + False + + + + + + True + False + 0 + + + + True + True + True + True + 0 + + True + * + False + + + 0 + True + True + + + + + + True + True + True + True + 0 + + True + * + False + + + 0 + True + True + + + + + 0 + True + True + + + + + + True + False + 0 + + + + True + True + Hinzufügen + True + GTK_RELIEF_NORMAL + True + + + 0 + False + False + + + + + + True + True + Löschen + True + GTK_RELIEF_NORMAL + True + + + 0 + False + False + + + + + 0 + True + False + GTK_PACK_END + + + + + False + True + + + + + + True + Download + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + tab + + + + + + True + False + 0 + + + + + + + + + + + + + + + False + True + + + + + + True + Bilder + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + tab + + + + + + True + False + 0 + + + + True + False + 0 + + + + True + Quelldatei + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + 0 + False + False + + + + + + True + True + GTK_POLICY_NEVER + GTK_POLICY_NEVER + GTK_SHADOW_IN + GTK_CORNER_TOP_LEFT + + + + True + True + GDK_EXTENSION_EVENTS_ALL + False + False + True + GTK_JUSTIFY_LEFT + GTK_WRAP_NONE + False + 0 + 0 + 0 + 0 + 0 + 0 + Dateiname + + + + + 0 + True + True + + + + + 0 + True + True + + + + + + True + True + Quelldatei einlesen + True + GTK_RELIEF_NORMAL + True + + + + 0 + True + False + GTK_PACK_END + + + + + + True + True + Quelldatei auswählen + True + GTK_RELIEF_NORMAL + True + + + + 0 + False + False + + + + + False + True + + + + + + True + Einstellungen + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + tab + + + + + + True + False + 0 + + + + True + label5 + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + 0 + False + False + + + + + + True + + + 0 + True + True + + + + + + True + True + GTK_POLICY_ALWAYS + GTK_POLICY_ALWAYS + GTK_SHADOW_NONE + GTK_CORNER_TOP_LEFT + + + + True + True + True + False + True + GTK_JUSTIFY_LEFT + GTK_WRAP_NONE + True + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0 + True + True + + + + + False + True + + + + + + True + Logbuch + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + tab + + + + + + + diff --git a/WKNcharts/wkncharts.glade.bak b/WKNcharts/wkncharts.glade.bak new file mode 100644 index 0000000..23c7a1d --- /dev/null +++ b/WKNcharts/wkncharts.glade.bak @@ -0,0 +1,497 @@ + + + + + + + True + window1 + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + False + True + False + True + False + False + GDK_WINDOW_TYPE_HINT_NORMAL + GDK_GRAVITY_NORTH_WEST + + + + + True + True + True + True + GTK_POS_TOP + False + False + + + + True + False + 0 + + + + True + True + 0 + + + + True + Wertpapierkennnummer + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + 0 + False + False + + + + + + True + Aktien/Fond Name + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + 0 + False + False + + + + + 0 + False + False + + + + + + True + False + 0 + + + + True + True + True + True + 0 + + True + * + False + + + 0 + True + True + + + + + + True + True + True + True + 0 + + True + * + False + + + 0 + True + True + + + + + 0 + True + True + + + + + + True + False + 0 + + + + True + True + Hinzufügen + True + GTK_RELIEF_NORMAL + True + + + 0 + False + False + + + + + + True + True + Löschen + True + GTK_RELIEF_NORMAL + True + + + 0 + False + False + + + + + 0 + True + False + GTK_PACK_END + + + + + False + True + + + + + + True + Download + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + tab + + + + + + True + False + 0 + + + + + + + + + + + + + + + False + True + + + + + + True + Bilder + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + tab + + + + + + True + False + 0 + + + + True + False + 0 + + + + True + Quelldatei + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + 0 + False + False + + + + + + True + False + True + GTK_POLICY_NEVER + GTK_POLICY_NEVER + GTK_SHADOW_IN + GTK_CORNER_TOP_LEFT + + + + True + True + GDK_EXTENSION_EVENTS_ALL + True + False + False + GTK_JUSTIFY_LEFT + GTK_WRAP_NONE + True + 0 + 0 + 0 + 0 + 0 + 0 + Dateiname + + + + + 0 + True + True + + + + + 0 + True + True + + + + + + True + True + Quelldatei einlesen + True + GTK_RELIEF_NORMAL + True + + + + 0 + True + False + GTK_PACK_END + + + + + + True + True + Quelldatei auswählen + True + GTK_RELIEF_NORMAL + True + + + + 0 + False + False + + + + + False + True + + + + + + True + Einstellungen + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + tab + + + + + + True + False + 0 + + + + True + label5 + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + 0 + False + False + + + + + + True + + + 0 + True + True + + + + + + True + True + GTK_POLICY_ALWAYS + GTK_POLICY_ALWAYS + GTK_SHADOW_NONE + GTK_CORNER_TOP_LEFT + + + + True + True + True + False + True + GTK_JUSTIFY_LEFT + GTK_WRAP_NONE + True + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0 + True + True + + + + + False + True + + + + + + True + Logbuch + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + tab + + + + + + + diff --git a/WKNcharts/wkncharts.gladep b/WKNcharts/wkncharts.gladep new file mode 100644 index 0000000..5034bee --- /dev/null +++ b/WKNcharts/wkncharts.gladep @@ -0,0 +1,11 @@ + + + + + WKNcharts + wkncharts + FALSE + FALSE + FALSE + FALSE + diff --git a/WKNcharts/wkncharts.gladep.bak b/WKNcharts/wkncharts.gladep.bak new file mode 100644 index 0000000..5034bee --- /dev/null +++ b/WKNcharts/wkncharts.gladep.bak @@ -0,0 +1,11 @@ + + + + + WKNcharts + wkncharts + FALSE + FALSE + FALSE + FALSE + diff --git a/WKNcharts/wkns.txt b/WKNcharts/wkns.txt new file mode 100644 index 0000000..05b3a8e --- /dev/null +++ b/WKNcharts/wkns.txt @@ -0,0 +1,2 @@ +881823 samsung + diff --git a/WKNcharts/wkns.txt.orig b/WKNcharts/wkns.txt.orig new file mode 100644 index 0000000..169524b --- /dev/null +++ b/WKNcharts/wkns.txt.orig @@ -0,0 +1,11 @@ +881823 samsung +980705 grund-global +870737 nokia +847652 dws-vermoegen +847414 dws-technologie +DE000A0AB0K1 allegro-inv +DE0005152623 deka-technologie +LU0048578792 fidelity +DE0009802306 seb-immoinvest +DE0009848002 dws-internet + diff --git a/gallery.py b/gallery.py new file mode 100755 index 0000000..351a717 --- /dev/null +++ b/gallery.py @@ -0,0 +1,142 @@ +#!/usr/bin/env python +# see: http://www.amk.ca/python/code/ + +import sys, os, getopt +try: + from PIL import Image +except ImportError: + print >>sys.stderr, ("Unable to import PIL.Image; " + "is the Python Imaging Library installed?") + sys.exit(0) + +__version__ = '1.01' +__doc__ = """%s [option] file1 file2 +Options: + --help Display this usage message + --html Output HTML to stdout + --resize x y Resize specified images to x,y + --rotate x Rotate the image counter clockwise for x degrees + --size Display the image sizes + --thumbnail x y Make thumbnails of specified images, ignoring existing + thumbnails that happen to be listed among the files. + +If a filename is of the form *_thumb.*, it's assumed to be a thumbnail. + +""" % sys.argv[0] + +def is_thumbnail (filename): + "Returns true if the filename is for a thumbnail" + root, ext = os.path.splitext(filename) + return root.endswith('_thumb') + +def thumbnail_name (filename): + """Return the thumbnail form of a filename, + converting foo.jpg to foo_thumb.jpg. + """ + assert not is_thumbnail(filename) + root, ext = os.path.splitext(filename) + return root + '_thumb' + ext + +def output_html (args): + for filename in args: + if is_thumbnail(filename): continue + thumbnail = thumbnail_name(filename) + + if not os.path.exists(thumbnail): + print >>sys.stderr, ("%s: thumbnail %s doesn't exist" % + (sys.argv[0], thumbnail) ) + + im = Image.open(thumbnail) + width, height = im.size + + print ('

' + '\n\nXXX\n' + '


\n\n' + % (filename, thumbnail, width, height) ) + +def make_thumbnails (args): + x, y = int(args[0]), int(args[1]) + args = args[2:] ; args.sort() + + for filename in args: + if is_thumbnail(filename): continue + thumbnail = thumbnail_name(filename) + + print >>sys.stderr, filename + im = Image.open(filename) + im.thumbnail((x,y)) + im.save(thumbnail) + +def rotate_images (args): + x = int(args[0]) + args = args[1:] ; args.sort() + for filename in args: + im = Image.open(filename) + im2 = im.rotate(x) + im2.save(filename) + print "rotated %s %i degrees" % (filename, x) + +def resize_images (args): + x, y = int(args[0]), int(args[1]) + args = args[2:] ; args.sort() + for filename in args: + im = Image.open(filename) + w,h = im.size + im2 = im.resize((x,y)) + print >>sys.stderr, ('%s: was %i,%i; resizing to %i,%i' + % (filename, w,h, x,y) ) + im2.save(filename) + + +def main (): + opts, args = getopt.getopt(sys.argv[1:], + 'h', + ['help', + 'html', + 'resize', + 'size', + 'thumbnail', + 'rotate']) + + # Remove the unused option arguments + opts = [opt for opt,arg in opts] + + # Print usage message if requested + if '-h' in opts or '--help' in opts: + print >>sys.stderr, __doc__ + sys.exit(0) + + # Ensure that exactly one option is supplied + if len(opts) == 0: + print >> sys.stderr, ("%s: must specify one of --size, --help" + "\n --html, --resize, --thumbnail --rotate" % + sys.argv[0] ) + sys.exit(0) + elif len(opts) > 1: + print >> sys.stderr, ("%s: cannot specify multiple options" % + sys.argv[0] ) + sys.exit(0) + + # Perform each of the possible actions + opt = opts[0] + if opt == '--html': + output_html(args) + elif opt == '--resize': + resize_images(args) + elif opt == '--rotate': + rotate_images(args) + elif opt == '--size': + for filename in args: + image = Image.open(filename) + x, y = image.size + print filename, ':', x,y + elif opt == '--thumbnail': + make_thumbnails(args) + + else: + print >>sys.stderr, ("%s: unknown option" % sys.argv[0]) + +if __name__ == '__main__': + main() + diff --git a/normalizer.py b/normalizer.py new file mode 100755 index 0000000..47c7243 --- /dev/null +++ b/normalizer.py @@ -0,0 +1,114 @@ +#!/usr/bin/env python +## this is a dirty, lame hack by a dirty, lame guy +## - reads a .m3u file (e.g. generated by xmms) +## - converts any audiofile to wavefiles using incredible mplayer +## - provides normalized wavefiles using transcode +## - burns an audio-cd +# !!feel free to copy, modify, redistribute and at most _use_ it!! +# AGE/02004 + +import os,sys +import string + +#recorder = "ATAPI:0,0,0" #fuer cdrecord mit 2.6 kernel und ide brenner +recorder = "0,0,0" #fuer cdrecord mit 2.6 kernel und ide brenner + +__doc__ = """usage: %s file.m3u wav-destination""" % sys.argv[0] + +################ +### init checks +try: + m3ufile = sys.argv[1] + wavdir = sys.argv[2] + if not os.access(wavdir,os.W_OK) : + print "%s not writeable" % wavdir + sys.exit(3) +except: + print >>sys.stderr, __doc__ + sys.exit(1) + + +print "\nDirty, lame hack in action:\n" +################ +### m3u einlesen +try: + temp = open(m3ufile,"r") + m3u = temp.read() + temp.close() +except: + print "I can't find the .m3u file" + sys.exit(2) +# M's Kommentar Schnibbler +notfound = 0 +while notfound == 0: + startpos = string.find(m3u,"#") + if startpos <0: + notfound +=1 + endpos = string.find(m3u,"\n",startpos) + cutme = m3u[startpos:endpos] + m3u = string.replace(m3u,cutme,"") + +valuepairs = string.split(m3u,"\n") +m3u = [] +for i in valuepairs: + if i != "": + m3u.append(i) +# im m3u-array stehen jetzt hoffentlich ;) nur noch pfadangaben +# checken ob's stimmt & und ob alle files existieren +abort = 0 +for i in m3u: + if not os.path.exists(i): + abort = abort + 1 + print "===> not found: %s " % i + m3u.remove(i) +if abort > 0: + print "\nI can't find %i audiofiles - giving up" % abort + #TODO + # abfrage ob ohne die files mit gekuertzter m3u weiter gemacht werden + # soll.. + sys.exit(0) +else: + print "\nI found %i audiofiles to convert, normalize and burn:" % len(m3u) + + +############## +### ogg/mp3 -> wav +count = 0 +for file in m3u: + count+=1 + # fuehrende nullen ranballern + #if count < 10: + #count0 = "0"+str(count) + #else: + #count0 = str(count) + count0 = "%.3i" % count + command = "mplayer \""+file+"\" -vc dummy -vo null -ao pcm -aofile "+wavdir+"/"+str(count0)+".wav &> /dev/null" + print "\nexec: "+command + session = os.popen(command,"w") + session.write("") + session.flush() + session.close() + +######################### +### wav -> normalized wav +wavefiles = os.listdir(wavdir) +for wave in wavefiles: + command = "transcode -J normalize -y wav -i "+wavdir+"/"+wave+" -m "+wavdir+"/"+ wave+".norm &> /dev/null" + print "\nexec: "+command + session = os.popen(command,"w") + session.write("") + session.flush() + session.close() + +################## +### wav -> audiocd +command = "sudo cdrecord -v -dev="+recorder+" -pad -audio "+wavdir+"/*.wav.norm" +print "\nexec: "+command +print "\nwarning: If this fails, try to change the \"recorder\" variable!" +session = os.popen(command,"w") +session.write("") +session.flush() +session.close() + +#print "\n That's it! Eine Stunde coden und dafuer jetzt den Sommer geniessen..." +print "done"