Answered step by step
Verified Expert Solution
Question
1 Approved Answer
import phonenumbers from phonenumbers import geocoder from openpyxl import load _ workbook from yourapp.models import Customer from yourapp.serializers import CustomerSerializer # Validate data ( example
import phonenumbers
from phonenumbers import geocoder
from openpyxl import loadworkbook
from yourapp.models import Customer
from yourapp.serializers import CustomerSerializer
# Validate data example validation
def validatedatarow:
# Your validation logic here
pass
# Determine country from phone number
def getcountryfromphonephonenumber:
parsednumber phonenumbers.parsephonenumber, None
country geocoder.countrynamefornumberparsednumber, en
return country
# Read Excel file
excelfile "pathtoyourfilexlsx
wb loadworkbookexcelfile
ws wbactive
# Process each row and create Customer records
for row in wsiterrowsminrow valuesonlyTrue:
# Validate data
validatedatarow
# Determine country from phone number
country getcountryfromphonerow # Assuming phone number is in the third column
# Create a dictionary with the data
customerdata
'fullname': row
'email': row
'phonenumber': row
'country': country,
# Add other fields as needed
# Serialize data
serializer CustomerSerializerdatacustomerdata
if serializer.isvalid:
# Save the record
serializer.save
else:
printfError processing row: row Errors: serializererrors when this code is running it says phone numbers not found, what can I do step by step or how can I edit this code without phonenumbers?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started