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

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!

2

u/expressly_ephemeral Nov 27 '19

VPN, i didn't think of that.

Yeah, I mean, again, in this use case all the application has to do is make GET and POST calls. Outbound only. Server wouldn't be visible from the outside world even WITHOUT the vpn.