stockbot-buyvm/main.py

65 lines
1.7 KiB
Python
Raw Normal View History

2023-12-02 19:49:46 +00:00
"""buyvm stock checker"""
2023-12-02 20:33:07 +00:00
import requests
2023-12-02 19:49:46 +00:00
from bs4 import BeautifulSoup
2023-12-02 20:33:07 +00:00
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 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
2023-12-02 19:49:46 +00:00
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'] = package_quantity
order_button = package_element.find('a', class_='btn-primary')
if order_button:
order_url = order_button['href']
2023-12-02 20:33:07 +00:00
package['url'] = BASE_URL + order_url
2023-12-02 19:49:46 +00:00
else:
package['url'] = ''
packages.append(package)
return packages
def main():
2023-12-02 20:33:07 +00:00
for url in URLS:
html = get_url(url)
packages = get_packages(html)
for package in packages:
print('Package Name:', package['name'])
print('Package Quantity:', package['qty'])
print('Order URL:', package['url'])
print('---------------------------')
2023-12-02 19:49:46 +00:00
if __name__ == '__main__':
main()