コード例 #1
0
ファイル: dataLogger.py プロジェクト: gjinhui/raspberrypi-1
def tweet(lux, temperature):
    '''Tweet if certain conditions are met'''
    message = None
    now = datetime.datetime.now()
    if temperature <= TWEET["cold"]:
        if (now - lastTweet["temperature"]).seconds > TWEET["cycle"]:
            message = ((now.strftime('%H:%M') + " and Freezing! {t:<4}" +
                        u'\u00b0' + "C").format(t=temperature))
            lastTweet["temperature"] = now
    if temperature > TWEET["hot"]:
        if (now - lastTweet["temperature"]).seconds > TWEET["cycle"]:
            message = ((now.strftime('%H:%M') + " and Hot Hot Hot! {t:<4}" +
                        u'\u00b0' + "C").format(t=temperature))
            lastTweet["temperature"] = now
    if (now - lastTweet["temperature"]).seconds > TWEET["tweet"]:
        if temperature <= TWEET["cold"]:
            message = ((now.strftime('%H:%M') + " and Freezing! {t:<4}" +
                        u'\u00b0' + "C").format(t=temperature))
            lastTweet["temperature"] = now
        elif temperature > TWEET["hot"]:
            message = ((now.strftime('%H:%M') + " and Hot Hot Hot! {t:<4}" +
                        u'\u00b0' + "C").format(t=temperature))
            lastTweet["temperature"] = now
        else:
            message = ((now.strftime('%H:%M') + " and {t:<4}" + u'\u00b0' +
                        "C").format(t=temperature))
            lastTweet["temperature"] = now

    if lux <= TWEET["dark"]:
        if (now - lastTweet["lux"]).seconds > TWEET["cycle"]:
            message = (now.strftime('%H:%M') + " and dark!")
            lastTweet["lux"] = now
    if lux > TWEET["bright"]:
        if (now - lastTweet["lux"]).seconds > TWEET["cycle"]:
            message = (now.strftime('%H:%M') + " Bright Light!")
            lastTweet["lux"] = now
    if (now - lastTweet["lux"]).seconds > TWEET["tweet"]:
        if lux <= TWEET["dark"]:
            message = (now.strftime('%H:%M') + " and dark!")
            lastTweet["lux"] = now
        elif lux > TWEET["bright"]:
            message = (now.strftime('%H:%M') + " Bright Light!")
            lastTweet["lux"] = now
    if message:
        message = "In " + LOCATION['city'] + ", " + LOCATION[
            'country_name'] + " it's " + message
        #print "Tweeting: ", message

        tweety.tweet(message)
コード例 #2
0
def tweet(lux,temperature):
    '''Tweet if certain conditions are met'''
    message = None
    now=datetime.datetime.now()
    if temperature <= TWEET["cold"]:
        if (now - lastTweet["temperature"]).seconds > TWEET["cycle"]:
            message = ((now.strftime('%H:%M') + " and Freezing! {t:<4}" + u'\u00b0' + "C").format(t=temperature))
            lastTweet["temperature"] = now
    if temperature > TWEET["hot"]:
        if (now - lastTweet["temperature"]).seconds > TWEET["cycle"]:
            message = ((now.strftime('%H:%M') + " and Hot Hot Hot! {t:<4}"+ u'\u00b0' + "C").format(t=temperature))
            lastTweet["temperature"] = now
    if (now - lastTweet["temperature"]).seconds > TWEET["tweet"]:
        if temperature <= TWEET["cold"]:
            message = ((now.strftime('%H:%M') + " and Freezing! {t:<4}" + u'\u00b0' + "C").format(t=temperature))
            lastTweet["temperature"] = now
        elif temperature > TWEET["hot"]:
            message = ((now.strftime('%H:%M') + " and Hot Hot Hot! {t:<4}" + u'\u00b0' + "C").format(t=temperature))
            lastTweet["temperature"] = now
        else:
            message = ((now.strftime('%H:%M') + " and {t:<4}" + u'\u00b0' + "C").format(t=temperature))
            lastTweet["temperature"] = now

    if lux <= TWEET["dark"]:
        if (now - lastTweet["lux"]).seconds > TWEET["cycle"]:
            message = (now.strftime('%H:%M') + " and dark!")
            lastTweet["lux"] = now
    if lux > TWEET["bright"]:
        if (now - lastTweet["lux"]).seconds > TWEET["cycle"]:
            message = (now.strftime('%H:%M') + " Bright Light!")
            lastTweet["lux"] = now
    if (now - lastTweet["lux"]).seconds > TWEET["tweet"]:
        if lux <= TWEET["dark"]:
            message = (now.strftime('%H:%M') + " and dark!")
            lastTweet["lux"] = now
        elif lux > TWEET["bright"]:
            message = (now.strftime('%H:%M') + " Bright Light!")
            lastTweet["lux"] = now
    if message:
        message = "In " + LOCATION['city'] + ", " + LOCATION['country_name'] + " it's " + message
        #print "Tweeting: ", message

        tweety.tweet(message)
コード例 #3
0
ファイル: dataLogger.py プロジェクト: Cribstone/raspberrypi
def tweet(lux, temperature):
    """Tweet if certain conditions are met"""
    now = datetime.datetime.now()
    if temperature <= TWEET["cold"]:
        if (now - lastTweet["temperature"]).seconds > TWEET["cycle"]:
            tweety.tweet(now.strftime("%H:%M") + " and it's Freezing! " + temperature + " C")
            lastTweet["temperature"] = now
    if temperature > TWEET["hot"]:
        if (now - lastTweet["temperature"]).seconds > TWEET["cycle"]:
            tweety.tweet((now.strftime("%H:%M") + " and it's Hot Hot Hot! {t:<4}" + " C").format(t=temperature))
            lastTweet["temperature"] = now
    if lux <= TWEET["dark"]:
        if (now - lastTweet["lux"]).seconds > TWEET["cycle"]:
            tweety.tweet(now.strftime("%H:%M") + " and it's dark!")
            lastTweet["lux"] = now
    if lux > TWEET["bright"]:
        if (now - lastTweet["lux"]).seconds > TWEET["cycle"]:
            tweety.tweet(now.strftime("%H:%M") + " Bright Light!")
            lastTweet["lux"] = now