Ejemplo n.º 1
0
import os
import sys
import textwrap
import time
import datetime

import timeloop
# we use this for simple little tasks only
# and don't want engage another logger
timeloop.app.logging.disable(level=9999)

import lipyd.settings as settings

__all__ = ['new_logger', 'Logger']

_log_flush_timeloop = timeloop.Timeloop()


def new_logger(name=None, logdir=None, verbosity=None, **kwargs):
    """
    Returns a new logger with default settings (can be customized).

    Parameters
    ----------
    name : str
        Custom name for the log.
    logdir : str
        Path to the directoty to store log files.
    verbosity : int
        Verbosity level, lowest is 0. Messages from levels above this
        won't be written to the log..
Ejemplo n.º 2
0
        switchno = 'switch1'
    elif "2" in component:
        switchno = 'switch2'
    if "toggle" in component:
        statetype = 'Relay_state'
    elif "switch" in component:
        statetype = 'Switch_state'

    sql = "UPDATE Switch SET {} = {} WHERE SwitchNo = '{}'".format(
        statetype, state, switchno)
    cursor.execute(sql)
    db.commit()
    db.close()


tl = timeloop.Timeloop()


@tl.job(interval=timedelta(seconds=1))
def check_switch1_state():
    stime = time.time()
    i = 0
    while time.time() < stime + 0.1:
        i += GPIO.input(15)
    print(i)
    if i > 14:
        print("Switch1: ON")
        switch1state = 1
    else:
        print("Switch1: OFF")
        switch1state = 0
Ejemplo n.º 3
0
import pypath.inputs.mirbase as mirbase_input
import pypath.share.common as common
import pypath.share.session as session_mod
import pypath.share.settings as settings
import pypath.share.cache as cache_mod

# method names for ID types
inputs = {
    'uniprot': 'all_uniprots',
    'swissprot': 'all_swissprots',
    'trembl': 'all_trembls',
    'mirbase': 'mirbase_mature_all',
    'mir-pre': 'mirbase_precursor_all',
}

_reflists_cleanup_timeloop = timeloop.Timeloop()


class ReferenceListManager(session_mod.Logger):
    def __init__(self, cleanup_period=10, lifetime=300):

        session_mod.Logger.__init__(self, name='reflists')

        @_reflists_cleanup_timeloop.job(
            interval=datetime.timedelta(seconds=cleanup_period))
        def _cleanup():

            self._remove_expired()

        _reflists_cleanup_timeloop.start(block=False)
Ejemplo n.º 4
0
    For TrEMBL IDs returns False.
    """

    return is_uniprot(name, organism=organism, swissprot=True)


def is_trembl(name, organism=9606):
    """
    Tells if ``name`` is a TrEMBL ID of ``organism``.
    For SwissProt IDs returns False.
    """

    return is_uniprot(name, organism=organism, swissprot=False)


_cleanup_timeloop = timeloop.Timeloop()


@_cleanup_timeloop.job(interval=datetime.timedelta(seconds=_cleanup_period))
def _cleanup():

    keys = list(globals()['db'].keys())

    for key in keys:

        if time.time() - globals()['_last_used'][key] > _lifetime:

            _remove(key)


_cleanup_timeloop.start(block=False)
Ejemplo n.º 5
0
import time
import timeloop
import logging
import sys
import dotenv

from modules import telegram, weather

hostname = sys.argv[1]
config = dotenv.dotenv_values("Sunscreen-tuya.env")

logging.basicConfig(
    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
    level=logging.INFO)

background = timeloop.Timeloop()

is_closed = None


@background.job(interval=datetime.timedelta(seconds=5))
def update_device_status():
    global is_closed
    global hostname
    global config

    device = tinytuya.CoverDevice(config['DEVICE_ID'], hostname,
                                  config['LOCAL_KEY'])
    device.set_version(3.3)
    device.set_socketRetryLimit(120)
Ejemplo n.º 6
0
                    help='Send data interval in sec')
parser.add_argument('database',
                    nargs='?',
                    default='nalog',
                    type=str,
                    help='Influx database name')
parser.add_argument(
    'cols',
    nargs='*',
    type=str,
    default='time,key,duration,operation,message,status,istatus,report'.split(
        ","),
    help='Comma-separated influx fields')
args = parser.parse_args()

t1 = timeloop.Timeloop()

zabbix_server = "n7701-sys951"
zabbix_host = "n7701-sys420"
home = os.getcwd()
if not os.path.exists(f"{home}/dat"):
    os.makedirs(f"{home}/dat")
sender_exe = "D:/zabbix_agent/bin/win64/zabbix_sender.exe"
influx_exe = "D:/influx/influxdb/influx.exe"
text_cols = ",".join([f'"{x}"' for x in args.cols])
query = f'select {text_cols} from autotests ' \
        f'where time>now()-{args.interval}s order by time desc'
query = query.replace("\"", "\\\"")


@t1.job(interval=timedelta(seconds=args.interval))
Ejemplo n.º 7
0
import timeloop

import pypath.utils.mapping as mapping
import pypath.share.common as common
import pypath.internals.intera as intera
import pypath.resources.urls as urls
import pypath.share.curl as curl
import pypath.inputs.uniprot as uniprot_input
import pypath.utils.seq as _se
import pypath.share.session as session_mod
import pypath.utils.taxonomy as taxonomy
import pypath.share.cache as cache_mod

timeloop.app.logging.disable(level=9999)
_homology_cleanup_timeloop = timeloop.Timeloop()

_logger = session_mod.Logger(name='homology')
_log = _logger._log


class HomologyManager(session_mod.Logger):
    def __init__(self, cleanup_period=10, lifetime=300):

        session_mod.Logger.__init__(self, name='homology')

        @_homology_cleanup_timeloop.job(
            interval=datetime.timedelta(seconds=cleanup_period))
        def _cleanup():

            self._remove_expired()