Beispiel #1
0
    def get_irc_socket_object(self):
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.settimeout(10)

        self.sock = sock

        try:
            sock.connect((self.config['server'], self.config['port']))
        except:
            pp('Cannot connect to server (%s:%s).' % (self.config['server'], self.config['port']), 'error')
            sys.exit()

        sock.settimeout(None)

        sock.send('USER %s\r\n' % self.credentials['username'])
        sock.send('PASS %s\r\n' % self.credentials['oauth_password'])
        sock.send('NICK %s\r\n' % self.credentials['username'])

        if self.check_login_status(sock.recv(1024)):
            pp('Login successful.')
        else:
            pp('Login unsuccessful. (hint: make sure your oauth token is set in self.config/self.config.py).', 'error')
            sys.exit()

        # start threads for channels that have cron messages to run
        for channel in self.config['channels']:
            if channel in self.config['cron']:
                if self.config['cron'][channel]['run_cron']:
                    thread.start_new_thread(cron.cron(self, channel).run, ())
                if self.config['cron'][channel]['refresh_moderators']:
                    thread.start_new_thread(refresh_moderators(channel).run, ())

        self.join_channels(self.channels_to_string(self.config['channels']))

        return sock
Beispiel #2
0
def index():
    #スクレイピングサンプル
    s = scrap.Scraping()
    data = s.collectData()

    #cronサンプル
    c = cron.cron()
    text = c.limp()
    html = render_template('index.html', a=data, b=text)
    return html
Beispiel #3
0
    def get_irc_socket_object(self):
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.settimeout(10)

        self.sock = sock

        try:
            sock.connect((self.config['server'], self.config['port']))
        except:
            pp(
                'Cannot connect to server (%s:%s).' %
                (self.config['server'], self.config['port']), 'error')
            sys.exit()

        sock.settimeout(None)

        sock.send('USER %s\r\n' % self.config['username'])
        sock.send('PASS %s\r\n' % self.config['oauth_password'])
        sock.send('NICK %s\r\n' % self.config['username'])

        if self.check_login_status(sock.recv(1024)):
            pp('Login successful.')
        else:
            pp(
                'Login unsuccessful. (hint: make sure your oauth token is set in self.config/self.config.py).',
                'error')
            sys.exit()

        # sock.send("CAP REQ :twitch.tv/tags\x0d\x0a")
        # sock.send("CAP REQ :twitch.tv/commands\x0d\x0a")
        sock.send("CAP REQ :twitch.tv/membership\r\n")
        sock.send("CAP END\r\n")

        # start threads for channels that have cron messages to run
        for channel in self.config['channels']:
            if channel in self.config['cron']:
                if self.config['cron'][channel]['run_cron']:
                    thread.start_new_thread(cron.cron(self, channel).run, ())

        self.join_channels(self.channels_to_string(self.config['channels']))

        return sock
Beispiel #4
0
def main():
    # set up queue and cron jobs
    upload_queue = list()
    jobs = cron(upload_queue, main_jobs)
    # Start uploader job
    Thread(target=uploader,
           kwargs={
               "cron_obj": jobs,
               "upload_queue": upload_queue
           }).start()
    Thread(target=check_db,
           kwargs={
               "cron_obj": jobs,
               "upload_queue": upload_queue
           }).start()

    # some jobs don't work unless on main thread???
    while True:
        if main_jobs:
            main_jobs.pop(0)()
        time.sleep(1)
