Skip to content

Instantly share code, notes, and snippets.

@rosshiga
Created April 14, 2020 02:23
Show Gist options
  • Save rosshiga/2bd498abb77a8aa67a90d1b4e80084cd to your computer and use it in GitHub Desktop.
Save rosshiga/2bd498abb77a8aa67a90d1b4e80084cd to your computer and use it in GitHub Desktop.
Tally Counter for Pi
from email.message import EmailMessage
import smtplib
import urllib.request
import subprocess
import smtplib
import socket
from email.mime.text import MIMEText
import datetime
import time
device = "Clicker-Pi"
recipients = ["[email protected]", "[email protected]", "[email protected]"]
gmail_user = '[email protected]'
gmail_password = 'qriwgcweilkavybs'
site = 'http://clicker.waianaestore.com/num.php'
upTrigger = 70
downTrigger = 60
lastTrigger = downTrigger
def sendmail(subject, message):
smtpserver = smtplib.SMTP('smtp.gmail.com', 587)
smtpserver.ehlo()
smtpserver.starttls()
smtpserver.login(gmail_user, gmail_password)
msg = MIMEText(message)
msg['Subject'] = f'{subject} - {device}'
msg['From'] = gmail_user
msg['To'] = ", ".join(recipients)
smtpserver.sendmail(gmail_user, recipients, msg.as_string())
smtpserver.quit()
def exec(args):
return subprocess.Popen(args, shell=True, stdout=subprocess.PIPE).communicate()[0].decode("utf-8")
while True:
try:
time.sleep(1)
currentCount = int(urllib.request.urlopen(site).read().decode('utf8'))
print(f'{currentCount} - {lastTrigger}')
if currentCount >= upTrigger and currentCount > lastTrigger:
print('high')
lastTrigger = currentCount + 100
sendmail("HIGH Capacity", f'{currentCount}')
if currentCount <= downTrigger and currentCount < lastTrigger:
print('low')
lastTrigger = 0
sendmail("LOW Capacity", f'{currentCount}')
except:
print("errror")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment