コード例 #1
0
ファイル: messages.py プロジェクト: mlsteele/sleepybymail
"""
Get text for messages.
"""

import datetime
import urllib
import uuid
import quickieconfig as qc

LOG_SERVER_HOST = qc.param("LOG_SERVER_HOST")
LOG_SERVER_PORT = qc.param("LOG_SERVER_PORT")

def make_link(data):
    """Create a logging link from a simple dictionary of stuff."""
    querystring = urllib.urlencode(data)
    return "http://{}:{}/log?{}".format(
            LOG_SERVER_HOST,
            LOG_SERVER_PORT,
            querystring)

def morning_message_body():
    """Get the body text of the morning message."""
    message_uuid = uuid.uuid4()
    lines = []
    lines.append("Hello,")
    lines.append("")
    lines.append("How many hours did you sleep last night?")
    for n in xrange(4, 12):
        lines.append("")
        lines.append("")
        link_uuid = uuid.uuid4()
コード例 #2
0
"""
Example of how to send a message.
"""

from sendgrid import SendGridClient, Mail

import quickieconfig as qc

SENDGRID_USER = qc.param("SENDGRID_USER")
SENDGRID_PASS = qc.param("SENDGRID_PASS")
FROM_EMAIL = qc.param("FROM_EMAIL")
TO_ADDR = qc.param("TARGET_EMAIL")
BODY = "foo"

client = SendGridClient(SENDGRID_USER, SENDGRID_PASS, raise_errors=True)

message = Mail(from_email=FROM_EMAIL, to=TO_ADDR, subject="test", text=BODY)

status, msg = client.send(message)
print "status", status
print "msg", msg
コード例 #3
0
ファイル: logserver.py プロジェクト: mlsteele/sleepybymail
"""
Listen and log arbitrary stuff.
"""

import datetime
import pymongo
import quickieconfig as qc
from flask import Flask, request

SERVER_DEBUG_MODE = qc.param("SERVER_DEBUG_MODE") in ["ON", "YES", "TRUE", "1", 1]
MONGO_DB = qc.param("MONGO_DB")

app = Flask(__name__)
mongo_client = pymongo.MongoClient()
mongo_db = mongo_client[MONGO_DB]

@app.route("/")
def root():
    return "Hey there."

@app.route("/heartbeat")
def heartbeat():
    return "Still alive."

@app.route("/log")
def receive_log():
    data = _unmultidict(request.args)
    data["time_logged"] = datetime.datetime.now()
    _add_log_entry(data)
    return "Ok."
コード例 #4
0
ファイル: logserver.py プロジェクト: mlsteele/sleepybymail
"""
Listen and log arbitrary stuff.
"""

import datetime
import pymongo
import quickieconfig as qc
from flask import Flask, request

SERVER_DEBUG_MODE = qc.param("SERVER_DEBUG_MODE") in [
    "ON", "YES", "TRUE", "1", 1
]
MONGO_DB = qc.param("MONGO_DB")

app = Flask(__name__)
mongo_client = pymongo.MongoClient()
mongo_db = mongo_client[MONGO_DB]


@app.route("/")
def root():
    return "Hey there."


@app.route("/heartbeat")
def heartbeat():
    return "Still alive."


@app.route("/log")
def receive_log():
コード例 #5
0
"""
Get text for messages.
"""

import datetime
import urllib
import uuid
import quickieconfig as qc

LOG_SERVER_HOST = qc.param("LOG_SERVER_HOST")
LOG_SERVER_PORT = qc.param("LOG_SERVER_PORT")


def make_link(data):
    """Create a logging link from a simple dictionary of stuff."""
    querystring = urllib.urlencode(data)
    return "http://{}:{}/log?{}".format(LOG_SERVER_HOST, LOG_SERVER_PORT,
                                        querystring)


def morning_message_body():
    """Get the body text of the morning message."""
    message_uuid = uuid.uuid4()
    lines = []
    lines.append("Hello,")
    lines.append("")
    lines.append("How many hours did you sleep last night?")
    for n in xrange(4, 12):
        lines.append("")
        lines.append("")
        link_uuid = uuid.uuid4()