Update powerball.py

Only display the latest winning numbers unless -List or -L argument is specified.
This commit is contained in:
Justin Oros
2024-11-18 11:19:56 -07:00
committed by GitHub
parent b1a65acbd0
commit 5c6c431244
+25 -6
View File
@@ -1,12 +1,12 @@
#!/usr/bin/python3 #!/usr/bin/python3
# Description: CLI to https://powerball.com (prints previous winning results) # Description: CLI to https://powerball.com (prints winning powerball results)
# Usage: python3 powerball.py # Usage: python3 powerball.py [-List|-L]
# 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
import sys
# ANSI escape codes for text formatting # ANSI escape codes for text formatting
RED = '\033[31m' RED = '\033[31m'
@@ -31,9 +31,16 @@ powerballs = soup.find_all('div', class_='form-control col powerball item-powerb
# Initalize and Set starting positions # Initalize and Set starting positions
whiteballPos = powerballPos = 0 whiteballPos = powerballPos = 0
# Loop through previous Drawing Dates # Check for arguments to decide if we should print all or just the first line
for date in drawingDates: if len(sys.argv) > 1 and sys.argv[1].lower() in ['-list', '-l']:
# Print Drawing Date # 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):
print(date.text.strip() + ":", end=" ") print(date.text.strip() + ":", end=" ")
# Print 5 White Balls # Print 5 White Balls
@@ -44,3 +51,15 @@ for date in drawingDates:
# Print 1 Power Ball in red # Print 1 Power Ball in red
print(RED + powerballs[powerballPos].text.strip() + RESET) print(RED + powerballs[powerballPos].text.strip() + RESET)
powerballPos += 1 powerballPos += 1
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)