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?

20

u/BruceJi 📦 Nov 27 '19

I wonder if that's not the best idea in case something goes wrong? But if you get the email, you can probably just buy it online with your phone within a few minutes anyway.

16

u/azur08 Nov 27 '19 edited Nov 27 '19

in case something goes wrong

Like buying everything Amazon has to offer over and over again!

31

u/Cat_Marshal Nov 27 '19
while True:
    purchase()

9

u/BruceJi 📦 Nov 27 '19

"Merry Christmas, here are 20 pop-up tents, for all that... popping up?... you do? Eheh..."

2

u/expressly_ephemeral Nov 27 '19

Hah! I know a lady who gave her grandkid the tablet to play with and he ordered 20 chromebooks. Kids and scripts, man. Fuckin' dangerous.

10

u/expressly_ephemeral Nov 27 '19

I acknowledge... tricky to test, tricky to validate. Cooler, though.

3

u/BruceJi 📦 Nov 27 '19

It really would be!

3

u/expressly_ephemeral Nov 27 '19

I guess I think you could use the email as a backstop, though. You get the email saying the price happened and then a follow up saying “I bought it” or “your code stinks, get out your credit card.”

I mean.. what if OP is in meeting when the trigger fires? What if his wife’s water has just broken while she’s driving her real estate clients around? He won’t be able close the deal!

1

u/dBASSa Nov 27 '19

Theres tons of sneaker bots that do this already. They are heavily linked with fraud and abuse so limited sale items block orders this way often times.

1

u/expressly_ephemeral Nov 27 '19

How would a vendor be able to block a bespoke script running from a host on OPs personal network?

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]

→ More replies (2)

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()

0

u/[deleted] Nov 27 '19

[deleted]

1

u/expressly_ephemeral Nov 27 '19

Sure, but then you’d have to be canny enough to make the following realizations: I shouldn’t share this with anybody. I should figure a way to make sure the eventual connection is ssl (via selenium). This should be hosted on my private network only unless there’s a way to make this kind of thing reasonably secure. And, finally, there’s probably a way to make this kind of thing secure and I should figure out how people publish code like this.

I have my personal login credentials hardcoded into some scripts, but the run solely on a machine that lives in a closet in my house, and I make sure not to push them to a public repo.

0

u/[deleted] Nov 27 '19

[deleted]

1

u/expressly_ephemeral Nov 27 '19 edited Nov 27 '19

You know, I’ve done the threat modeling. If somebody breaks my OpenVPN instance and compromises my router, then they ssh into the server that runs these scripts (a server which only responds to logins with my private rsa token), or worse finds an exploit by which they can get a reverse shell... then I’ve got much bigger worries than whether they can harvest the username password I use to check my kid’s missing homework list.

Edit: I’m saying, you’re right. I wouldn’t do it with my login credentials for my bank,

0

u/[deleted] Nov 27 '19

[deleted]

2

u/expressly_ephemeral Nov 27 '19

There's a fine line between good threat modeling and gross negligence!

→ More replies (1)