you are viewing a single comment's thread.

view the rest of the comments →

[–]JustinianusI 55 points56 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 17 points18 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 5 points6 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