forked from MrTpat/newegg-bot-public
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscanner.py
67 lines (63 loc) · 2.2 KB
/
scanner.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
import requests
import buyBot
import sys
import colors
import configparser
import time
from notify import notify
def inStock(s_id: str, price: float) -> bool:
url = 'https://www.newegg.com/product/api/ProductRealtime?ItemNumber=' + s_id
try:
r = requests.get(url)
except:
colors.printFail('Failed to make request to instock API, trying again...')
return inStock(s_id, price)
if r.status_code == 200:
try:
j = r.json()
inStock = j['MainItem']['Instock']
acceptPrice = j['MainItem']['FinalPrice'] <= price
if inStock and acceptPrice:
colors.printSuccess('ITEM IN STOCK FOR GOOD PRICE!!!')
elif inStock and not acceptPrice:
colors.printFail('Item in stock, price too high...')
else:
colors.printInfo('Item not in stock...')
return inStock and acceptPrice
except:
colors.printFail('Invalid response, IP block?')
return False
else:
colors.printFail('Unsuccessful request made, IP block?')
return False
profile = ''
if len(sys.argv) == 1:
profile = 'TEST'
colors.printInfo('Running in test mode...')
else:
profile = sys.argv[1]
colors.printFail('CONFIRM YOU WANT TO RUN THE ACTUAL SCRIPT FOR CONFIG: ' + profile)
input()
config = configparser.ConfigParser()
config.read('config.ini')
secondary_product_id = config[profile]['secondaryId']
price = float(config[profile]['priceThreshold'])
phoneNumber = config['CREDENTIALS']['phoneNumber']
email = config['CREDENTIALS']['email']
emailPassword = config['CREDENTIALS']['emailPassword']
server = config['CREDENTIALS']['server']
bought = False
iterationsUntilCookieTest = 90
iterations = 0
while not bought:
if iterations == iterationsUntilCookieTest:
notify("Need to refresh cookies!", email, emailPassword, server, phoneNumber)
colors.printFail("Need to refresh cookies!")
iterations = 0
if inStock(secondary_product_id, price):
buyBot.main(profile)
bought = True
notify("Bought item. Check newegg.", email, emailPassword, server, phoneNumber)
else:
iterations = iterations + 1
time.sleep(30)