コード例 #1
0
ファイル: spud.py プロジェクト: aaronoppenheimer/spudcam
    def heartbeat(who, subj=''):
        logit('heatbeating on command from {0}'.format(who))
        if subj == '':
            subj = 'Heartbeat'

        spudemail.sendMail(recipient=who, subject=subj, message='Heatbeat!')
        return False
コード例 #2
0
def main():
    """ send daily image """
    logit('sending daily picture')
    spudemail.sendMail(recipient='*****@*****.**',
                       subject="Today's Picture",
                       message='Baboom!',
                       picture=dir_path + '/pix/pic.jpg')
コード例 #3
0
ファイル: spud.py プロジェクト: aaronoppenheimer/spudcam
 def log(who, subj=''):
     logit('sending log on command from {0}'.format(who))
     spudemail.sendMail(recipient=who,
                        subject='Log File',
                        file='/home/pi/spudcam/logs/runnerlog.txt')
     spudemail.sendMail(recipient=who,
                        subject='Other Log File',
                        file='/home/pi/spudcam/logs/cronlog')
コード例 #4
0
ファイル: series.py プロジェクト: aaronoppenheimer/spudcam
def main():
    """ send daily image """
    logit('sending series')
    spudemail.sendMail(recipient='*****@*****.**',
                       subject="Sunrise",
                       message='The Pictures!',
                       series=dir_path + '/pix/series{0:02}.jpg',
                       seriesRange=range(1, 31))
コード例 #5
0
ファイル: spud.py プロジェクト: aaronoppenheimer/spudcam
    def picture(who, subj=''):
        logit('sending picture on command from {0}'.format(who))
        if subj == '':
            subj = 'Picture'

        spudemail.sendMail(recipient=who,
                           subject=subj,
                           message='The Picture!',
                           picture=dir_path + '/pix/pic.jpg')
        return False
コード例 #6
0
ファイル: spud.py プロジェクト: aaronoppenheimer/spudcam
    def series(who, subj=''):
        logit('sending series on command from {0}'.format(who))
        if subj == '':
            subj = 'Series'

        spudemail.sendMail(recipient=who,
                           subject=subj,
                           message='The Picture!',
                           series=dir_path + '/pix/series{0:02}.jpg',
                           seriesRange=range(1, 16))
        return False
コード例 #7
0
ファイル: spud.py プロジェクト: aaronoppenheimer/spudcam
 def temp(who, subj=''):
     logit('sending temperature on command from {0}'.format(who))
     #        f=open('/sys/class/thermal/thermal_zone0/temp')
     #        line=f.readline()
     #        f.close()
     #        temperature=int(line)/1000
     #        spudemail.sendMail(recipient=who, subject='Spud Temp', message='Temperature:{0}'.format(temperature))
     humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
     spudemail.sendMail(recipient=who,
                        subject='Spud Temp',
                        message='Temperature:{0}, Humidity:{1}'.format(
                            temperature, humidity))
コード例 #8
0
ファイル: camera.py プロジェクト: aaronoppenheimer/spudcam
def takePicture(filename):
    camera = PiCamera(resolution=(1296, 730))
    try:
        #        camera.rotation = 180
        camera.rotation = 0
        sleep(4)
        n = datetime.now() - timedelta(hours=4)
        camera.exif_tags['IFD0.DateTime'] = n.strftime("%Y:%m:%d %H:%M:%S")
        camera.capture(filename, quality=30)
    except Exception as e:
        logit('camera problem: {0}'.format(str(e)))
    finally:
        camera.close()
コード例 #9
0
ファイル: endpoint.py プロジェクト: kristopolous/frustrometer
def application(environ, start_response):
    write = start_response('200 OK', [
      ('Access-Control-Allow-Origin', '*'),
      ('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS'),
      ('Content-Type', 'application/json')
    ])

    raw = environ['wsgi.input'].read(int(environ.get('CONTENT_LENGTH', '0')))
    if len(raw) > 0:
      log.logit(raw)

      try:
        content = json.loads(raw)
      except ValueError:
        return [json.dumps({"error": "I need JSON, with your input as the value to the data key"})]

# The challenge makes sure that UUIDs don't get stomped
# by people who want to hijack an existing comment.
#
# Both the publically accessible uuid and the privately
# stored challenge has to match before anything is updated

      my_challenge = 0

      if 'uid' in content and content['uid'] != 0:
        my_guid = content['uid']

        if 'c' in content:
          my_challenge = content['c']

      else:
        my_guid = myrand()
        my_challenge = myrand()

      if 'id' in content and content['id'] == 'fave':
        log.faveit(raw)
      else:
        res = model.analyze(content['data'])

      res['uid'] = my_guid
      res['c'] = my_challenge

      return [json.dumps(res)]

    return [json.dumps({"error": "I need some POST input to analyze, dumbfuck."})]
コード例 #10
0
def sendmail(to_,sub_,main_="molebot.com"):
    server = smtplib.SMTP_SSL()
    logit(str(server.connect(host,port)))
    logit((server.login(from_,pswd)))
    msg = MIMEText(main_)
    msg['From'] = from_
    msg['To'] = to_
    msg['Subject'] = sub_
    logit(str(server.sendmail(from_,to_,msg.as_string())))
    logit('qqmail ok')
    server.quit()
