# -*- coding: utf-8 -*-
from dbfpy import dbf
import sys
#MARKIERT: True (<type 'bool'>)
#GESPERRT: False (<type 'bool'>)
# UNGUELT: False (<type 'bool'>)
# WWWONLY: False (<type 'bool'>)
#   FIRMA:  (<type 'str'>)
#    NAME: A & W Assekuranz GmbH (<type 'str'>)
# VORNAME:  (<type 'str'>)
#  ANREDE:  (<type 'str'>)
# STRASSE: Falscheider Str. (<type 'str'>)
#  HAUSNR: 18 (<type 'str'>)
#ORTSTEIL:  (<type 'str'>)
#    LAND: D (<type 'str'>)
#     PLZ: 32584 (<type 'str'>)
#     ORT: L�hne (<type 'str'>)
#  TE'LZUS:  (<type 'str'>)
# VORWAHL: 05732 (<type 'str'>)
# TELEFON: 82404 (<type 'str'>)
#  ZUSATZ:  (<type 'str'>)
#     WWW:  (<type 'str'>)
#   EMAIL:  (<type 'str'>)
#   ALORT: 36091000 (<type 'int'>)
#   RECNO: 16381871 (<type 'int'>)
#     TID: 0 (<type 'int'>)
#   DATID: 135 (<type 'int'>)
# BEZEING: A & W Assekuranz GmbH (<type 'str'>)


sFile = sys.argv[1]

db = dbf.Dbf('/home/jhamel/' + sFile + '.KBX')
outfile = '/home/jhamel/Projekte/Addresses/' + sFile + '.txt'
f = open(outfile, 'wb')
for rec in db:
    s = '"' + rec['ANREDE'] + '";' 
    s += '"' + rec['VORNAME'] + '";'
    s += '"' + rec['NAME'] + '";'
    s += '"' + rec['FIRMA'] + '";'
   
   
    s += '"' + rec['STRASSE']  + '";'
    s += '"' + rec['HAUSNR']+ '",'
    s += '"' + rec['STRASSE'] + ' ' + rec['HAUSNR']+ '";'
    s += '"' + rec['ORTSTEIL'] + '";'
    s += '"' + rec['LAND'] + '";'
    s += '"' + rec['PLZ'] + '";'
    s += '"' + rec['ORT'] + '";'
    
    s += '"' + rec['TELZUS'] + '";'
    s += '"' + rec['VORWAHL'] + '";'
    s += '"' + rec['TELEFON'] + '";'
    s += '"(' + rec['VORWAHL'] +  ') ' + rec['TELEFON'] + '";'
    s += '"' + rec['VORWAHL'] +  '/' + rec['TELEFON'] + '"\n'
    
    s = s.encode('utf-8').decode('latin-1')
    f.write(s)
    
f.close()
    
print rec['NAME']
print