Beispiel #5
0
def maincode(ci, send_mail=True, lifetime=None, keepalive=True):
    global stop
    stop = False

    print("lifetime:", lifetime)

    signal.signal(signal.SIGTERM,mysignal)
    signal.signal(signal.SIGINT,mysignal)
    log.info('okerr processor pid: {} ci: {} started as user {}, procsleep: {} seconds'.format(
        os.getpid(), ci, pwd.getpwuid(os.getuid())[0], settings.PROCSLEEP))
    iteration = 0
    
    lastmemtime = 0

    started = time.time()    

    last_iupdated = time.time()

    totalu = 0

    if keepalive:
        log.info('Keepalive indicators...')
        c = 0
        totali = Indicator.objects.filter(ci = ci, disabled = False).count()
        for i in Indicator.objects.filter(ci = ci, disabled = False):
            # log.debug('keep {}'.format(i))
            i.reanimate()
            i.save()
            c += 1
            if not c % 100:
                log.info('.. rescheduled {}/{} indicators'.format(c, totali))

        ka_time = time.time() - started;
        log.info('rescheduled {} indicators in {:.2f}s ({:.2f} i/s)'.format(c, ka_time, float(c)/ka_time))

    while not stop:
        if time.time()>(lastmemtime + 600):
            log.info('okerr-process {} uptime: {} Memory usage: {} (kb)'.\
                format(os.getpid(),
                int(time.time() - started),
                resource.getrusage(resource.RUSAGE_SELF).ru_maxrss))
            lastmemtime=time.time()
 
        u = loop(ci, send_mail)
        totalu += u
        
        if time.time() > last_iupdated + 300:
            log.debug('update {} (totalu: {})'.format(myindicator.name, totalu))
            try:
                myindicator.update(totalu, '{} indicators in {:.2f}s'.format(totalu, time.time() - last_iupdated ))
            except okerrupdate.OkerrExc as e:
                log.error('myindicator {} update error: {}'.format(myindicator.name, e))
            totalu = 0
            last_iupdated = time.time()
            
        if u == 0:
            time.sleep(settings.PROCSLEEP)                    
        else:
            # no sleep, we did something, maybe there is other work
            pass
        cron.cron(log)
        iteration+=1
        reset_queries()
        gc.collect()
        
        if lifetime:
            if time.time() > started + lifetime:
                log.warning('Lifetime {} sec passed. Suicide.'.format(lifetime))
                stop = True

    log.info("stop: {}, quitting".format(stop))
Beispiel #6
0
import cron
#cronサンプル
c = cron.cron()
text = c.limp()
print(text)
Beispiel #7
0
def test_star_hour_can_fire_this_hour():
    assert cron(10, None, 10, 30) == (False, 10, 30)
Beispiel #8
0
def test_if_all_star_then_runs_now():
    assert cron(None, None, 10, 10) == (False, 10, 10)
Beispiel #9
0
def test_cron_does_not_crash(cron_hour, cron_minute, current_hour,
                             current_minute):
    cron(cron_hour, cron_minute, current_hour, current_minute)
Beispiel #10
0
def test_star_minute_can_fire_at_current_minute():
    assert cron(2, None, 2, 10) == (False, 2, 10)
Beispiel #11
0
from time import localtime,strftime
#from datetime import datetime
import datetime
from messaging import messaging
from cron import cron
#from cloudftp import get_serialnumbers
from webcammov import send_wc_pix
import os
from anwesenheit import anwesenheit
import satellites
#from delay_list import szenen_timer

aes = alarm_event()
anw_status = anwesenheit()
mes = messaging()
crn = cron()
#sz_timer = szenen_timer(def_to_run = set_szene)

PS3_IP = '192.168.192.27'
BettPi_PIP = '192.168.192.24'

schluessellist = {'Christoph':'C86000BDB9E9EE10800000B0','Sabina':'6CF049E0FBE2FD40B95F273B', 'Huckle':'00D0C9CCDE48EDB14000F139','Russ':'C86000BDB9F2EE10AA310081'}
ezcont_interlock = {'Video_Audio':PS3_IP, 'BettPi':BettPi_PIP, 'Sonos_Wohnzi':PS3_IP, sn.WohnZi:PS3_IP}

tv_remote = remotecontrol(constants.eigene_IP,'192.168.192.26','00:30:1b:a0:2f:05')
tv_remote_lan = remotecontrol(constants.eigene_IP,'192.168.192.29','00:30:1b:a0:2f:05')
no_event = ['Alarm','Achtung','Hinweis','Hue_Meldung','set_hinweis']

ezcontrol = myezcontrol(constants.xs1_.IP,constants.xs1_.USER,constants.xs1_.PASS)

router = satellites.get_satellite("Router")