-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add thriftbooks; f ix homedepot; fix generic
- Loading branch information
Showing
6 changed files
with
59 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
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 |
---|---|---|
|
@@ -11,5 +11,5 @@ | |
"imapclient==2.3.1", | ||
"mail-parser==3.9.3" | ||
], | ||
"version": "3.5.0" | ||
"version": "3.12.0" | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import logging | ||
import re | ||
import math | ||
|
||
from bs4 import BeautifulSoup | ||
from ..const import EMAIL_ATTR_BODY | ||
|
||
|
||
_LOGGER = logging.getLogger(__name__) | ||
ATTR_THRIFT_BOOKS = 'thrift_books' | ||
EMAIL_DOMAIN_THRIFT_BOOKS = 'thriftbooks' | ||
|
||
track_copy_pattern = re.compile(r"track my package", re.IGNORECASE) | ||
order_number_pattern = re.compile(r"Order #:\s+(\d+)") | ||
|
||
def parse_thrift_books(email): | ||
"""Parse thrift books tracking numbers.""" | ||
tracking_numbers = [] | ||
|
||
soup = BeautifulSoup(email[EMAIL_ATTR_BODY], 'html.parser') | ||
elements = soup.find_all('a') | ||
|
||
for element in elements: | ||
link = element.get('href') | ||
|
||
if not link: | ||
continue | ||
|
||
if 'spmailtechno' not in link: | ||
continue | ||
|
||
try: | ||
if re.search(track_copy_pattern, element.text): | ||
match = re.search(order_number_pattern, email[EMAIL_ATTR_BODY]) | ||
if match: | ||
tracking_numbers.append({ | ||
'link': link, | ||
'tracking_number': match.group(1) | ||
}) | ||
except: | ||
pass | ||
|
||
return tracking_numbers |
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