banool/recreation-gov-campsite-checker

Add smtplib for notifications

Closed this issue · 2 comments

I'm not very github savvy else I would do a pull request?....

For now, I thought I would offer up this block of code I inserted to notify me when a site was available. It worked perfect for me yesterday/today to snatch a very sought after location within 60 seconds. Absolutely appreciate you creating the base script to work with the new recreation.gov site. I just have to find a scraper for the reserveamerica.com site now and wrap them.... Hoping I can pick up PHP and create a web-based wrapper to connect them together.

This is showing the top and bottom parts of the original script so you can see where I put this.
Pretty sure this could be extracted and put into a module instead to better protect the password or maybe just use a dummy email account.

I use my email and sms for notifications that include the link to the site/campground so I can quickly scan sites for which one is open. If I knew the API call to show open sites in a campground that would be even nicer.... Maybe have a link in the notification to "book now" which would place it in your cart and give you 15min to reserve it?

    if availabilities:
        print(
            "There are campsites available from {} to {}!!!".format(
                args.start_date.strftime(INPUT_DATE_FORMAT),
                args.end_date.strftime(INPUT_DATE_FORMAT),
            )
        )
        import smtplib
        from email.mime.text import MIMEText
        me = "username@comcast.net"
        recipients = ['recipent@gmail.com', '7201234567@vtext.com']
        passwd = "password here"
        body = ("There are " + str(current) + " sites available out of " + str(maximum) + " site(s) at " + name_of_site
             +  "\nLink to Reserve: https://recreation.gov/camping/campgrounds/" + str(park_id) + "/availability")
        msg = MIMEText(body)
        msg['Subject'] = 'Campsites Available for ' + args.start_date.strftime(INPUT_DATE_FORMAT) + ' - ' + args.end_date.strftime(INPUT_DATE_FORMAT)
        msg['From'] = "sender@example.com"
        msg['To'] = ", ".join(recipients)
        session = smtplib.SMTP('smtp.comcast.net',587)
        session.login(me, passwd)
        session.sendmail(me, recipients, msg.as_string())
        session.quit()

    else:
        print("There are no campsites available :(")
    print("\n".join(out))

Using a while loop for now until I can do a cron entry... (running this out of a FreeNas jail on python36)

while [ 1 ]; do python camping.py --start-date 2019-07-11 --end-date 2019-07-12 233187; sleep 60; done

image

Feel free to make a pull request 😄. I'd rather not pollute the main script. Instead make another file like notifier.py that consumes the stdout of the main script and does something with it.

This has had no activity for 8 months so I'm going to close this out to keep things clean.