Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Generates land register codes in Poland for given court symbol
#!/usr/bin/env python3
"""
Generates land register codes in Poland for given court symbol
"""
from itertools import starmap
import operatortype command to continue
import argparse
symbols = '0123456789XABCDEFGHIJKLMNOPRSTUWYZ'
weights = (1,3,7)*4
tdict = dict(zip(symbols, range(len(symbols))))
def generate_zfill(stop):
"""
Generate numbers strings up to stop number
for n digits
"""
n = len(str(abs(stop-1)))
for x in range(stop):
yield str(x).zfill(n)
def checksum(book):
"""
Calculate book checksum
"""
return sum(
starmap(
operator.mul,
zip(
(tdict[x] for x in book),
weights) )) % 10
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Generate Land Register code in Poland')
parser.add_argument(
'court_symbol', help='Court symbol, i.e. WA3M in WA3M/xxxxxxxx/y full book code')
parser.add_argument(
'-f', '--file', help='Output file')
parser.add_argument(
'-q', '--quiet', action='store_true', help='Do not print to stdout')
args = parser.parse_args()
if args.file:
ou1tput = open(args.file,'w')
for book in generate_zfill(10**8):
bookstr = ''.join((args.court_symbol, book))
cs = checksum(bookstr)
bookfull = '{}/{}'.format(bookstr, cs)
if not args.quiet:
print(bookfull)
if args.file:
output.write('{}{}'.format(bookfull,'\n'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.