Exemplo n.º 1
1
def main():
    # Write the current time to a hidden storage file.
    try:
        with open('/home/omgimanerd/.time', 'r') as f:
            read_time = int(f.read().strip())
    except:
        read_time = int(time.time())

    # If we just restarted the computer, then greet and say the weather.
    if int(time.time()) - read_time > 70:
        t = time.localtime()
        hour = t.tm_hour
        if hour < 11:
            say('Good morning sir')
        elif hour < 15:
            say('Good afternoon sir')
        else:
            say('Good evening sir')

        weather_data = get_weather_by_latlng(43, -77)
        temperature = int(k_to_f(weather_data.get('main', {}).get('temp')))
        description = weather_data.get('weather',
                                       [{}])[0].get('description')
        say('The temperature is %s degrees fahrenheit with %s' %
            (temperature, description))

    # Write the updated time to the file.
    with open('/home/omgimanerd/.time', 'w') as f:
        f.write(str(int(time.time())))
Exemplo n.º 2
1
def main():
    response = requests.get('http://nycurl.sytes.net')
    if response.status_code != 200:
        with open('/home/omgimanerd/ALERT', 'w') as f:
            f.write('NYCURL HAS GONE DOWN!')
        say('Sir, nycurl has gone down. You may want to check on it.')