-
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.
- Loading branch information
Showing
5 changed files
with
101 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import logging | ||
import re | ||
|
||
from bs4 import BeautifulSoup | ||
from ..const import EMAIL_ATTR_BODY | ||
|
||
|
||
_LOGGER = logging.getLogger(__name__) | ||
ATTR_NINTENDO = 'nintendo' | ||
EMAIL_DOMAIN_NINTENDO = 'nintendo.com' | ||
|
||
|
||
def parse_nintendo(email): | ||
"""Parse Nintendo tracking numbers.""" | ||
tracking_numbers = [] | ||
|
||
soup = BeautifulSoup(email[EMAIL_ATTR_BODY], 'html.parser') | ||
links = [link.get('href') for link in soup.find_all('a')] | ||
for link in links: | ||
if not link: | ||
continue | ||
match = re.search('trackNums=(.*?)$', link) | ||
if match and match.group(1) not in tracking_numbers: | ||
tracking_numbers.append(match.group(1)) | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import logging | ||
import re | ||
|
||
from bs4 import BeautifulSoup | ||
from ..const import EMAIL_ATTR_BODY | ||
|
||
|
||
_LOGGER = logging.getLogger(__name__) | ||
ATTR_PLEDGEBOX = 'pledgebox' | ||
EMAIL_DOMAIN_PLEDGEBOX = 'pledgebox.com' | ||
|
||
|
||
def parse_pledgebox(email): | ||
"""Parse Pledge Box tracking numbers.""" | ||
tracking_numbers = [] | ||
|
||
soup = BeautifulSoup(email[EMAIL_ATTR_BODY], 'html.parser') | ||
lines = [element.text for element in soup.find_all('td')] | ||
for line in lines: | ||
if not line: | ||
continue | ||
match = re.search('^(\d{12})$', line) | ||
_LOGGER.error(match) | ||
|
||
if match and match.group(1) not in tracking_numbers: | ||
tracking_numbers.append(match.group(1)) | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import logging | ||
import re | ||
|
||
from bs4 import BeautifulSoup | ||
from ..const import EMAIL_ATTR_BODY, EMAIL_ATTR_SUBJECT | ||
|
||
|
||
_LOGGER = logging.getLogger(__name__) | ||
ATTR_UBIQUITI = 'ubiquiti' | ||
EMAIL_DOMAIN_UBIQUITI = 'shopifyemail.com' | ||
|
||
|
||
def parse_ubiquiti(email): | ||
"""Parse Ubiquiti tracking numbers.""" | ||
tracking_numbers = [] | ||
_LOGGER.error(email) | ||
|
||
# see if it's an shipped order email | ||
order_number_match = re.search('A shipment from order #(.*?) is on the way', email[EMAIL_ATTR_SUBJECT]) | ||
_LOGGER.error(order_number_match) | ||
if not order_number_match: | ||
return tracking_numbers | ||
|
||
order_number = order_number_match.group(1) | ||
|
||
soup = BeautifulSoup(email[EMAIL_ATTR_BODY], 'html.parser') | ||
links = [link.href for link in soup.find_all('a')] | ||
for link in links: | ||
if not link: | ||
continue | ||
match = re.search('/(\d{26})/orders/', link) | ||
if match and link not in tracking_numbers: | ||
tracking_numbers.append({ | ||
"tracking_number": order_number, | ||
"link": link, | ||
}) | ||
|
||
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