Initial release #1
2
.gitignore
vendored
2
.gitignore
vendored
@ -3,3 +3,5 @@ venv/
|
|||||||
|
|
||||||
__pycache__/
|
__pycache__/
|
||||||
*.py[cod]
|
*.py[cod]
|
||||||
|
|
||||||
|
config.py
|
||||||
|
84
main.py
Normal file
84
main.py
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
"""buyvm stock checker"""
|
||||||
|
import requests
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
|
from config import DISCORD_WEBHOOK
|
||||||
|
|
||||||
|
BASE_URL = 'https://my.frantech.ca/'
|
||||||
|
URLS = [
|
||||||
|
'https://my.frantech.ca/cart.php?gid=37', # Las Vegas
|
||||||
|
'https://my.frantech.ca/cart.php?gid=38', # New York
|
||||||
|
'https://my.frantech.ca/cart.php?gid=48', # Miami
|
||||||
|
'https://my.frantech.ca/cart.php?gid=39', # Luxembourg
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
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):
|
||||||
|
try:
|
||||||
|
response = requests.get(url)
|
||||||
|
response.raise_for_status()
|
||||||
|
except requests.RequestException as e:
|
||||||
|
print(f'error fetching {url}: {str(e)}')
|
||||||
|
return None
|
||||||
|
|
||||||
|
return response.text
|
||||||
|
|
||||||
|
|
||||||
|
def get_packages(html):
|
||||||
|
soup = BeautifulSoup(html, 'html.parser')
|
||||||
|
packages = []
|
||||||
|
|
||||||
|
package_elements = soup.find_all('div', class_='package')
|
||||||
|
for package_element in package_elements:
|
||||||
|
package = {}
|
||||||
|
|
||||||
|
package_name = package_element.find('h3', class_='package-name').text.strip()
|
||||||
|
package['name'] = package_name
|
||||||
|
|
||||||
|
package_quantity = package_element.find('div', class_='package-qty').text.strip()
|
||||||
|
package['qty'] = int(package_quantity.split()[0])
|
||||||
|
|
||||||
|
order_button = package_element.find('a', class_='btn-primary')
|
||||||
|
if order_button:
|
||||||
|
order_url = order_button['href']
|
||||||
|
package['url'] = BASE_URL + order_url
|
||||||
|
else:
|
||||||
|
package['url'] = ''
|
||||||
|
|
||||||
|
packages.append(package)
|
||||||
|
|
||||||
|
return packages
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
for url in URLS:
|
||||||
|
html = get_url(url)
|
||||||
|
|
||||||
|
packages = get_packages(html)
|
||||||
|
for package in packages:
|
||||||
|
if package['qty'] > 0:
|
||||||
|
send_notification({
|
||||||
|
"username": "stockbot-buyvm",
|
||||||
|
"embeds": [
|
||||||
|
{
|
||||||
|
"author": {
|
||||||
|
"name": "BuyVM",
|
||||||
|
},
|
||||||
|
"title": package['name'],
|
||||||
|
"url": package['url'],
|
||||||
|
"description": f"{package['qty']} in stock now!"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"content": "STOCK ALERT"
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
2
requirements.txt
Normal file
2
requirements.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
beautifulsoup4
|
||||||
|
requests
|
Loading…
Reference in New Issue
Block a user