forked from druyang/amazon-PS5-automation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
59 lines (52 loc) · 1.84 KB
/
main.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
# coding: utf-8
from dotenv import load_dotenv
from logger import logger
from selenium import webdriver
from selenium.webdriver import DesiredCapabilities
import amazonBot
load_dotenv(verbose=True)
dotenv_path = '.env'
load_dotenv(dotenv_path)
def launch():
d = DesiredCapabilities.CHROME
d['loggingPrefs'] = {'performance': 'ALL'}
opt = webdriver.ChromeOptions()
opt.add_argument("--disable-xss-auditor")
opt.add_argument("--disable-web-security")
opt.add_argument('--disable-dev-shm-usage')
opt.add_argument("--allow-running-insecure-content")
opt.add_argument("--no-sandbox")
opt.add_argument("--remote-debugging-port=921")
opt.add_argument("--disable-webgl")
opt.add_argument("--disable-popup-blocking")
browser = webdriver.Chrome('.\chromedriver', options=opt, desired_capabilities=d)
# opt.add_argument("--user-data-dir=selenium") # added this option to use cookies, you may need to perform initial login within Selenium
browser.implicitly_wait(10)
browser.set_page_load_timeout(5)
logger.info('Started Chrome')
return browser
if __name__ == '__main__':
# Launch selenium
try:
b = launch()
b.get(amazonBot.ITEM_URL)
except Exception as inst:
logger.error('Failed to open browser: {}'.format(format(inst)))
# Item purchasing logic
try:
done = False
while(not done):
try:
# Navigate to the item and buy if checks pass
if amazonBot.purchase_item(b):
done = True
logger.info("Successfully purchased item")
except Exception as e:
logger.error('ERROR: {}'.format(e))
finally:
logger.info('Closing Chromium')
try:
b.close()
except BaseException:
pass
logger.info('Closed Chromium')