fabianmoronzirfas
1/15/2013 - 9:59 AM

connection check.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# https://gist.github.com/raw/4523614/weather.yandex.py

from growlnotify import growlnotify
from macos import silence
from say import say
from sleep import sleeping
from yandexweather import download

xml = download(26686)  # Сафоново
xml.save("~/Documents/weather/yandex.xml")
growlnotify(u"На улице %s C" % xml.temperature, xml.weather)
if not sleeping:
    if silence():
        text = u"На улице %s, %s" % (xml.temperature, xml.weather)
        print text.encode("utf8")
        say(text)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from datetime import datetime
from dateutil.relativedelta import relativedelta
from growlnotify import growlnotify
from ical import ical
from itunes import itunes
from skype import skype
from vlc import vlc
from say import say
from home.ventilation import last
from man import sleeping

now = datetime.now()
if not sleeping:
    if not last() or relativedelta(now, last().start).hours >= 3:
        ical.todo("ventilation")
        if not not vlc.playing:
            growlnotify(u"Начните проветривание")
        if not itunes.playing and not skype.calling:
            say(u"Начните проветривание")
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# https://gist.github.com/raw/4523614/time-out-free%20normal.py

from growlnotify import growlnotify
from idle import idle
from itunes import itunes
from skype import skype
from vlc import vlc
from say import say

if idle() < 60 * 15:
    if not vlc.playing:
        growlnotify(
            u"Перерыв",
            u"10 минут",
            app="Time Out Free"
        )
        if not itunes.playing and not skype.calling:
            say(u"Сделайте перерыв на 10 минут")
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# https://gist.github.com/raw/4523614/time-out-free%20micro.py

from growlnotify import growlnotify
from idle import idle
from itunes import itunes
from skype import skype
from vlc import vlc
from say import say

if idle() < 60 * 5:
    if not vlc.playing:
        growlnotify(
            u"смотрите вдаль",
            u"в течении 20-ти секунд",
            app="Time Out Free"
        )
        if not itunes.playing and not skype.calling:
            say(u"Смотрите вдаль в течении двадцати секунд")
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# https://gist.github.com/raw/4523614/time%20announce.py


from datetime import datetime
from pytils.numeral import choose_plural
from growlnotify import growlnotify
from say import say
from itunes import itunes
from skype import skype
from vlc import vlc


if not vlc.playing:
    now = datetime.now()
    growlnotify(u"Сейчас", str(now.hour), app="System preferences")
    if skype.calling and not itunes.playing:
        if now.hour > 1:
            numending = choose_plural(now.hour, (u"час", u"часа", u"часов"))
            h = "%s %s" % (now.hour, numending)
        else:
            h = u"час"
        if now.hour < 5:
            h = h + u" ночи"
        say(u"Сейчас %s" % h)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# https://gist.github.com/raw/4523614/temperature.py
from time import sleep
from pytils.numeral import choose_plural
from growlnotify import growlnotify
from idle import idle
from osascript import osascript
from say import say
from tempmonitor import air
from itunes import itunes
from skype import skype
from vlc import vlc


def get_volume():
    return int(osascript("""
output volume of (get volume settings)"""))


def set_volume(v):
    osascript("set volume output volume %s" % v)

t = air()
numending = choose_plural(t, (u"градус", u"градуса", u"градусов"))

if not vlc.playing:
    if t < 10:
        growlnotify(
            u"Температура %s °C" % t,
            u"Температура <10 опасна для компьютерной техники"
        )
        int(osascript())
        if get_volume() == 0:
            set_volume(30)
        say(u"Слишком низкая для компьютера температура в помещении")
    else:
        if idle() < 60:  # at computer
            if not 18 <= t <= 22:
                growlnotify(
                    u"Температура %s °C" % t,
                    u"Оптимальная температура для интеллектуальной работы в пределах 18..22 °C"
                )
                if not itunes.playing and not skype.calling:
                    say(u"Температура %s %s" % (t, numending))
                    sleep(1)
                    say(u"Рекомендуется температура в помещении в пределах 18..22 °C")
#!/usr/bin/env python
# https://gist.github.com/raw/4523614/systemlog%20notify.py
# -*- coding: utf-8 -*-

