|
14 | 14 | from selenium.webdriver.firefox.options import Options
|
15 | 15 |
|
16 | 16 | from usps.storage import security
|
17 |
| -from . import USER_AGENT, Package, Step |
| 17 | +from . import USER_AGENT_CHROME, Package, Step |
18 | 18 | from .exceptions import MissingElement, NoTextInElement, InvalidElementType, StatusNotAvailable
|
19 | 19 |
|
20 | 20 | # Handle status mappings
|
|
34 | 34 | "arrived at usps facility": "At Facility",
|
35 | 35 | "departed usps facility": "Left Facility",
|
36 | 36 | "package acceptance pending": "Accepted",
|
37 |
| - "garage / other door / other location at address": "Delivered" |
| 37 | + "garage / other door / other location at address": "Delivered", |
| 38 | + "left with individual": "Delivered" |
38 | 39 | }
|
39 | 40 |
|
40 | 41 | # BS4 wrappers
|
@@ -76,6 +77,13 @@ def __generate_security(cls, url: str) -> str:
|
76 | 77 | with Status("[cyan]Generating cookies...", spinner = "arc"):
|
77 | 78 | options = Options()
|
78 | 79 | options.add_argument("--headless")
|
| 80 | + |
| 81 | + # Setup profile with user agent |
| 82 | + profile = webdriver.FirefoxProfile() |
| 83 | + profile.set_preference("general.useragent.override", USER_AGENT_CHROME) |
| 84 | + |
| 85 | + # Handle instance creation |
| 86 | + options.profile = profile |
79 | 87 | instance = webdriver.Firefox(options = options)
|
80 | 88 | instance.get(url)
|
81 | 89 |
|
@@ -108,7 +116,7 @@ def track_package(cls, tracking_number: str) -> Package:
|
108 | 116 |
|
109 | 117 | else:
|
110 | 118 | page = BeautifulSoup(
|
111 |
| - cls._session.get(url, cookies = cls._cookies, headers = {"User-Agent": USER_AGENT}).text, |
| 119 | + cls._session.get(url, cookies = cls._cookies, headers = {"User-Agent": USER_AGENT_CHROME}).text, |
112 | 120 | "html.parser"
|
113 | 121 | )
|
114 | 122 | if "originalHeaders" in str(page):
|
|
0 commit comments