-
Notifications
You must be signed in to change notification settings - Fork 12
/
config.py
134 lines (122 loc) · 4.35 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
from selenium.webdriver.common.by import By
import toml
CONF_PATH = 'conf.toml'
USER_DATA_DIR = 'chrome-user-data'
BASE_URL = 'https://www.amazon.com/'
try:
options = toml.load(CONF_PATH)['options']
if options.get('use_smile'):
BASE_URL = 'https://smile.amazon.com/'
if options.get('chrome_data_dir'):
USER_DATA_DIR = options['chrome_data_dir']
except Exception:
pass
NAV_TIMEOUT = 20
INTERVAL = 25
VALID_SERVICES = [
'Whole Foods',
'Amazon Fresh'
]
class Patterns:
AUTH_URL = BASE_URL + 'ap/'
NOT_LOGGED_IN = "Hello, Sign in"
OOS_URL = 'gp/buy/itemselect/handlers/display.html'
OOS = "This item is no longer available"
THROTTLE_URL = 'throttle.html'
NO_SLOTS_MULTI = "No.*delivery windows are available"
class Locators:
LOGIN = (By.ID, 'nav-link-accountList')
OOS_ITEM = (By.XPATH, "//*[contains(@class, ' item-row')]")
OOS_CONTINUE = (By.XPATH, "//*[@name='continue-bottom']")
CART_ITEMS = (By.XPATH, "//div[@data-name='Active Items']"
"/*[contains(@class, 'sc-list-item')]")
THROTTLE_CONTINUE = (By.XPATH, "//*[contains(@id, 'throttle') and "
"@role='button']")
PAYMENT_ROW = (By.XPATH, "//*[starts-with(@class, 'payment-row')]")
class SlotLocators:
def __init__(self, slot_type='single'):
if slot_type == 'single':
self.CONTAINER = (By.CLASS_NAME, 'ufss-slotselect-container')
self.SLOT = (
By.XPATH,
"//*[contains(@class, 'ufss-slot ') and "
"contains(@class, 'ufss-available')]"
)
self.CONTINUE = (
By.XPATH,
"//*[contains(@class, 'ufss-overview-continue-button')]"
)
elif slot_type == 'multi':
self.CONTAINER = (By.ID, 'slot-container-root')
self.SLOT = (
By.XPATH,
"//*[starts-with(@id, 'slot-button-root-20') and "
"not(contains(@class, 'disabled'))]"
)
self.CONTINUE = (
By.XPATH,
"//input[@class='a-button-text a-declarative' and "
"@type='submit']"
)
else:
raise ValueError("Unrecognized slot type '{}'".format(slot_type))
class SiteConfig:
def __init__(self, service):
if service not in VALID_SERVICES:
raise ValueError(
"Invalid service '{}'\n Services implemented: \n{}".format(
service, VALID_SERVICES
)
)
self.service = service
self.BASE_URL = BASE_URL
self.Locators = Locators()
self.Patterns = Patterns()
self.routes = {}
self.routes['SLOT_SELECT'] = {
'route_start': BASE_URL,
'waypoints': [
(
(By.ID, 'nav-cart'),
'gp/cart/view.html'
),
(
(By.XPATH, "//*[contains(text(),'Checkout {}')]/..".format(
service
)),
'alm/byg'
),
(
(By.XPATH, "//span[contains(@class, 'byg-continue-button')]"),
'alm/substitution'
),
(
(By.ID, 'subsContinueButton'),
'gp/buy/shipoptionselect/handlers/display.html'
)
]
}
self.routes['CHECKOUT'] = {
'route_start': BASE_URL + 'gp/buy/shipoptionselect/handlers/display.html',
'waypoints': [
(
[SlotLocators().CONTINUE, SlotLocators('multi').CONTINUE],
'gp/buy/payselect/handlers/display.html'
),
(
(By.ID, 'continue-top'),
'gp/buy/spc/handlers/display.html',
'select_payment_method' # function to be called before nav
),
(
(By.XPATH, "//input[contains(@class, 'place-your-order-button')]"),
'gp/buy/thankyou/handlers/display.html'
)
]
}
@property
def cart_endpoint(self):
if self.service == 'Amazon Fresh':
return 'cart/fresh'
else:
return 'cart/localmarket'