Format with black and remove unused imports

main
Eric Ihli 2 years ago
parent db49b62a46
commit 426906cadb

@ -2,7 +2,6 @@ import locale
import logging import logging
import json import json
import operator import operator
import requests
import html2text import html2text
from lottery_data_scraper.schemas import GameSchema from lottery_data_scraper.schemas import GameSchema
@ -12,7 +11,7 @@ from lottery_data_scraper.util import fetch_html
# because California only gives prize values and our schema # because California only gives prize values and our schema
# expects a string representation of the prize. # expects a string representation of the prize.
# https://docs.python.org/3/library/locale.html # https://docs.python.org/3/library/locale.html
locale.setlocale(locale.LC_ALL, 'en_US.utf8') locale.setlocale(locale.LC_ALL, "en_US.utf8")
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
h = html2text.HTML2Text() h = html2text.HTML2Text()
@ -20,6 +19,7 @@ h = html2text.HTML2Text()
BASE_URL = "https://www.calottery.com" BASE_URL = "https://www.calottery.com"
SCRATCHER_URL = "https://www.calottery.com/api/games/scratchers" SCRATCHER_URL = "https://www.calottery.com/api/games/scratchers"
def num_tx_initial(game): def num_tx_initial(game):
grand_prize = game["topPrizeTier"] grand_prize = game["topPrizeTier"]
return grand_prize["odds"] * grand_prize["totalNumberOfPrizes"] return grand_prize["odds"] * grand_prize["totalNumberOfPrizes"]
@ -35,7 +35,9 @@ def fetch_games():
"available": prize_["numberOfPrizesPending"], "available": prize_["numberOfPrizesPending"],
"claimed": prize_["numberOfPrizesCashed"], "claimed": prize_["numberOfPrizesCashed"],
"value": prize_["value"], "value": prize_["value"],
"prize": locale.currency(prize_["value"], grouping=True)[:-3] # -3 to drop the cents "prize": locale.currency(prize_["value"], grouping=True)[
:-3
], # -3 to drop the cents
} }
prizes.append(prize) prizes.append(prize)
grand_prize = sorted(game_["prizeTiers"], key=operator.itemgetter("value"))[-1] grand_prize = sorted(game_["prizeTiers"], key=operator.itemgetter("value"))[-1]

@ -2,11 +2,18 @@ import json
import subprocess import subprocess
import unittest import unittest
from lottery_data_scraper.util import fetch_html
class TestCalifornia(unittest.TestCase): class TestCalifornia(unittest.TestCase):
def test_all(self): def test_all(self):
result = subprocess.run(["python3", "-m", "lottery_data_scraper.california"], capture_output=True) result = subprocess.run(
["python3", "-m", "lottery_data_scraper.california"], capture_output=True
)
data = json.loads(result.stdout) data = json.loads(result.stdout)
self.assertEqual(data[0]["game_id"], "1405", "Expected the first game to be PAC-MAN, #1405.") self.assertEqual(
self.assertEqual(data[0]["num_tx_initial"], 37080000, "Expected 37,080,000 tickets for PAC-MAN #1405.") data[0]["game_id"], "1405", "Expected the first game to be PAC-MAN, #1405."
)
self.assertEqual(
data[0]["num_tx_initial"],
37080000,
"Expected 37,080,000 tickets for PAC-MAN #1405.",
)

Loading…
Cancel
Save