Skip to content

Commit

Permalink
Add flag for debug print() calls.
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-pri committed Dec 29, 2020
1 parent 742230a commit 0b58271
Showing 1 changed file with 41 additions and 32 deletions.
73 changes: 41 additions & 32 deletions genesisclient/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import logging
from lxml import etree

DEBUG = False
gc = None


Expand Down Expand Up @@ -62,7 +63,8 @@ def init_service_client(self, name):
if name not in self.service_clients:
url = (self.sites[self.site]['webservice_url']
+ self.endpoints[name])
print(" url = ", url)
if DEBUG:
print(" url = ", url)
self.service_clients[name] = suds.client.Client(url, retxml=True)
return self.service_clients[name]

Expand All @@ -89,7 +91,8 @@ def search(self, searchterm='*:*', limit=500, category='alle'):
"Datenquader", "Merkmal", "Statistik"
"""
client = self.init_service_client('RechercheService_2010')
#print(client)
if DEBUG:
print(client)
params = dict(luceneString=searchterm,
kennung=self.username,
passwort=self.password,
Expand Down Expand Up @@ -134,7 +137,8 @@ def terms(self, filter='*', limit=20):
to implement search term auto-completion.
"""
client = self.init_service_client('RechercheService_2010')
#print(client)
if DEBUG:
print(client)
params = dict(kennung=self.username,
passwort=self.password,
filter=filter,
Expand Down Expand Up @@ -174,7 +178,8 @@ def properties(self, filter='*', criteria='Code', type="alle", limit=500):
area
"""
client = self.init_service_client('RechercheService_2010')
#print(client)
if DEBUG:
print(client)
params = dict(kennung=self.username,
passwort=self.password,
filter=filter,
Expand Down Expand Up @@ -263,7 +268,8 @@ def property_statistics(self, property_code='*', selection='*',
listenLaenge=str(limit),
sprache='de')
result = client.service.MerkmalStatistikenKatalog(**params)
print(result)
if DEBUG:
print(result)

def property_tables(self, property_code='*', selection='*', limit=500):
client = self.init_service_client('RechercheService_2010')
Expand All @@ -275,7 +281,8 @@ def property_tables(self, property_code='*', selection='*', limit=500):
listenLaenge=str(limit),
sprache='de')
result = client.service.MerkmalTabellenKatalog(**params)
print(result)
if DEBUG:
print(result)

def statistics(self, filter='*', criteria='Code', limit=500):
"""
Expand Down Expand Up @@ -417,10 +424,12 @@ def table_export(self, table_code,
"""
Return data for a given table
"""
print("table_export")
if DEBUG:
print("table_export")
client = self.init_service_client('DownloadService_2010')

print("client = self.init_service_client('DownloadService_2010') =", client)
if DEBUG:
print("client = self.init_service_client('DownloadService_2010') =", client)
params = dict(kennung=self.username,
passwort=self.password,
name=table_code,
Expand All @@ -443,7 +452,8 @@ def table_export(self, table_code,
stand='',
sprache='de',
)
print(" nach --- > table_export")
if DEBUG:
print(" nach --- > table_export")
result = None

if len(regionalschluessel) == 8:
Expand All @@ -461,13 +471,13 @@ def table_export(self, table_code,
result = client.service.TabellenDownload(**params)
# Really nasty way to treat a multipart message...
# (room for improvement)
print("type(result) =====", type(result))
print("result =====", result)

result_str = result.decode("utf-8")
print("result_str =====", result_str)
parts = result_str.split("\n")
print("parts =====", parts)
if DEBUG:
print("type(result) =====", type(result))
print("result =====", result)
print("result_str =====", result_str)
print("parts =====", parts)

for i in range(0, 12):
parts.pop(0)
Expand All @@ -480,34 +490,31 @@ def table_export(self, table_code,
result = client.service.TabellenDownload(**params)
# Really nasty way to treat a multipart message...
# (room for improvement)
# (room for improvement)
print("type(result) =====", type(result))
print("result =====", result)

result_str = result.decode("utf-8")
print("result_str =====", result_str)
parts = result_str.split("\n")
print("parts =====", parts)
if DEBUG:
print("type(result) =====", type(result))
print("result =====", result)
print("result_str =====", result_str)
print("parts =====", parts)
# for i in range(0, 12):
# parts.pop(i)
parts.pop()
parts.pop()
return "\r\n".join(parts)
else:
print(" result = client.service.TabellenDownload(**params)", params)
result = client.service.TabellenDownload(**params)
print("type(result) =====", type(result))
print("result =====", result)

result_str = result.decode("utf-8")
print("result_str =====", result_str)

result_str = result.decode("utf-8")
parts = result_str.split(result_str.split("\r\n")[1])
data = parts[2].split("\r\n\r\n", 1)[-1]
#data = unicode(data.decode('latin-1'))
#data = unicode(data.decode('utf-8'))

print(" date ===== ", data)
if DEBUG:
print(" result = client.service.TabellenDownload(**params)", params)
print("type(result) =====", type(result))
print("result =====", result)
print("result_str =====", result_str)
print(" date ===== ", data)
return data


Expand All @@ -530,7 +537,8 @@ def download(client, args):
if args.regionalschluessel is not None and args.regionalschluessel != '*':
rs = args.regionalschluessel
path = '%s_%s.%s' % (args.download, args.regionalschluessel, args.format)
print("Downloading to file %s" % path)
if True:
print("Downloading to file %s" % path)
result = client.table_export(args.download,
regionalschluessel=rs,
format=args.format)
Expand Down Expand Up @@ -623,8 +631,8 @@ def main():
password=args.password)
# test if the service works
#gc.test_service()

print("gc = ", gc, "args =", args)
if DEBUG:
print("gc = ", gc, "args =", args)
if args.download is not None:
download(gc, args)
elif args.searchterm is not None:
Expand All @@ -633,6 +641,7 @@ def main():
lookup(gc, args)

# From here on it's all work-in-progress code
# ???????????????????????????????????????????
sys.exit()

# submit a search
Expand Down

0 comments on commit 0b58271

Please sign in to comment.