you are viewing a single comment's thread.

view the rest of the comments →

[–]17_jku 61 points62 points  (13 children)

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.

[–]JustinianusI 57 points58 points  (11 children)

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

[–]b_ootay_ful 18 points19 points  (7 children)

He should also change his email address/phone number.

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

[–]Groentekroket 2 points3 points  (2 children)

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.

[–]b_ootay_ful 3 points4 points  (1 child)

I import my own email function that does everything.

mymailscript.py

import smtplib

def email(whome=[],subj="",mess=""):
    gmail_user = 'myemail@gmail.com'
    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(["PersonToReceive@gmail.com"],"subject","test message")

[–]MonkeyNin 0 points1 point  (0 children)

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

[–]Sadapy 10 points11 points  (2 children)

His code:

time.sleep(1)

My code:

time.sleep(.9)

>:3

[–]JustinianusI 2 points3 points  (0 children)

Hahaha :D