mirror of
https://git.auk.su/Dinect/bonus-import-tools.git
synced 2025-12-28 18:10:01 +00:00
added user search
This commit is contained in:
22
app.py
22
app.py
@@ -63,6 +63,7 @@ for f in files:
|
||||
email_info = validate_email(email, check_deliverability=False)
|
||||
email = email_info.normalized
|
||||
except EmailNotValidError as e:
|
||||
email = None
|
||||
print(f'error in line: [{line_count}]- Invalid email: {email}')
|
||||
log_file.write(f'error in line: [{line_count}]- Invalid email: {email}\n')
|
||||
|
||||
@@ -75,16 +76,31 @@ for f in files:
|
||||
except ValueError as e:
|
||||
ret = f'Unexpected error in line: [{line_count}] {repr(e)}'
|
||||
log_file.write(f'{ret}\n')
|
||||
# Updating the database via the API
|
||||
user_found, user_id, user_card, purchases_url, data = get_user(card)
|
||||
|
||||
# Find user via the API
|
||||
# by card
|
||||
user_found_by_card, user_id, user_card, purchases_url, data = get_user(card)
|
||||
print(f'user_found_by_card {card}', user_found_by_card)
|
||||
# by phone
|
||||
phone = phone.replace('+', '')
|
||||
if not user_found_by_card:
|
||||
user_found_by_phone, user_id, user_card, purchases_url, data = get_user(phone, get_type='phone')
|
||||
print(f'user_found_by_phone {phone}', user_found_by_phone)
|
||||
|
||||
user_found = user_found_by_card or user_found_by_phone
|
||||
|
||||
# create new user if not found
|
||||
if not user_found:
|
||||
user_created, data = new_user('Иван тестов', '79039426495')
|
||||
user_created, data = new_user(
|
||||
full_name=nickname, phone=phone, gender=None, foreign_card=None, email=email,
|
||||
)
|
||||
if user_created:
|
||||
# log_file.write(f'error in line: [{line_count}]- Invalid user data: {data}\n')
|
||||
print('User created with', data['ID'], data['DIN'])
|
||||
else:
|
||||
log_file.write(f'error in line: [{line_count}]- Invalid user data: {data}\n')
|
||||
else:
|
||||
print('User found with', user_id, user_card, purchases_url)
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user