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

63

u/17_jku Nov 27 '19

I have not (just starting to tinker with Python...I'm a VB, SQL, SAS developer), but would love to see your approach. Of course, you would need to change the item URL so none of us snatch it up before you. Hahaha.

58

u/JustinianusI Nov 27 '19

Omg imagine! This poor guy writes the code and everything, shares it with us, and we use it to buy up all the product before he gets his! Love it :D

19

u/b_ootay_ful Nov 27 '19

He should also change his email address/phone number.

Every person that has this running, on every item, he gets a notification =P

0

u/[deleted] Nov 27 '19

[deleted]

0

u/[deleted] Nov 27 '19

[deleted]

2

u/b_ootay_ful Nov 27 '19

friendly russian hacker

We got hit by ransomware last Tuesday, and are still recovering.

I want to know HIS location.

3

u/Groentekroket Nov 27 '19

I store that kind of things as a environment variable. If you share your code you are sure nobody gets yourusername, email, passwords and that kind of things.

5

u/b_ootay_ful Nov 27 '19

I import my own email function that does everything.

mymailscript.py

import smtplib

def email(whome=[],subj="",mess=""):
    gmail_user = '[email protected]'
    gmail_pwd = 'HelloReddit'
    FROM = gmail_user
    TO = whome
    SUBJECT = subj
    TEXT = str(mess)

    # Prepare actual message
    message = """From: %s\nTo: %s\nSubject: %s\n\n%s
    """ % (FROM, ", ".join(TO), SUBJECT, TEXT)
    try:
        server = smtplib.SMTP("smtp.gmail.com", 587)
        server.ehlo()
        server.starttls()
        server.login(gmail_user, gmail_pwd)
        server.sendmail(FROM, TO, message)
        server.close()
        return ('Email sent!')
    except:
        return ('Something went wrong...')

whatever program I need to import or use

import mymailscript as emailscript

emailscript.email(["[email protected]"],"subject","test message")

1

u/MonkeyNin Nov 27 '19
def email(whome=[],subj="",mess=""):

You should read this: https://docs.python-guide.org/writing/gotchas/#mutable-default-arguments

.. config files

Check out using pathlib.Path and json

import pathlib
import json

    def load_config(json_path):
        # load config if it exists, otherwise return populated with required defaults
        defaults = {'monkey': '๐Ÿ’', 'cat': '๐Ÿˆ'}

        if not json_path.exists():
            # logger.error(f"File does not exist: {json_path}")
            return defaults

        config = json.loads(json_path.read_text(encoding='utf-8'))
        return config

data_root = Path('.').absolute() # or Path().home() or Path('.')
config_path = data_root / 'monkey.json'
config = load_config(config_path)

or if you want a truthy result

def load_config(json_path):
    if not json_path.exists():
        return {}

config = load_config(config_path)

if not config:
    # ... handle no file
else:
    # ... normal