Skip to content

Commit

Permalink
start conversion to python 3
Browse files Browse the repository at this point in the history
  • Loading branch information
tomshaffner committed May 14, 2019
1 parent 7c90de1 commit 4e296c0
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 44 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ The manual way: download or clone the code, change to the directory containing `

python setup.py install

Then make sure the `lxml` and `suds` Python modules are installed.
Then make sure the `lxml` and `suds-py3` Python modules are installed.

## Supported backends

Expand Down
81 changes: 40 additions & 41 deletions genesisclient/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# encoding: utf8

import suds
import logging
from lxml import etree
Expand Down Expand Up @@ -264,7 +263,7 @@ def property_statistics(self, property_code='*', selection='*',
listenLaenge=str(limit),
sprache='de')
result = client.service.MerkmalStatistikenKatalog(**params)
print result
print(result)

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

def statistics(self, filter='*', criteria='Code', limit=500):
"""
Expand Down Expand Up @@ -473,7 +472,7 @@ 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
print("Downloading to file %s" % path)
result = client.table_export(args.download,
regionalschluessel=rs,
format=args.format)
Expand All @@ -486,50 +485,50 @@ def search(client, args):
using options given via the command line
"""
term = args.searchterm
if type(term) != unicode:
if type(term) != str:
term = term.decode('utf8')
result = client.search(term)
for cat in result['meta'].keys():
for cat in list(result['meta'].keys()):
if result['meta'][cat] > 0:
print "Hits of type '%s': %d" % (cat.upper(), result['meta'][cat])
print("Hits of type '%s': %d" % (cat.upper(), result['meta'][cat]))
for hit in result['results']:
otype = hit['type'].upper()
if otype == 'MERKMAL' or otype == 'STATISTIK':
print "%s %s %s" % (otype, clean(hit['name']), clean(hit['description']))
print("%s %s %s" % (otype, clean(hit['name']), clean(hit['description'])))
elif otype == 'TABELLE':
print "%s %s %s" % (otype, clean(hit['name']), clean(hit['description']))
print("%s %s %s" % (otype, clean(hit['name']), clean(hit['description'])))
elif otype == 'BEGRIFF':
print "%s %s" % (otype, clean(hit['name']))
print("%s %s" % (otype, clean(hit['name'])))
else:
print "%s %s" % (hit['type'].upper(), hit)
print("%s %s" % (hit['type'].upper(), hit))


def lookup(client, args):
"""
Lookup tables and print out info on found entries
"""
term = args.lookup
if type(term) != unicode:
if type(term) != str:
term = term.decode('utf8')
for stat in gc.statistics(filter=term):
print "STATISTIC: %s %s" % (stat['id'], stat['description'])
print("STATISTIC: %s %s" % (stat['id'], stat['description']))
for s in gc.statistic_data(statistic_code=term):
print "STATISTIC DATA: %s %s" % (s['id'], s['description'])
print("STATISTIC DATA: %s %s" % (s['id'], s['description']))
for s in gc.statistic_properties(statistic_code=term):
print "STATISTIC PROPERTY: %s %s" % (s['id'], s['description'])
print("STATISTIC PROPERTY: %s %s" % (s['id'], s['description']))
for s in gc.statistic_tables(statistic_code=term):
print "STATISTIC TABLE: %s %s" % (s['id'], s['description'])
print("STATISTIC TABLE: %s %s" % (s['id'], s['description']))
for prop in gc.properties(filter=term):
print "PROPERTY: %s %s" % (prop['id'], prop['description'])
print("PROPERTY: %s %s" % (prop['id'], prop['description']))
if '*' not in term:
for prop in gc.property_occurrences(property_code=term):
print "PROPERTY OCCURRENCE: %s %s" % (prop['id'], prop['description'])
print("PROPERTY OCCURRENCE: %s %s" % (prop['id'], prop['description']))
for prop in gc.property_data(property_code=term):
print "PROPERTY DATA: %s %s" % (prop['id'], prop['longdescription'])
print("PROPERTY DATA: %s %s" % (prop['id'], prop['longdescription']))
for table in gc.tables(filter=term):
print "TABLE: %s %s" % (table['id'], table['description'])
print("TABLE: %s %s" % (table['id'], table['description']))
for term in gc.terms(filter=term):
print "TERM: %s %s" % (term['id'], term['description'])
print("TERM: %s %s" % (term['id'], term['description']))


def main():
Expand Down Expand Up @@ -586,45 +585,45 @@ def main():

# retrieve terms satrting with 'a'.
terms = gc.terms(filter='a*')
print "Terms list has", len(terms), "entries. Example:"
print (terms[0].inhalt)
print("Terms list has", len(terms), "entries. Example:")
print((terms[0].inhalt))

# retrieve catalogue items starting with "11111"
catalogue = gc.catalogue(filter='11111*')
print "Catalogue result has", len(catalogue), "entries. Example:"
print (catalogue[0].code,
print("Catalogue result has", len(catalogue), "entries. Example:")
print((catalogue[0].code,
catalogue[0].beschriftungstext.replace("\n", " "),
catalogue[0].inhalt)
catalogue[0].inhalt))

# retrieve properties
properties = gc.properties(filter='B*', type='sachlich')
print "Properties list has", len(properties), "entries. Example:"
print (properties[0].code, properties[0].inhalt)
print("Properties list has", len(properties), "entries. Example:")
print((properties[0].code, properties[0].inhalt))

# retrieve occurences for a property
occurences = gc.property_occurrences(property_code=properties[0].code)
print "Occurrences list has", len(occurences), "entries. Example:"
print (occurences[0].code, occurences[0].inhalt)
print("Occurrences list has", len(occurences), "entries. Example:")
print((occurences[0].code, occurences[0].inhalt))

# retrieve data for a property
data = gc.property_data(property_code=properties[0].code)
print "Data list has", len(data), "entries. Example:"
print (data[0].code,
print("Data list has", len(data), "entries. Example:")
print((data[0].code,
data[0].inhalt,
data[0].beschriftungstext.replace("\n", " "))
data[0].beschriftungstext.replace("\n", " ")))

statistics = gc.property_statistics(property_code=properties[0].code)
print "Statistics list has", len(statistics), "entries. Example:"
print (statistics[0].code,
statistics[0].inhalt.replace("\n", " "))
print("Statistics list has", len(statistics), "entries. Example:")
print((statistics[0].code,
statistics[0].inhalt.replace("\n", " ")))

tables = gc.property_tables(property_code=properties[0].code)
print "Tables list has", len(statistics), "entries. Example:"
print (tables[0].code,
tables[0].inhalt.replace("\n", " "))
print("Tables list has", len(statistics), "entries. Example:")
print((tables[0].code,
tables[0].inhalt.replace("\n", " ")))

table = gc.table_export(table_code=tables[0].code)
print table
print(table)

if __name__ == '__main__':
main()
main()
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from setuptools import setup

setup(name='genesisclient',
version='0.0.7',
version='0.0.8',
description='Genesis (DeStatis et. al.) client for Python',
author='Marian Steinbach',
author_email='[email protected]',
Expand All @@ -12,7 +12,7 @@
packages=['genesisclient'],
install_requires=[
'lxml',
'suds'],
'suds-py3'],
entry_points={
'console_scripts': [
'genesiscl = genesisclient:main'
Expand Down

0 comments on commit 4e296c0

Please sign in to comment.