from datetime import datetime
from os.path import exists, expanduser
from pickle import dump, load
from re import findall, sub
from growlnotify import growlnotify
from systemlog import items

f = expanduser("~/.launchd.syslog")
if exists(f):
    checked = load(open(f))
else:
    checked = datetime.now()

for i in items():
    if i.process.find("com.apple.launchd.peruser") >= 0:
        if i.datetime > checked:
            subprocess = findall("\(.*\)", i.process)[0][1:-1]
            label = sub("[\[\d\]]", "", subprocess)
            growlnotify(
                "%s %s" % (label, i.datetime.strftime('%H:%M')),
                i.message,
                app="Console",
                sticky=True
            )
dump(datetime.now(), open(f, "w"))
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# https://gist.github.com/raw/4523614/mac-on.py

from datetime import datetime
from dateutil.relativedelta import relativedelta
from osascript import osascript
from time import sleep
from say import say
from ical import ical
from itunes import itunes
from yandexweather import load
from pytils.numeral import choose_plural
from datetimerus.time import rus
from sun import today

osascript("set volume output volume 30")
itunes.play("alarm_clock")
itunes.fadein(60)
say(u"Доброе утро")
sleep(2)
ical.todo("water")
say(u"Выпейте стакан чистой воды с лимоном и медом")

sleep(5)
now = datetime.now()
say(u"Сейчас %s" % rus(now))
sleep(2)
say(u"Рассвет через %s" % rus(relativedelta(now, today().sunrise)))
sleep(2)
xml = load()
t = xml.temperature
c = choose_plural(t, (u"градус", u"градуса", u"градусов"))
say(u"На улице %s, температура %s %s" % (xml.weather, t, c))
#!/usr/bin/env python
# https://gist.github.com/raw/4523614/mac-off.py

from os import popen
from osascript import osascript
osascript("set volume output volume 0")
popen("open -a sleepdisplay")
popen("open -a transmission")
#!/usr/bin/env python
# https://gist.github.com/raw/4523614/imac-tempmonitor.py

from tempmonitor import grep, sensors
from imac import session
from imac.tempmonitor import cls


for sensor in sensors():
    session.add(cls(
        sensor=sensor,
        value=grep(sensor)
    ))
#!/usr/bin/env python
# https://gist.github.com/raw/4523614/imac-idle.py

from idle import idle
from imac import session
from imac.idle import cls


session.add(cls(value=idle()))
#!/usr/bin/python
# -*- coding: utf-8 -*-
# https://gist.github.com/raw/4523614/earthtools.org.sun.py

from earthtools.sun import download, url
from datetime import date, timedelta
from ical import ical
import sun

# http://itouchmap.com/latlong.html
lat = 53.7397885  # Кричев
lon = 31.7182528  # Кричев

lat = 55.120010  # Сафоново
lon = 33.233448  # Сафоново
# http://www.earthtools.org/sun/53.7397885/31.7182528/15/10/4/0
# http://www.earthtools.org/sun/55.120010/33.233448/15/10/4/0

for i in range(0, 8):
    date = date.today() + timedelta(days=i)
    xml = download(url(lat, lon, month=date.month, day=date.day))
    sun.set(date, xml.sunrise, xml.sunset)
    if i == 0:  # today
        #ical.get_event("Daytime").set_dates(xml.sunrise,xml.sunset)
        print xml.sunrise, xml.sunset
#!/usr/bin/env python
# https://gist.github.com/raw/4523614/display-sleep.py

from skype import skype
from vlc import vlc
from os import popen
from idle import idle

if (idle() / 60) > 5:  # >5 minutes idle
    if not skype.calling and not vlc.playing:
        popen("open -a sleepdisplay")
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# https://gist.github.com/raw/4523614/connection%20check.py


from datetime import datetime
from requests import get
from vlc import vlc
from growlnotify import growlnotify

try:
    get("http://www.apple.com", timeout=5)
except Exception, e:
    if not vlc.playing:
        now = datetime.now()
        growlnotify("%s:%s" % (now.hour, now.minute), "No internet connection :(", app="Terminal", sticky=True)