コード例 #11
0
def getSecret():
    f = None
    try:
        f = open('secret.txt')
    except:
        pass

    if f is None:
        try:
            f = open('/home/pi/spudcam/secret.txt')
        except:
            pass

    if f is not None:
        line = f.readline().strip()
        f.close()
        return line
    else:
        logit('no secret file!')
        return ''
コード例 #12
0
def sendMail(recipient, subject, message=None, picture=None, file=None, series=None, seriesRange=None):
    """this is some test documentation in the function"""

    SECRET = getSecret() # gmail version
    #SECRET = "1!{0}".format(getSecret()[:13])

    password = SECRET

    msg = MIMEMultipart()
    msg['From'] = username
    msg['To'] = recipient
    msg['Subject'] = subject
    
    if message:
        msg.attach(MIMEText(message))

    if picture:
        msgImage = getMailPicture(picture)
        # Define the image's ID as referenced above
        if msgImage:
            msgImage.add_header('Content-ID', 'pic')
            msgImage.add_header('Content-Disposition', 'attachment; filename="{0}"'.format(psplit(picture)[-1]))
            msg.attach(msgImage)

    if series and seriesRange:
        for i in seriesRange:
            picname = series.format(i)
            msgImage = getMailPicture(picname)
            # Define the image's ID as referenced above
            if msgImage:
                msgImage.add_header('Content-ID', 'pic')
                msgImage.add_header('Content-Disposition', 'attachment; filename="{0}"'.format(psplit(picname)[-1]))
                msg.attach(msgImage)
        
    if file:
        try:
            with open(file, 'r') as theFile:
                msgLog=theFile.read()  
            msg.attach(MIMEText(msgLog))
        except Exception as e:
            logit(str(e))

    try:
        logit('sending mail to ' + recipient + ' re: ' + subject)

        # mailServer = smtplib.SMTP('smtp.gmail.com', 587)
        mailServer = smtplib.SMTP('smtp.comcast.net', 587)
        mailServer.ehlo()
        mailServer.starttls()
        mailServer.ehlo()
        mailServer.login(username, password)
        mailServer.sendmail(username, recipient, msg.as_string())
        mailServer.close()

    except Exception as e:
        logit(str(e))
コード例 #13
0
ファイル: spud.py プロジェクト: aaronoppenheimer/spudcam
 def restart(who, subj=''):
     logit('restarting on command from {0}'.format(who))
     return True  # quit the program
コード例 #14
0
ファイル: spud.py プロジェクト: aaronoppenheimer/spudcam
def main():

    spudemail.sendMail("*****@*****.**", "started!",
                       "spud is up! Version {0}".format(VERSION))
    logit('started at {0}'.format(datetime.datetime.now() -
                                  datetime.timedelta(hours=4)))

    def restart(who, subj=''):
        logit('restarting on command from {0}'.format(who))
        return True  # quit the program

    def heartbeat(who, subj=''):
        logit('heatbeating on command from {0}'.format(who))
        if subj == '':
            subj = 'Heartbeat'

        spudemail.sendMail(recipient=who, subject=subj, message='Heatbeat!')
        return False

    def picture(who, subj=''):
        logit('sending picture on command from {0}'.format(who))
        if subj == '':
            subj = 'Picture'

        spudemail.sendMail(recipient=who,
                           subject=subj,
                           message='The Picture!',
                           picture=dir_path + '/pix/pic.jpg')
        return False

    def series(who, subj=''):
        logit('sending series on command from {0}'.format(who))
        if subj == '':
            subj = 'Series'

        spudemail.sendMail(recipient=who,
                           subject=subj,
                           message='The Picture!',
                           series=dir_path + '/pix/series{0:02}.jpg',
                           seriesRange=range(1, 16))
        return False

    def log(who, subj=''):
        logit('sending log on command from {0}'.format(who))
        spudemail.sendMail(recipient=who,
                           subject='Log File',
                           file='/home/pi/spudcam/logs/runnerlog.txt')
        spudemail.sendMail(recipient=who,
                           subject='Other Log File',
                           file='/home/pi/spudcam/logs/cronlog')

    def temp(who, subj=''):
        logit('sending temperature on command from {0}'.format(who))
        #        f=open('/sys/class/thermal/thermal_zone0/temp')
        #        line=f.readline()
        #        f.close()
        #        temperature=int(line)/1000
        #        spudemail.sendMail(recipient=who, subject='Spud Temp', message='Temperature:{0}'.format(temperature))
        humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
        spudemail.sendMail(recipient=who,
                           subject='Spud Temp',
                           message='Temperature:{0}, Humidity:{1}'.format(
                               temperature, humidity))

    accession = 0
    while (True):

        try:
            recd = spudemail.getMail()
        except:
            logit("Unexpected error fetching email: {0}".format(
                sys.exc_info()[0]))
            recd = []

        quit = False

        doit = {
            'restart': restart,
            'heartbeat': heartbeat,
            'picture': picture,
            'series': series,
            'log': log,
            'temp': temp
        }

        for r in recd:
            cmd = r['subj']
            cmd = cmd.strip().lower()
            accession = accession + 1
            logit('{0} from: {1}   subj: {2}   body: >{3}<'.format(
                accession, r['from'], cmd, r['body']))

            if cmd in doit.keys():
                quit = doit[cmd](r['from'], r['body'])

            if quit:  # anyone ask us to quit?
                return

        time.sleep(10)
コード例 #15
0
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import json
import sys
import log
import model

content = sys.stdin.read()
log.logit(content)
print json.dumps(model.analyze(content))