Initial release #1

Merged
agatha merged 3 commits from dev into master 2023-12-02 20:54:04 +00:00
2 changed files with 27 additions and 5 deletions
Showing only changes of commit f82b47ac8b - Show all commits

2
.gitignore vendored
View File

@ -3,3 +3,5 @@ venv/
__pycache__/ __pycache__/
*.py[cod] *.py[cod]
config.py

30
main.py
View File

@ -2,6 +2,8 @@
import requests import requests
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
from config import DISCORD_WEBHOOK
BASE_URL = 'https://my.frantech.ca/' BASE_URL = 'https://my.frantech.ca/'
URLS = [ URLS = [
'https://my.frantech.ca/cart.php?gid=37', # Las Vegas 'https://my.frantech.ca/cart.php?gid=37', # Las Vegas
@ -11,6 +13,13 @@ URLS = [
] ]
def send_notification(payload):
try:
requests.post(DISCORD_WEBHOOK, json=payload)
except requests.RequestException as e:
print(f'error sending notification: {str(e)}')
def get_url(url): def get_url(url):
try: try:
response = requests.get(url) response = requests.get(url)
@ -34,7 +43,7 @@ def get_packages(html):
package['name'] = package_name package['name'] = package_name
package_quantity = package_element.find('div', class_='package-qty').text.strip() package_quantity = package_element.find('div', class_='package-qty').text.strip()
package['qty'] = package_quantity package['qty'] = int(package_quantity.split()[0])
order_button = package_element.find('a', class_='btn-primary') order_button = package_element.find('a', class_='btn-primary')
if order_button: if order_button:
@ -54,10 +63,21 @@ def main():
packages = get_packages(html) packages = get_packages(html)
for package in packages: for package in packages:
print('Package Name:', package['name']) if package['qty'] > 0:
print('Package Quantity:', package['qty']) send_notification({
print('Order URL:', package['url']) "username": "stockbot-buyvm",
print('---------------------------') "embeds": [
{
"author": {
"name": "BuyVM",
},
"title": package['name'],
"url": package['url'],
"description": f"{package['qty']} in stock now!"
}
],
"content": "STOCK ALERT"
})
if __name__ == '__main__': if __name__ == '__main__':