Change scrape_url to scrap_game_history, white_balls to game_balls
This commit is contained in:
1 parent
6db3f85c58
commit
45fb8cf0c3
1 file changed
+9
-9
+9
-9
@@ -12,7 +12,7 @@ from bs4 import BeautifulSoup
|
||||
|
||||
load_dotenv()
|
||||
|
||||
def scrape_url(game: str, year: int | None) -> dict:
|
||||
def scrape_game_history(game: str, year: int | None) -> dict:
|
||||
"""
|
||||
Scrape game data from the url provided. This function requires specific environment variables be present
|
||||
in order to function properly.
|
||||
@@ -22,11 +22,11 @@ def scrape_url(game: str, year: int | None) -> dict:
|
||||
:return: dict()
|
||||
|
||||
Examples:
|
||||
>>>scrape_url(game='mega-millions')
|
||||
draw_date {'white_balls': ...}
|
||||
>>>scrape_game_history(game='mega-millions')
|
||||
draw_date {'main_balls': ...}
|
||||
|
||||
>>>scrape_url(game='mega-millions', year=2020)
|
||||
draw_date {'white_balls': ...}
|
||||
>>>scrape_game_history(game='mega-millions', year=2020)
|
||||
draw_date {'main_balls': ...}
|
||||
"""
|
||||
drawings = {}
|
||||
|
||||
@@ -42,13 +42,13 @@ def scrape_url(game: str, year: int | None) -> dict:
|
||||
pick5 = []
|
||||
draw_date = parser.parse(result.find(os.getenv('DRAW_DATE_CONTAINER'),
|
||||
class_=os.getenv('DRAW_DATE_CLASS')).text).date().strftime('%Y-%m-%d')
|
||||
white_balls = result.find_all(os.getenv('BALL_CONTAINER'), class_=os.getenv('BALL_CLASS'))
|
||||
main_balls = result.find_all(os.getenv('BALL_CONTAINER'), class_=os.getenv('BALL_CLASS'))
|
||||
game_ball = result.find(os.getenv('BALL_CONTAINER'),
|
||||
class_=[os.getenv('POWERBALL_CLASS'), os.getenv('MEGABALL_CLASS')])
|
||||
multiplier = result.find(os.getenv('BALL_CONTAINER'),
|
||||
class_=[os.getenv('POWERBALL_MULTIPLIER_CLASS'), os.getenv('MEGA_MILLIONS_MULTIPLIER_CLASS')])
|
||||
|
||||
for ball in white_balls:
|
||||
for ball in main_balls:
|
||||
pick5.append(int(ball.text.strip()))
|
||||
|
||||
game_ball = int(game_ball.find('span').text)
|
||||
@@ -58,8 +58,8 @@ def scrape_url(game: str, year: int | None) -> dict:
|
||||
multiplier = 1
|
||||
|
||||
if game == 'mega-millions':
|
||||
drawings[draw_date] = {'white_balls': pick5, 'mega-ball': game_ball, 'multiplier': multiplier}
|
||||
drawings[draw_date] = {'main_balls': pick5, 'mega-ball': game_ball, 'multiplier': multiplier}
|
||||
elif game == 'powerball':
|
||||
drawings[draw_date] = {'white_balls': pick5, 'powerball': game_ball, 'multiplier': multiplier}
|
||||
drawings[draw_date] = {'main_balls': pick5, 'powerball': game_ball, 'multiplier': multiplier}
|
||||
|
||||
return drawings
|
||||
Reference in new issue
Block a user