Update powerball.py

The power ball now displays in red.
This commit is contained in:
Justin Oros
2024-11-18 11:09:11 -07:00
committed by GitHub
parent b81e5051c0
commit b1a65acbd0
+18 -14
View File
@@ -1,12 +1,17 @@
#!/usr/bin/python3 #!/usr/bin/python3
# Description: CLI to Powerball.com (prints previous winning results) # Description: CLI to https://powerball.com (prints previous winning results)
# Usage: python3 powerball.py # Usage: python3 powerball.py
# Author: Justin Oros # Author: Justin Oros
# Source: https://github.com/JustinOros # Source: https://github.com/JustinOros
# Dependencies: pip install requests beautifulsoup4
import requests import requests
from bs4 import BeautifulSoup as BS from bs4 import BeautifulSoup as BS
# ANSI escape codes for text formatting
RED = '\033[31m'
RESET = '\033[0m'
# Perform an HTTP GET request to the Powerball website # Perform an HTTP GET request to the Powerball website
powerballUrl = 'https://www.powerball.com/previous-results?gc=powerball' powerballUrl = 'https://www.powerball.com/previous-results?gc=powerball'
r = requests.get(powerballUrl, verify=True) r = requests.get(powerballUrl, verify=True)
@@ -15,28 +20,27 @@ r = requests.get(powerballUrl, verify=True)
soup = BS(r.text, 'html.parser') soup = BS(r.text, 'html.parser')
# Parse Drawing Dates # Parse Drawing Dates
drawingDates = soup.find_all('h5',class_='card-title') drawingDates = soup.find_all('h5', class_='card-title')
# Parse White Balls # Parse White Balls
whiteballs = soup.find_all('div',class_='form-control col white-balls item-powerball') whiteballs = soup.find_all('div', class_='form-control col white-balls item-powerball')
# Parse Power Balls # Parse Power Balls
powerballs = soup.find_all('div',class_='form-control col powerball item-powerball') powerballs = soup.find_all('div', class_='form-control col powerball item-powerball')
# Initalize and Set starting positions # Initalize and Set starting positions
whiteballPos = powerballPos = 0 whiteballPos = powerballPos = 0
# Loop through previous Drawing Dates # Loop through previous Drawing Dates
for date in drawingDates: for date in drawingDates:
# Print Drawing Date
print(date.text.strip() + ":", end=" ")
# Print Drawing Date # Print 5 White Balls
print (date.text + ":", end=" ") for i in range(0, 5):
print(whiteballs[whiteballPos].text.strip() + ",", end=" ")
whiteballPos += 1
# Print 5 White Balls # Print 1 Power Ball in red
for i in range(0,5): print(RED + powerballs[powerballPos].text.strip() + RESET)
print (whiteballs[whiteballPos].text + ",", end=" ") powerballPos += 1
whiteballPos += 1
# Print 1 Power Ball
print (powerballs[powerballPos].text)
powerballPos += 1