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_info = validate_email(email, check_deliverability=False)
|
||||||
email = email_info.normalized
|
email = email_info.normalized
|
||||||
except EmailNotValidError as e:
|
except EmailNotValidError as e:
|
||||||
|
email = None
|
||||||
print(f'error in line: [{line_count}]- Invalid email: {email}')
|
print(f'error in line: [{line_count}]- Invalid email: {email}')
|
||||||
log_file.write(f'error in line: [{line_count}]- Invalid email: {email}\n')
|
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:
|
except ValueError as e:
|
||||||
ret = f'Unexpected error in line: [{line_count}] {repr(e)}'
|
ret = f'Unexpected error in line: [{line_count}] {repr(e)}'
|
||||||
log_file.write(f'{ret}\n')
|
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:
|
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:
|
if user_created:
|
||||||
# log_file.write(f'error in line: [{line_count}]- Invalid user data: {data}\n')
|
# log_file.write(f'error in line: [{line_count}]- Invalid user data: {data}\n')
|
||||||
print('User created with', data['ID'], data['DIN'])
|
print('User created with', data['ID'], data['DIN'])
|
||||||
else:
|
else:
|
||||||
log_file.write(f'error in line: [{line_count}]- Invalid user data: {data}\n')
|
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)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ def get_user(search_id, get_type='auto', headers=None) -> tuple:
|
|||||||
# return False, r.text
|
# return False, r.text
|
||||||
|
|
||||||
|
|
||||||
def new_user(nickname, phone, gender=None, foreign_card=None, headers=None):
|
def new_user(full_name, phone, gender=None, foreign_card=None, email=None, headers=None):
|
||||||
"""
|
"""
|
||||||
A function that creates a new user with optional headers.
|
A function that creates a new user with optional headers.
|
||||||
|
|
||||||
@@ -91,11 +91,12 @@ def new_user(nickname, phone, gender=None, foreign_card=None, headers=None):
|
|||||||
tuple: A tuple containing a boolean indicating the success of the request and the JSON response.
|
tuple: A tuple containing a boolean indicating the success of the request and the JSON response.
|
||||||
If the request is successful, the boolean is True and the JSON response is returned.
|
If the request is successful, the boolean is True and the JSON response is returned.
|
||||||
If the request is unsuccessful, the boolean is False and the JSON response is returned.
|
If the request is unsuccessful, the boolean is False and the JSON response is returned.
|
||||||
|
:param email:
|
||||||
:param gender:
|
:param gender:
|
||||||
:param foreign_card:
|
:param foreign_card:
|
||||||
:param headers:
|
:param headers:
|
||||||
:param phone:
|
:param phone:
|
||||||
:param nickname :
|
:param full_name :
|
||||||
"""
|
"""
|
||||||
if headers is None:
|
if headers is None:
|
||||||
headers = HEADERS
|
headers = HEADERS
|
||||||
@@ -104,8 +105,9 @@ def new_user(nickname, phone, gender=None, foreign_card=None, headers=None):
|
|||||||
|
|
||||||
params = {
|
params = {
|
||||||
# "short_name": nickname,
|
# "short_name": nickname,
|
||||||
"full_name": nickname,
|
"full_name": full_name,
|
||||||
"phone": phone,
|
"phone": phone,
|
||||||
|
"email": email,
|
||||||
# "gender": gender,
|
# "gender": gender,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user