ADD Postal Code, TODO
This commit is contained in:
@ -329,6 +329,31 @@ def fix_typo(call, fullname, verbose=1):
|
||||
fix_typo.lines = None
|
||||
fix_typo.spaces = []
|
||||
|
||||
def isinteger(s):
|
||||
for char in s:
|
||||
if not char.isdigit():
|
||||
return False
|
||||
return True
|
||||
|
||||
def call_change_city(location):
|
||||
match location:
|
||||
case 'Groß Schweinbarth':
|
||||
city = location
|
||||
postal_code = 2221
|
||||
|
||||
|
||||
def call_postal_code(location):
|
||||
|
||||
if location == '' or location[0] == '*':
|
||||
return ''
|
||||
p = location.split(' ',1)
|
||||
if isinteger(p[0]) and int(p[0]) > 1000 and int(p[0]) < 10000:
|
||||
postal_code = p[0]
|
||||
city = p[1]
|
||||
else:
|
||||
postal_code, city = call_change_city(location)
|
||||
return postal_code
|
||||
|
||||
def call_data_record(line, mod_date, verbose, cur):
|
||||
|
||||
# we have to split the record with a cost-intensive regular expression
|
||||
@ -381,26 +406,36 @@ def call_data_record(line, mod_date, verbose, cur):
|
||||
print(f'Call: {call}, Name: {fullname}, Gender: {gender}')
|
||||
else:
|
||||
print(f'Call: {call}, First Name: {firstname}, Surname: {surname}, Gender: {gender}')
|
||||
|
||||
print(f'Location: {location}, Address: {address}, Permit: {permit_class}')
|
||||
|
||||
created = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
||||
call_data_record.cnt += 1 # increment the User_id
|
||||
user_id = call_data_record.cnt
|
||||
# print(created)
|
||||
statement = "INSERT INTO `callbook_user`(`user_id`,`call`,`firstname`,`surname`,`gender`,`created`,`modified`) VALUES (%s, %s, %s, %s, %s, %s, %s)"
|
||||
data = (user_id,call,firstname,surname,gender,created,created)
|
||||
|
||||
try:
|
||||
# cur.execute(f"INSERT INTO `callbook_user` (`call`,`firstname`,`surname`,\
|
||||
# `created`,`created_by`,`modified`,`modified_by`,`active`)\
|
||||
# VALUES ('{call}','{firstname}','{surname}','{created}','0','{created}','0','{created}');")
|
||||
# cur.execute(f'INSERT INTO `callbook_user` (`call`) VALUES ("{call}");')
|
||||
cur.execute(statement, data)
|
||||
except mariadb.Error as e:
|
||||
print(f'\n[WARN] MySQLError during execute statement\n\tArgs: {e.args}')
|
||||
except Exception as e:
|
||||
print('Error: {}'.format(e), file=sys.stderr)
|
||||
statement = f'SELECT `call`, `firstname`, `surname`, `gender` FROM `callbook_user` WHERE `call` = "{call}" AND `active` = 1'
|
||||
cur.execute(statement)
|
||||
result = cur.fetchall()
|
||||
if not result:
|
||||
postal_code = call_postal_code(location)
|
||||
statement = "INSERT INTO `callbook_address`(`location`,`address`,`postal_code`) VALUES (%s,%s,%s)"
|
||||
data = (location,address,postal_code)
|
||||
try: cur.execute(statement, data)
|
||||
except mariadb.Error as e:
|
||||
print(f'\n[WARN] MySQLError during execute statement\n\tArgs: {e.args}')
|
||||
except Exception as e:
|
||||
print('Error: {}'.format(e), file=sys.stderr)
|
||||
|
||||
statement = "INSERT INTO `callbook_user`(`user_id`,`call`,`firstname`,`surname`,`gender`,`created`,`modified`,`address_id`) VALUES (%s, %s, %s, %s, %s, %s, %s, LAST_INSERT_ID())"
|
||||
data = (user_id,call,firstname,surname,gender,created,created)
|
||||
try:
|
||||
cur.execute(statement, data)
|
||||
except mariadb.Error as e:
|
||||
print(f'\n[WARN] MySQLError during execute statement\n\tArgs: {e.args}')
|
||||
except Exception as e:
|
||||
print('Error: {}'.format(e), file=sys.stderr)
|
||||
else:
|
||||
for r in result:
|
||||
print(f'Call: {call} {firstname} {surname} {gender} <- ')
|
||||
|
||||
call_data_record.cnt = 0
|
||||
|
||||
|
Reference in New Issue
Block a user