This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pip install phonenumbers | |
#pip install validate_email | |
import phonenumbers | |
from phonenumbers import carrier | |
from phonenumbers.phonenumberutil import number_type | |
from validate_email import validate_email | |
import pickle | |
userdata = r'E:\Code_Repo\messaging\phonename.dictionary' | |
useremail = r'E:\Code_Repo\messaging\phoneemail.dictionary' | |
phonename = {} | |
phoneemail = {} | |
class Person: | |
def __init__(self,name,phonenumber,emailaddress): | |
#Constructor | |
self.name = name | |
self.phonenumber = phonenumber | |
self.emailaddress = emailaddress | |
def validate_phonenumber(self): | |
#Phone number validation | |
status = carrier._is_mobile(number_type(phonenumbers.parse(self.phonenumber))) | |
return status | |
def validate_email_addr(self): | |
#Email validation | |
is_valid = validate_email(self.emailaddress) | |
return is_valid | |
def Save_data(): | |
guestuser1 =Person('Raj','+91-7406947660','siva@siva.com') | |
guestuser2 =Person('Raja','+91-7406947760','siva1@siva.com') | |
print(guestuser1.validate_email_addr()) | |
print(guestuser1.validate_phonenumber()) | |
#Save data | |
phonename[guestuser1.phonenumber] = guestuser1.name | |
phoneemail[guestuser1.emailaddress] = guestuser1.emailaddress | |
phonename[guestuser2.phonenumber] = guestuser2.name | |
phoneemail[guestuser2.emailaddress] = guestuser2.emailaddress | |
#Persist data | |
with open(userdata, 'wb') as config_dictionary_file: | |
pickle.dump(phonename, config_dictionary_file) | |
with open(useremail, 'wb') as config_dictionary_file: | |
pickle.dump(phoneemail, config_dictionary_file) | |
def Read_data(): | |
#read data | |
with open(userdata, 'rb') as config_dictionary_file: | |
userdatavalues = pickle.load(config_dictionary_file) | |
for key,datavalues in userdatavalues.items(): | |
print(key) | |
print(datavalues) | |
with open(useremail, 'rb') as config_dictionary_file: | |
useremailvalues = pickle.load(config_dictionary_file) | |
for key,datavalues in useremailvalues.items(): | |
print(key) | |
print(datavalues) | |
Save_data() | |
Read_data() | |
No comments:
Post a Comment