def create_lead(email_id):
 from email.utils import parseaddr
 from frappe.model.naming import get_default_naming_series
 (real_name, email_id) = parseaddr(email_id)
 if frappe.db.get_value(u'Lead', {u'email_id': email_id}):
  return
 lead = frappe.get_doc({u'doctype': u'Lead', u'email_id': email_id, u'lead_name': (real_name or email_id), u'status': u'Lead', u'naming_series': get_default_naming_series(u'Lead'), u'company': frappe.db.get_default(u'Company'), u'source': u'Email'})
 lead.insert()

def create_lead ( email_id ) : from email . utils import parseaddr from frappe . model . naming import get_default_naming_series ( real_name , email_id ) = parseaddr ( email_id ) if frappe . db . get_value ( u'Lead' , { u'email_id' : email_id } ) : return lead = frappe . get_doc ( { u'doctype' : u'Lead' , u'email_id' : email_id , u'lead_name' : ( real_name or email_id ) , u'status' : u'Lead' , u'naming_series' : get_default_naming_series ( u'Lead' ) , u'company' : frappe . db . get_default ( u'Company' ) , u'source' : u'Email' } ) lead . insert ( )
create a lead if it does not exist .