Skip to content

Commit 7aeb2d6

Browse files
authored
Create main.py
1 parent c5d70a0 commit 7aeb2d6

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

day95/main.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import requests
2+
import json
3+
from datetime import datetime
4+
import time
5+
from random import randint
6+
7+
product_name = "RTX 3080 FE"
8+
URL = "https://www.bestbuy.ca/ecomm-api/availability/products?accept=application%2Fvnd.bestbuy.standardproduct.v1%2Bjson&accept-language=en-CA&locations=938%7C202%7C617%7C203%7C57%7C926%7C977%7C233%7C930%7C927%7C62%7C622%7C931%7C245%7C207%7C954%7C795%7C916%7C910%7C544%7C932%7C237%7C200%7C965%7C990%7C956%7C943%7C937%7C942%7C223%7C985%7C925&postalCode=M8W&skus=15463567"
9+
10+
headers = {
11+
'authority': 'www.bestbuy.ca',
12+
'pragma': 'no-cache',
13+
'cache-control': 'no-cache',
14+
'user-agent': 'Mozilla/5.0 (Windows NT 11.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4159.2 Safari/537.36',
15+
'accept': '*/*',
16+
'sec-fetch-site': 'same-origin',
17+
'sec-fetch-mode': 'cors',
18+
'sec-fetch-dest': 'empty',
19+
'referer': 'https://www.bestbuy.ca/en-ca/product/nvidia-geforce-rtx-3080-10gb-gddr6x-video-card/15463567',
20+
'accept-language': 'en-US,en;q=0.9'
21+
}
22+
23+
24+
def main():
25+
quantity = 0
26+
attempt = 0
27+
28+
while quantity < 1:
29+
response = requests.get(URL, headers=headers)
30+
response_formatted = json.loads(response.content.decode('utf-8-sig').encode('utf-8'))
31+
32+
quantity = response_formatted['availabilities'][0]['shipping']['quantityRemaining']
33+
34+
if quantity < 1:
35+
print(f"Time: {datetime.now()} | Attempt: {attempt}")
36+
attempt += 1
37+
# time.sleep(randint(0, 5))
38+
else:
39+
print(f"🚨 {product_name} available to ship\nQuantity: {quantity}")
40+
alert(f"🚨 {product_name} is available to ship\nQuantity: {quantity}\n{headers['referer']}")
41+
time.sleep(60)
42+
main()
43+
44+
45+
def alert(bot_message):
46+
bot_token = "INSTERT BOT TOKEN"
47+
bot_chat_id = "INSERT BOT CHAT ID"
48+
send_text = 'https://api.telegram.org/bot' + bot_token + '/sendMessage?chat_id=' + bot_chat_id \
49+
+ '&parse_mode=Markdown&text=' + bot_message
50+
51+
bot_response = requests.get(send_text)
52+
return bot_response.json()
53+
54+
55+
try:
56+
main()
57+
except:
58+
print('MaxRetryError')
59+
time.sleep(120)
60+
main()

0 commit comments

Comments
 (0)