r/learnpython • • Nov 27 '19

Black Friday hack with python

So I just finished my python script to monitor the price of my target gadget this holiday. It’s going to be heavily discounted soon but it will go to the fastest finger.

I’ve written a python script with BeautifulSoup. I’ve also set email and SMS alerts in the script 😂😂

Was just wondering if there’s any other person doing this for Black Friday and Fastest Finger deals.

Update: Long overdue but just thought I should add that I got the phone.

362 Upvotes

100 comments sorted by

View all comments

26

u/expressly_ephemeral Nov 27 '19

Hey, why don’t you refactor into selenium and beautiful soup, teach your script your credit card info and let it buy it for you when it detects the drop?

0

u/[deleted] Nov 27 '19

[deleted]

1

u/expressly_ephemeral Nov 27 '19

OP should know better than to put his CC info into his github repo, right? Maybe I’m being naive?

2

u/bextie Nov 27 '19

None of my sensitive details are there.

https://github.com/Olunusib/black-friday

0

u/[deleted] Nov 27 '19

[deleted]

1

u/bextie Nov 27 '19

Oh I haven’t thought about that. Is it worth it? I feel that’s for ‘bigger’ projects.

0

u/[deleted] Nov 27 '19

[deleted]

1

u/bextie Nov 27 '19

Thank you! I’m definitely going to do that.

That’s a nice project you’ve got by the way.

1

u/MonkeyNin Nov 27 '19

You can simplify your exceptions, because a failed find call will return None we can take source

class Foo():
    def price(self):
        try:
            productPrice = self.soup.find(id="priceblock_ourprice").get_text()
            return productPrice

        except AttributeError:

            try:
                productPrice = self.soup.find(id="priceblock_dealprice").get_text()
                return productPrice

            except AttributeError:
                pass

We can test for None when there are no matches

class Foo():
    def price(self):
        element_price_price = self.soup.find(id="priceblock_ourprice")
        if not element_price_price:
            print('Price not found!')
            return 0 # or `None` depending on your context

        return product_price.get_text()