2023-07-11 15:28:57 -07:00
|
|
|
#!/usr/bin/python3
|
2024-11-18 11:19:56 -07:00
|
|
|
# Description: CLI to https://powerball.com (prints winning powerball results)
|
|
|
|
|
# Usage: python3 powerball.py [-List|-L]
|
2023-07-11 15:28:57 -07:00
|
|
|
# Author: Justin Oros
|
|
|
|
|
# Source: https://github.com/JustinOros
|
|
|
|
|
|
|
|
|
|
import requests
|
|
|
|
|
from bs4 import BeautifulSoup as BS
|
2024-11-18 11:19:56 -07:00
|
|
|
import sys
|
2023-07-11 15:28:57 -07:00
|
|
|
|
2024-11-18 11:09:11 -07:00
|
|
|
# ANSI escape codes for text formatting
|
|
|
|
|
RED = '\033[31m'
|
|
|
|
|
RESET = '\033[0m'
|
|
|
|
|
|
2023-07-11 15:28:57 -07:00
|
|
|
# Perform an HTTP GET request to the Powerball website
|
|
|
|
|
powerballUrl = 'https://www.powerball.com/previous-results?gc=powerball'
|
|
|
|
|
r = requests.get(powerballUrl, verify=True)
|
|
|
|
|
|
|
|
|
|
# Parse out our HTML using BeautifulSoup
|
|
|
|
|
soup = BS(r.text, 'html.parser')
|
|
|
|
|
|
|
|
|
|
# Parse Drawing Dates
|
2024-11-18 11:09:11 -07:00
|
|
|
drawingDates = soup.find_all('h5', class_='card-title')
|
2023-07-11 15:28:57 -07:00
|
|
|
|
|
|
|
|
# Parse White Balls
|
2024-11-18 11:09:11 -07:00
|
|
|
whiteballs = soup.find_all('div', class_='form-control col white-balls item-powerball')
|
2023-07-11 15:28:57 -07:00
|
|
|
|
2024-11-18 11:09:11 -07:00
|
|
|
# Parse Power Balls
|
|
|
|
|
powerballs = soup.find_all('div', class_='form-control col powerball item-powerball')
|
2023-07-11 15:28:57 -07:00
|
|
|
|
|
|
|
|
# Initalize and Set starting positions
|
|
|
|
|
whiteballPos = powerballPos = 0
|
|
|
|
|
|
2024-11-18 11:19:56 -07:00
|
|
|
# Check for arguments to decide if we should print all or just the first line
|
|
|
|
|
if len(sys.argv) > 1 and sys.argv[1].lower() in ['-list', '-l']:
|
|
|
|
|
# If -List or -L is present, print all lines
|
|
|
|
|
print_all = True
|
|
|
|
|
else:
|
|
|
|
|
# If no arguments or other arguments, print only the first line
|
|
|
|
|
print_all = False
|
|
|
|
|
|
|
|
|
|
# Function to print a single line of results
|
|
|
|
|
def print_line(date, whiteballPos, powerballPos):
|
2024-11-18 11:09:11 -07:00
|
|
|
print(date.text.strip() + ":", end=" ")
|
2023-07-11 15:28:57 -07:00
|
|
|
|
2024-11-18 11:09:11 -07:00
|
|
|
# Print 5 White Balls
|
|
|
|
|
for i in range(0, 5):
|
|
|
|
|
print(whiteballs[whiteballPos].text.strip() + ",", end=" ")
|
|
|
|
|
whiteballPos += 1
|
|
|
|
|
|
|
|
|
|
# Print 1 Power Ball in red
|
|
|
|
|
print(RED + powerballs[powerballPos].text.strip() + RESET)
|
|
|
|
|
powerballPos += 1
|
2024-11-18 11:19:56 -07:00
|
|
|
|
|
|
|
|
return whiteballPos, powerballPos
|
|
|
|
|
|
|
|
|
|
# Loop through previous Drawing Dates and print results
|
|
|
|
|
if print_all:
|
|
|
|
|
# Print all lines if -List or -L is present
|
|
|
|
|
for date in drawingDates:
|
|
|
|
|
whiteballPos, powerballPos = print_line(date, whiteballPos, powerballPos)
|
|
|
|
|
else:
|
|
|
|
|
# Print only the first line
|
|
|
|
|
if drawingDates:
|
|
|
|
|
print_line(drawingDates[0], whiteballPos, powerballPos)
|