def get_company_name(s):
"""Takes out common domain suffixes e.g. com, net
:param s: domain name
:type s: string
:returns: sanitized string
:rtype: unicode string
"""
return (((s.replace('.com',' ')).replace('.net',' '))\
.replace('.org',' '))\
.replace('.',' ').replace('co',' ')
On Tuesday, August 29, 2017 at 6:46:32 PM UTC-7, Anthony wrote:
>
> What does the get_company_name() function look like?
>
> On Tuesday, August 29, 2017 at 6:22:57 PM UTC-4, Ben Lawrence wrote:
>>
>> 2.15.3-stable+timestamp.2017.08.07.07.32.04
>> (Running on nginx/1.10.3, Python 2.7.12)
>>
>>
>> Hi
>> I hesitate to ask this because it will betray my stupidity
>>
>> I have this:
>>
>> *c_rows = db(db.company.domain_tag == c_domain).select()*
>> if *len(c_rows)==0*: # add the company
>> c_id = db.company.insert(
>> name = get_company_name(c_domain),
>> e_mail = valid_email,
>> *domain_tag = c_domain )*
>> else: # length MUST be one
>> c_id = c_rows.last().id
>>
>> and this the error:
>>
>> File "applications/remail/models/scheduler.py", line 120, in
>> insert_company
>> domain_tag = c_domain )
>> File "/home/www-data/web2py/gluon/packages/dal/pydal/objects.py", line
>> 734, in insert
>> ret = self._db._adapter.insert(self, row.op_values())
>> File "/home/www-data/web2py/gluon/packages/dal/pydal/adapters/base.py",
>> line 486, in insert
>> raise e
>> IntegrityError: duplicate key value violates unique constraint
>> "company_domain_tag_key"
>> DETAIL: Key (domain_tag)=(platronics.com) already exists.
>>
>>
>> Wha?! if domain_tag is already there would len(c_rows) > 0 and so would
>> not try to insert the record?
>>
>>
>>
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.