Skip to content

Commit

Permalink
feat: starbucks provider
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenmirabito committed May 22, 2020
1 parent a65c8eb commit 961b8dc
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Automation tool for checking the balance of gift cards issued by various provide
- [GameStop](https://www.gamestop.com/giftcards/) - `gamestop` <sup>CAPTCHA</sup>
- [Best Buy](https://www.bestbuy.com/gift-card-balance) - `bestbuy`
- [Home Depot](https://www.homedepot.com/mycheckout/giftcard) - `homedepot` <sup>CAPTCHA</sup>
- [Starbucks](https://www.starbucks.com/card) - `starbucks`

Providers marked with <sup>CAPTCHA</sup> will require an [Anti-CAPTCHA](https://anti-captcha.com) API key.

Expand Down
1 change: 1 addition & 0 deletions balance_check/providers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
"onevanilla",
"prepaidgiftbalance",
"spafinder",
"starbucks",
]
51 changes: 51 additions & 0 deletions balance_check/providers/starbucks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import asyncio
import pyppeteer
from balance_check import logger
from balance_check.provider import BalanceCheckProvider
from balance_check.validators.gift_card import Merchant, GiftCardSchema


class Starbucks(BalanceCheckProvider):
def __init__(self):
super().__init__()

self.website_url = "https://www.starbucks.com/card"
self.schema = GiftCardSchema(Merchant.Starbucks)

async def scrape(self, fields):
browser = await pyppeteer.launch(
handleSIGINT=False, handleSIGTERM=False, handleSIGHUP=False
)
page = await browser.newPage()

logger.info("Fetching balance check page")
await page.goto(self.website_url)

logger.info("Filling balance check form")
await page.type("#Card_Number", fields["card_number"])
await page.type("#Card_Pin", fields["pin"])

logger.info("Requesting balance")
await page.click("#CheckBalance button")
await page.waitForSelector(".fetch_balance_value", {"timeout": 10000})

avail_balance = await page.querySelectorEval(
".fetch_balance_value", "(node => node.innerText)"
)

logger.info("Success! Card balance: {}".format(avail_balance))

return {"available_balance": avail_balance}

def check_balance(self, **kwargs):
if self.validate(kwargs):
logger.info("Checking balance for card: {}".format(kwargs["card_number"]))

loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)

return loop.run_until_complete(
self.scrape(
{"card_number": kwargs["card_number"], "pin": kwargs["pin"],}
)
)
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ requests
tqdm
lxml
selenium
pyppeteer
chromedriver-binary

0 comments on commit 961b8dc

Please sign in to comment.