-
-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
abf83fc
commit c0424d2
Showing
3 changed files
with
50 additions
and
12 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
from waitress import serve | ||
|
||
from names_dataset import NameDataset, NameWrapper | ||
from names_dataset.emails import extract_names_from_email | ||
|
||
logger = logging.getLogger(__name__) | ||
logging.basicConfig( | ||
|
@@ -46,6 +47,37 @@ def str2bool(s: Union[bool, str]) -> bool: | |
return False | ||
|
||
|
||
@app.route('/split', methods=['GET']) | ||
def split(): | ||
try: | ||
req = request | ||
q = req.args.get('q') | ||
if q is None: | ||
return generate_output( | ||
'provide a parameter q, for example ' | ||
'[email protected] or philipperemy', status=False | ||
) | ||
else: | ||
first_name, last_name = extract_names_from_email(nd, q) | ||
if first_name is not None: | ||
result_first_name = nd.search(first_name)['first_name'] | ||
else: | ||
result_first_name = None | ||
if last_name is not None: | ||
result_last_name = nd.search(last_name)['last_name'] | ||
else: | ||
result_last_name = None | ||
result_first_name['name'] = first_name | ||
result_last_name['name'] = last_name | ||
result = { | ||
'first_name': result_first_name, | ||
'last_name': result_last_name | ||
} | ||
return generate_output({'result': result}, status=True) | ||
except Exception as e: | ||
return generate_output({'error': str(e)}, status=True) | ||
|
||
|
||
@app.route('/country_codes', methods=['GET']) | ||
def country_codes(): | ||
try: | ||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import unittest | ||
|
||
from names_dataset import NameDataset | ||
from names_dataset.emails import extract_names_from_email | ||
|
||
|
||
|
@@ -28,6 +29,9 @@ def test_1(self): | |
'[email protected]', | ||
'[email protected]', | ||
] | ||
inputs2 = [] | ||
for i in inputs: | ||
inputs2.append(i.split('@')[0]) | ||
|
||
outputs = [ | ||
[None, None], | ||
|
@@ -52,8 +56,9 @@ def test_1(self): | |
['philippe', 'remy'], | ||
] | ||
|
||
for input_, output_ in zip(inputs, outputs): | ||
first_name, last_name = extract_names_from_email(input_) | ||
nd = NameDataset() | ||
for input_, output_ in zip(inputs2, outputs): | ||
first_name, last_name = extract_names_from_email(nd, input_) | ||
print(input_) | ||
self.assertEqual(output_[0], first_name) | ||
self.assertEqual(output_[1], last_name) | ||
|