Example #1
0
def main():
    today = date.today()
    sunRiseHour, sunRiseMins, sunSetHour, sunSetMins = calcsunriseandsunset(
        today)
    print sunRiseHour, sunRiseMins, sunSetHour, sunSetMins
    now = datetime.now()
    nowHour = now.hour
    nowMins = now.minute

    daytime = False

    if nowHour > sunRiseHour and nowHour < sunSetHour:
        daytime = True
    if nowHour == sunRiseHour and nowMins >= sunRiseMins:
        daytime = True
    if nowHour == sunSetHour and nowMins < sunSetMins:
        daytime = True

    if daytime == True:
        print "Its daytime"
        itsdaytime = True
    else:
        print "Its nighttime"
        itsdaytime = False

    quit = False

    while (quit == False):
        sleep(30)
        today = date.today()
        sunRiseHour, sunRiseMins, sunSetHour, sunSetMins = calcsunriseandsunset(
            today)
        now = datetime.now()
        print "Its "
        print now
        nowHour = now.hour
        nowMins = now.minute
        daytime = False
        if nowHour > sunRiseHour and nowHour < sunSetHour:
            daytime = True
        if nowHour == sunRiseHour and nowMins >= sunRiseMins:
            daytime = True
        if nowHour == sunSetHour and nowMins < sunSetMins:
            daytime = True

        if itsdaytime == True and daytime == False:
            push("Closing door")
            print "Its nighttime at "
            print now
            itsdaytime = False

        if itsdaytime == False and daytime == True:
            push("Opening Door")
            print "Its daytime at "
            print now
            itsdaytime = True
Example #2
0
def notice_me(user_id, filter):
    soup = get_profile_page(user_id, filter)
    # 定位微博正文的div
    profiles = soup.find_all(id=re.compile('^M_.*?'))
    nearest_one = profiles[0]
    # 排除第一条是置顶微博的情况
    if profiles[0].find_all('span', class_='kt'):
        nearest_one = profiles[1]
    print(datetime.now())
    if '分钟' in nearest_one.find('span', class_="ct").get_text():
        try:
            push('微博更新提醒', msg=nearest_one.get_text())
            print('Send success!!')
        except Exception as e:
            print('Send failed!!')
Example #3
0
def notice_me_old(filter):
    an_hour_ago = (datetime.now() - timedelta(hours=1)).strftime("%m月%d日%H:%M")
    soup = get_profile_page(user_id, filter)
    nearest_one = soup.find_all(id=re.compile('^M_.*?'))[0]
    # print(nearest_one.get_text())
    print(nearest_one.find('span', class_="ct").get_text())
    rep_time = ''
    for i in nearest_one.find('span', class_="ct").get_text().split()[:2]:
        rep_time += i
    print(rep_time)
    print(an_hour_ago)
    print(datetime.now())
    if rep_time > an_hour_ago:
        push('微博更新提醒', msg=nearest_one.get_text())
    print('Done!')
Example #4
0
def closeDoor():
    status = WORKING
    finishtime = timer() + CLOSE_TIME
    print finishtime
    push("Starting Motor")
    motor(REVERSE)  #start the motor closing

    while status == WORKING:
        if timer() >= finishtime:  #timer expired
            debugprint("TIMER EXPIRED")
            status = TIMEOUT
            push("Time Out - Check Ramp")

    motor(STOPMOTOR)
    push("Stopping Motor")
    return (status)
Example #5
0
    return


def debug(x):
    print(x)
    return


# This is the start of the main program

coords = {'longitude': 0.34, 'latitude': 51.1}
sun = Sun()

print sun.getSunriseTime(coords)
# Sunrise time UTC (decimal, 24 hour format)
push("hi")
print sun.getSunriseTime(coords)['hr']
print sun.getSunriseTime(coords)['min']

print sun.getSunsetTime(coords)['hr']
print sun.getSunsetTime(coords)['min']

GPIO.setmode(GPIO.BOARD)
PIR_PIN = 26
GPIO.setup(PIR_PIN, GPIO.IN)

print howfar()

try:
    print("testing c to exit")
    sleep(2)
Example #6
0
def main():
    log = logging.getLogger(__name__)

    log.setLevel(logging.DEBUG)

    handler = logging.handlers.SysLogHandler(address='/dev/log')

    formatter = logging.Formatter('%(module)s.%(funcName)s: %(message)s')
    handler.setFormatter(formatter)

    log.addHandler(handler)
    today = date.today()
    sunRiseHour, sunRiseMins, sunSetHour, sunSetMins = calcsunriseandsunset(
        today)
    print sunRiseHour, sunRiseMins, sunSetHour, sunSetMins
    now = datetime.now()
    nowHour = now.hour
    nowMins = now.minute
    #push("HenHotel starting")

    GPIO.setmode(GPIO.BOARD)

    daytime = False

    if nowHour > sunRiseHour and nowHour < sunSetHour:
        daytime = True
    if nowHour == sunRiseHour and nowMins >= sunRiseMins:
        daytime = True
    if nowHour == sunSetHour and nowMins < sunSetMins:
        daytime = True

    if daytime == True:
        print "Its daytime"
        log.debug('Daytime')
        itsdaytime = True
    else:
        print "Its nighttime"
        log.debug('Nighttime')
        itsdaytime = False

    quit = False
    oldHour = nowHour
    try:

        while (quit == False):
            sleep(
                30
            )  # Extend this later, or replace with an interruptable sleep
            today = date.today()
            sunRiseHour, sunRiseMins, sunSetHour, sunSetMins = calcsunriseandsunset(
                today)
            #Add a delay after sunset do give the birds time to go in
            sunSetMins += DELAY
            if sunSetMins >= 60:
                sunSetHour += 1
                sunSetMins -= 60

            now = datetime.now()
            nowHour = now.hour
            nowMins = now.minute
            daytime = False
            if nowHour > sunRiseHour and nowHour < sunSetHour:
                daytime = True
            if nowHour == sunRiseHour and nowMins >= sunRiseMins:
                daytime = True
            if nowHour == sunSetHour and nowMins < sunSetMins:
                daytime = True

            if itsdaytime == True and daytime == False:
                message = "Door Starting to close - distance = " + str(
                    howfar()) + "cm"
                push(message)
                log.debug(message)
                closeDoor()
                message = "Door should be closed - distance = " + str(
                    howfar()) + "cm"
                push(message)
                print "Its nighttime at "
                print now
                itsdaytime = False

            if itsdaytime == False and daytime == True:
                message = "Door Starting to open - distance = " + str(
                    howfar()) + "cm"
                push(message)
                log.debug(message)
                openDoor()
                message = "Door should be open - distance = " + str(
                    howfar()) + "cm"
                push(message)
                print "Its daytime at "
                print now
                itsdaytime = True
    # End of while


#End of main
#test

#except:
# this catches ALL other exceptions including errors.
# You won't get any error messages for debugging
# so only use it once your code is working
#   print "Other error or exception occurred!"

    finally:
        GPIO.cleanup()  # this ensures a clean exit
        print "In Finally function"
        push("In Finally, not sure what happened - system needs a reboot")