CHG callbook_address SQL table

This commit is contained in:
Thomas Kuschel 2024-06-30 14:05:55 +02:00
parent 7dfbeb3b79
commit e77006bf76
2 changed files with 65 additions and 12 deletions

View File

@ -12,7 +12,7 @@ CREATE TABLE IF NOT EXISTS `callbook_user`(
`modified` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
`modified_by` INT(10) UNSIGNED NOT NULL DEFAULT 0,
`active` TINYINT(1) NOT NULL DEFAULT 1 COMMENT 'the user is active',
`inactive` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
`inactive` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT 'old inactive call since...',
`address_id` INT(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'link to id of callbook_adress',
PRIMARY KEY(`id`)
) AUTO_INCREMENT=0
@ -23,14 +23,21 @@ CREATE TABLE IF NOT EXISTS `callbook_address`(
`id` SERIAL,
`location` VARCHAR(200) NOT NULL DEFAULT '' COMMENT 'original location from the import',
`address` VARCHAR(200) NOT NULL DEFAULT '' COMMENT 'original address from the import',
`postal_code` VARCHAR(20) NOT NULL DEFAULT '' COMMENT 'also known as Zip code, "Postleitzahl"',
`org_city` VARCHAR(200) NOT NULL DEFAULT '' COMMENT 'original city from the import',
`city` VARCHAR(200) NOT NULL DEFAULT '' COMMENT 'calculated city from the original city',
`status` INT(1) NOT NULL DEFAULT '0' COMMENT 'Status of the address: 0...invalid, -1...uncertain, -2...in progress, 1...computed (valid)',
`postal_code` VARCHAR(20) NOT NULL DEFAULT '' COMMENT 'also known as Zip code, "Postleitzahl", computed from location',
`city` VARCHAR(200) NOT NULL DEFAULT '' COMMENT 'city, computed from location',
`street` VARCHAR(200) NOT NULL DEFAULT '' COMMENT 'street, computed from address',
`federal_state_code` TINYINT NOT NULL DEFAULT -1
COMMENT 'Austria: 0...outside, 1...Vienna, 2...Salzburg, 3...Lower Austria, 4...Burgenland, 5...Upper Austria, 6...Styria, 7...Tyrol, 8...Carinthia, 9...Vorarlberg',
`lat` DOUBLE NOT NULL DEFAULT 0.0 COMMENT 'latitude',
`long` DOUBLE NOT NULL DEFAULT 0.0 COMMENT 'longitude',
`qth` VARCHAR(20) NOT NULL DEFAULT '' COMMENT 'Maidenhead locator, QTH locator',
`created` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
`created_by` INT(10) UNSIGNED NOT NULL DEFAULT 0,
`modified` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
`modified_by` INT(10) UNSIGNED NOT NULL DEFAULT 0,
`active` TINYINT(1) NOT NULL DEFAULT 1 COMMENT 'the address is active',
`inactive` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT 'old inactive address, since...',
PRIMARY KEY(`id`)
) AUTO_INCREMENT=0
DEFAULT CHARSET=utf8mb4

View File

@ -335,14 +335,58 @@ def isinteger(s):
return False
return True
def call_change_city(location):
match location:
case 'Groß Schweinbarth':
city = location
postal_code = 2221
def call_change_city(location, address, verbose):
post_file = '.post_code'
path = get_active_path(post_file)
if os.path.exists(path) and not call_change_city.lines:
try:
with open(path, 'r') as file:
call_change_city.lines = file.readlines()
if verbose > 0:
print(f'File "{post_file}":')
for line in call_change_city.lines:
print(f'>> {line.rstrip()}')
print('>> ** EOF **')
# print(f'{path}')
except FileNotFoundError:
print(f'The file {path} was not found.')
except Exception as e:
print(f'An error occurred: {e}')
else:
return 0,'',''
postal_code = 0
city = location
street = address
for line in call_change_city.lines:
locpart = line.split(' ',1)
if len(locpart) < 2:
continue
citypart = locpart[1].split('|',1)
if (citypart[0] != location): # A hit? Else...
continue
postal_code = locpart[0]
city = citypart[0]
print(f'PLZ: {postal_code}, City: {city}')
if len(citypart) > 0:
street = citypart[1]
exchange = citypart[1].split('#')
city = exchange[0]
if len(exchange) > 1:
city = exchange[1]
if len(exchange) > 2:
street = exchange[2]
print(f'postal_code: {postal_code}, city: {city}, street: {street}')
return postal_code, city, street
call_change_city.lines = None
def call_postal_code(location):
def call_postal_code(location, address, verbose):
if location == '' or location[0] == '*':
return ''
@ -351,7 +395,9 @@ def call_postal_code(location):
postal_code = p[0]
city = p[1]
else:
postal_code, city = call_change_city(location)
postal_code, city, street = call_change_city(location, address, verbose)
return postal_code
def call_data_record(line, mod_date, verbose, cur):
@ -416,7 +462,7 @@ def call_data_record(line, mod_date, verbose, cur):
cur.execute(statement)
result = cur.fetchall()
if not result:
postal_code = call_postal_code(location)
postal_code = call_postal_code(location, address, verbose)
statement = "INSERT INTO `callbook_address`(`location`,`address`,`postal_code`) VALUES (%s,%s,%s)"
data = (location,address,postal_code)
try: cur.execute(statement, data)