Answered step by step
Verified Expert Solution
Link Copied!

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 load_workbook
from yourapp.models import Customer
from yourapp.serializers import CustomerSerializer
# Validate data (example validation)
def validate_data(row):
# Your validation logic here
pass
# Determine country from phone number
def get_country_from_phone(phone_number):
parsed_number = phonenumbers.parse(phone_number, None)
country = geocoder.country_name_for_number(parsed_number, "en")
return country
# Read Excel file
excel_file = "path/to/your/file.xlsx"
wb = load_workbook(excel_file)
ws = wb.active
# Process each row and create Customer records
for row in ws.iter_rows(min_row=2, values_only=True):
# Validate data
validate_data(row)
# Determine country from phone number
country = get_country_from_phone(row[2]) # Assuming phone number is in the third column
# Create a dictionary with the data
customer_data ={
'full_name': row[0],
'email': row[1],
'phone_number': row[2],
'country': country,
# Add other fields as needed
}
# Serialize data
serializer = CustomerSerializer(data=customer_data)
if serializer.is_valid():
# Save the record
serializer.save()
else:
print(f"Error processing row: {row}, Errors: {serializer.errors}") 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application Development And Administration

Authors: Mannino Michael

5th Edition

0983332401, 978-0983332404

More Books

Students also viewed these Databases questions