Exemple #1
0
def validate_config(config):
    if not config.has_section('general'):
        die("No [general] section found.")

    twiggy.quickSetup(name2level(config.get('general', 'log.level')),
                      config.get('general', 'log.file'))

    if not config.has_option('general', 'targets'):
        die("No targets= item in [general] found.")

    targets = config.get('general', 'targets')
    targets = [t.strip() for t in targets.split(",")]

    for target in targets:
        if target not in config.sections():
            die("No [%s] section found." % target)

    for option in ['bitly.api_user', 'bitly.api_key']:
        if not config.has_option('general', option):
            log.name('config').warning(
                "URLs will not be shortened with bit.ly")

    # Validate each target one by one.
    for target in targets:
        service = config.get(target, 'service')
        if not service:
            die("No 'service' in [%s]" % target)

        if service not in SERVICES:
            die("'%s' in [%s] is not a valid service." % (service, target))

        # Call the service-specific validator
        SERVICES[service].validate_config(config, target)
Exemple #2
0
def validate_config(config):
    if not config.has_section("general"):
        die("No [general] section found.")

    twiggy.quickSetup(name2level(config.get("general", "log.level")), config.get("general", "log.file"))

    if not config.has_option("general", "targets"):
        die("No targets= item in [general] found.")

    targets = config.get("general", "targets")
    targets = [t.strip() for t in targets.split(",")]

    for target in targets:
        if target not in config.sections():
            die("No [%s] section found." % target)

    for option in ["bitly.api_user", "bitly.api_key"]:
        if not config.has_option("general", option):
            log.name("config").warning("URLs will not be shortened with bit.ly")

    # Validate each target one by one.
    for target in targets:
        service = config.get(target, "service")
        if not service:
            die("No 'service' in [%s]" % target)

        if service not in SERVICES:
            die("'%s' in [%s] is not a valid service." % (service, target))

        # Call the service-specific validator
        SERVICES[service].validate_config(config, target)
Exemple #3
0
def pull(dry_run, flavor):
    """ Pull down tasks from forges and add them to your taskwarrior tasks.

    Relies on configuration in bugwarriorrc
    """
    twiggy.quickSetup()
    try:
        main_section = _get_section_name(flavor)

        # Load our config file
        config = load_config(main_section)

        tw_config = TaskWarriorBase.load_config(get_taskrc_path(config, main_section))
        lockfile_path = os.path.join(os.path.expanduser(tw_config["data"]["location"]), "bugwarrior.lockfile")

        lockfile = PIDLockFile(lockfile_path)
        lockfile.acquire(timeout=10)
        try:
            # Get all the issues.  This can take a while.
            issue_generator = aggregate_issues(config, main_section)

            # Stuff them in the taskwarrior db as necessary
            synchronize(issue_generator, config, main_section, dry_run)
        finally:
            lockfile.release()
    except LockTimeout:
        log.name("command").critical(
            "Your taskrc repository is currently locked. "
            "Remove the file at %s if you are sure no other "
            "bugwarrior processes are currently running." % (lockfile_path)
        )
    except:
        log.name("command").trace("error").critical("oh noes")
Exemple #4
0
def pull(dry_run, flavor, interactive):
    """ Pull down tasks from forges and add them to your taskwarrior tasks.

    Relies on configuration in bugwarriorrc
    """
    twiggy.quickSetup()
    try:
        main_section = _get_section_name(flavor)

        # Load our config file
        config = load_config(main_section, interactive)

        lockfile_path = os.path.join(get_data_path(), 'bugwarrior.lockfile')
        lockfile = PIDLockFile(lockfile_path)
        lockfile.acquire(timeout=10)
        try:
            # Get all the issues.  This can take a while.
            issue_generator = aggregate_issues(config, main_section)

            # Stuff them in the taskwarrior db as necessary
            synchronize(issue_generator, config, main_section, dry_run)
        finally:
            lockfile.release()
    except LockTimeout:
        log.name('command').critical(
            'Your taskrc repository is currently locked. '
            'Remove the file at %s if you are sure no other '
            'bugwarrior processes are currently running.' % (
                lockfile_path
            )
        )
    except RuntimeError as e:
        log.name('command').critical("Aborted (%s)" % e)
    except:
        log.name('command').trace('error').critical('oh noes')
Exemple #5
0
def validate_config(config):
    if not config.has_section('general'):
        die("No [general] section found.")

    twiggy.quickSetup(
        name2level(config.get('general', 'log.level')),
        config.get('general', 'log.file')
    )

    if not config.has_option('general', 'targets'):
        die("No targets= item in [general] found.")

    targets = config.get('general', 'targets')
    targets = [t.strip() for t in targets.split(",")]

    for target in targets:
        if target not in config.sections():
            die("No [%s] section found." % target)

    # Validate each target one by one.
    for target in targets:
        service = config.get(target, 'service')
        if not service:
            die("No 'service' in [%s]" % target)

        if service not in SERVICES:
            die("'%s' in [%s] is not a valid service." % (service, target))

        # Call the service-specific validator
        SERVICES[service].validate_config(config, target)
Exemple #6
0
def main():
    # Begin by parsing options and ensuring existence of input and output paths.
    quickSetup()
    parser = get_parser()
    options = parser.parse_args()
    output_path = options.output_path[0]
    pathlog = log.fields(output_path=output_path)
    if os.path.isdir(output_path):
        pathlog.info("directory OK")
    elif os.path.exists(output_path):
        pathlog.error("is NOT a directory")
        sys.exit(1)
    else:
        pathlog.error("does NOT exist")
        sys.exit(1)
    all_repos_valid = True
    for repo_path in options.repos:
        repolog = log.fields(repo_path=repo_path)
        try:
            repo = git.Repo(repo_path)
        except git.InvalidGitRepositoryError:
            repolog.error("is NOT a repository")
            all_repos_valid = False
        except git.NoSuchPathError:
            repolog.error("does NOT exist")
            all_repos_valid = False
        else:
            repolog.info("repository OK")
            repos[repo_path] = repo
    if not all_repos_valid:
        sys.exit(1)
    process_all_repos(repos)
Exemple #7
0
def pull(dry_run, flavor, interactive):
    """ Pull down tasks from forges and add them to your taskwarrior tasks.

    Relies on configuration in bugwarriorrc
    """
    twiggy.quickSetup()
    try:
        main_section = _get_section_name(flavor)

        # Load our config file
        config = load_config(main_section, interactive)

        lockfile_path = os.path.join(get_data_path(), 'bugwarrior.lockfile')
        lockfile = PIDLockFile(lockfile_path)
        lockfile.acquire(timeout=10)
        try:
            # Get all the issues.  This can take a while.
            issue_generator = aggregate_issues(config, main_section)

            # Stuff them in the taskwarrior db as necessary
            synchronize(issue_generator, config, main_section, dry_run)
        finally:
            lockfile.release()
    except LockTimeout:
        log.name('command').critical(
            'Your taskrc repository is currently locked. '
            'Remove the file at %s if you are sure no other '
            'bugwarrior processes are currently running.' % (lockfile_path))
    except RuntimeError as e:
        log.name('command').critical("Aborted (%s)" % e)
    except:
        log.name('command').trace('error').critical('oh noes')
Exemple #8
0
def validate_config(config, main_section):
    if not config.has_section(main_section):
        die("No [%s] section found." % main_section)

    twiggy.quickSetup(
        name2level(config.get(main_section, 'log.level')),
        config.get(main_section, 'log.file')
    )

    if not config.has_option(main_section, 'targets'):
        die("No targets= item in [%s] found." % main_section)

    targets = config.get(main_section, 'targets')
    targets = filter(lambda t: len(t), [t.strip() for t in targets.split(",")])

    if not targets:
        die("Empty targets= item in [%s]." % main_section)

    for target in targets:
        if target not in config.sections():
            die("No [%s] section found." % target)

    # Validate each target one by one.
    for target in targets:
        service = config.get(target, 'service')
        if not service:
            die("No 'service' in [%s]" % target)

        if service not in SERVICES:
            die("'%s' in [%s] is not a valid service." % (service, target))

        # Call the service-specific validator
        SERVICES[service].validate_config(config, target)
Exemple #9
0
def pull():
    """ Pull down tasks from forges and add them to your taskwarrior tasks.

    Relies on configuration in ~/.bugwarriorrc
    """
    twiggy.quickSetup()
    try:
        # Load our config file
        config = load_config()

        tw_config = TaskWarriorBase.load_config(get_taskrc_path(config))
        lockfile_path = os.path.join(
            os.path.expanduser(tw_config['data']['location']),
            'bugwarrior.lockfile')

        lockfile = PIDLockFile(lockfile_path)
        lockfile.acquire(timeout=10)
        try:
            # Get all the issues.  This can take a while.
            issue_generator = aggregate_issues(config)

            # Stuff them in the taskwarrior db as necessary
            synchronize(issue_generator, config)
        finally:
            lockfile.release()
    except LockTimeout:
        log.name('command').critical(
            'Your taskrc repository is currently locked. '
            'Remove the file at %s if you are sure no other '
            'bugwarrior processes are currently running.' % (lockfile_path))
    except:
        log.name('command').trace('error').critical('oh noes')
Exemple #10
0
def setup_logging(level = 'DEBUG', file = None):
    """
    Initialize the logging

    TODO: More advanced configuration for logging, based on config?
    """

    quickSetup(min_level = getattr(levels, level), file = file)
Exemple #11
0
    def __init__(self, root_src, root_dst):
        '''
            Setup the base options of the copy/convert setup
        '''
        self.src_root_dir = root_src
        self.dst_root_dir = root_dst
        self.log_root_dir = os.path.join(self.dst_root_dir, 'logs')
        self.log_processing = os.path.join(self.log_root_dir, 'processing.log')

        # quickSetup(file=self.log_processing)
        quickSetup()
        self.log_name = log.name('files')

        self.cur_file = None
Exemple #12
0
    def __init__(self, root_src, root_dst):
        '''
            Setup the base options of the copy/convert setup
        '''
        self.src_root_dir = root_src
        self.dst_root_dir = root_dst
        self.log_root_dir = os.path.join(self.dst_root_dir, 'logs')
        self.log_processing = os.path.join(self.log_root_dir, 'processing.log')

        # quickSetup(file=self.log_processing)
        quickSetup()
        self.log_name = log.name('files')

        self.cur_file = None
Exemple #13
0
    def __init__(self, patterns, directories, log=None, log_level=None):
        if log is None:
            log = twiggy.log
            twiggy.quickSetup(min_level=log_level, file=sys.stderr)
        self.log = log

        self.patterns = patterns
        self.log.fields(patterns=patterns).debug("using config")
        self.directories = directories
        watch_manager = self._watch_manager = pyinotify.WatchManager()
        handler = self.EventHandler(self.check_file)
        notifier = self._notifier = pyinotify.Notifier(watch_manager, handler)
        for directory in self.directories:
            self.log.fields(directory=directory).debug("watching")
            watch_manager.add_watch(directory, self._mask, rec=True)
Exemple #14
0
	def validate_config(self, config):

		# Logging
		twiggy.quickSetup(levels.INFO)

		# [general]
		if not config.has_section('general'):
			die("No [general] section found.")

		# [general] > targets
		if not config.has_option('general', 'targets'):
			die("No targets= item in [general] found.")

		for target in self.get_targets_list(config):
			if target not in config.sections():
				die("No [%s] section found." % target)
			if not config.has_option(target, 'service'):
				die("No 'service=...' option in [%s] section" % (target))
Exemple #15
0
def pull():
    """ Pull down tasks from forges and add them to your taskwarrior tasks.

    Relies on configuration in ~/.bugwarriorrc
    """
    twiggy.quickSetup()
    try:
        # Load our config file
        config = load_config()

        tw_config = TaskWarriorBase.load_config(get_taskrc_path(config))
        lockfile_path = os.path.join(
            os.path.expanduser(
                tw_config['data']['location']
            ),
            'bugwarrior.lockfile'
        )

        lockfile = PIDLockFile(lockfile_path)
        lockfile.acquire(timeout=10)
        try:
            # Get all the issues.  This can take a while.
            issue_generator = aggregate_issues(config)

            # Stuff them in the taskwarrior db as necessary
            synchronize(issue_generator, config)
        finally:
            lockfile.release()
    except LockTimeout:
        log.name('command').critical(
            'Your taskrc repository is currently locked. '
            'Remove the file at %s if you are sure no other '
            'bugwarrior processes are currently running.' % (
                lockfile_path
            )
        )
    except:
        log.name('command').trace('error').critical('oh noes')
Exemple #16
0
    def __init__(self, max_recursive=5):
        self.src_root_dir = os.path.join(os.sep, 'media', 'src')
        self.dst_root_dir = os.path.join(os.sep, 'media', 'dst')
        self.log_root_dir = os.path.join(self.dst_root_dir, 'logs')
        self.log_processing = os.path.join(self.log_root_dir, 'processing.log')

        self.recursive = 0
        self.max_recursive = max_recursive

        # quickSetup(file=self.log_processing)
        quickSetup()
        self.log_name = log.name('files')

        self.cur_file = None

        subtypes_apps = [
            (mimes_office, self._office_related),
            (mimes_pdf, self._pdf),
            (mimes_xml, self._office_related),
            (mimes_ms, self._executables),
            (mimes_compressed, self._archive),
            (mimes_data, self._binary_app),
        ]
        self.subtypes_application = self._init_subtypes_application(subtypes_apps)

        self.mime_processing_options = {
            'text': self.text,
            'audio': self.audio,
            'image': self.image,
            'video': self.video,
            'application': self.application,
            'example': self.example,
            'message': self.message,
            'model': self.model,
            'multipart': self.multipart,
            'inode': self.inode,
        }
Exemple #17
0
def test_quickSetup(mocker):
    mocker.patch('twiggy.quick_setup')

    def myfilt(msg):
        return True

    twiggy.quickSetup()
    twiggy.quickSetup(file=None)
    twiggy.quickSetup(file=sys.stdout)

    assert twiggy.quick_setup.call_args_list == [mocker.call(), mocker.call(file=None),
                                                 mocker.call(file=sys.stdout)]
Exemple #18
0
def test_quickSetup(mocker):
    mocker.patch('twiggy.quick_setup')

    def myfilt(msg):
        return True

    twiggy.quickSetup()
    twiggy.quickSetup(file=None)
    twiggy.quickSetup(file=sys.stdout)

    assert twiggy.quick_setup.call_args_list == [
        mocker.call(),
        mocker.call(file=None),
        mocker.call(file=sys.stdout)
    ]
Exemple #19
0
# Gateway between Xively and JeeNodes sensors
# Programmed by Igor Steiner
# 2014-03-15	correct the log and diagnostic code
# 2014-03-22	bug fixes
# 2014-12-26	read cumulative gas values (day, month) from JeeNode instead calculate on RPi, add battery value B22
# 2015-12-06    change the payload of external RoomNode and other optimizations

import serial, os
import sys
import requests
import json
import time
import twiggy as tw

tw.quickSetup(file='/home/pi/pachube/pachube.log')
tw.log.info('starting pachube_post.py')
firstStart=True
previousGasMeterHour = previousGasMeterDay = previousGasMeterMonth = 0
diffGasMeterHour = diffGasMeterDay = diffGasMeterMonth = 0
t0_hour = t0_day = t0_month = time.localtime()
print "time: ",time.asctime()

class SimpleSensor:
	def __init__(self, input_string):
		self.get_string_split = input_string[:52].split() # split string but only first 52 characters
		self.temperature = float (int(self.get_string_split[3])*0x100+int(self.get_string_split[2]))/10
		self.gasMeter = float (int(self.get_string_split[7])*0x1000000+int(self.get_string_split[6])*0x10000+int(self.get_string_split[5])*0x100+int(self.get_string_split[4]))/10
		self.counter = int(self.get_string_split[8])
		self.battery = float (int(self.get_string_split[9]))/10
		self.gasPrevDay = float (int(self.get_string_split[11])*0x100+int(self.get_string_split[10]))/10
		self.gasPrevMonth = float (int(self.get_string_split[13])*0x100+int(self.get_string_split[12]))/10
Exemple #20
0
        tw.log.error(log_message)

def write_to_db():
    query_string = 'insert into logs (time_stamp, value, response) values (?,?,?)'
    db_cursor.execute(query_string, (dt.datetime.now(), data_value, first_response))
    db_connection.commit()


s = serial.Serial('/dev/ttyUSB0',
                  baudrate=115200,
                  timeout=1)

db_connection = sqlite3.connect('./database.db')
db_cursor = db_connection.cursor()

tw.quickSetup(file='gprs.log')
tw.log.info('---------------------')
tw.log.info('starting gprs_post.py')
tw.log.info('---------------------')


while (1):
    tw.log.info('-- top of loop --')

    data_value = read_ain2()

    tw.log.info('data_value = ' + str(data_value))

    initiate_modem()
    post_nimbits_staggered(data_value)
    first_response = parse_response()
Exemple #21
0
                    liveness = CONFIG['HEART_LIVE']
                if time.time() > heartbeat:
                    heartbeat = time.time() + CONFIG['HEART_INTER']
                    logger.debug('HEARTBEAT TO: %s' % self.identity)
                    self.worker.send('HEARTBEAT')

        self.worker.close()
        self.ctx.term()

    def createSocket(self):
        self.identity = utils.identity()
        logger.debug('NEW IDENTITY: %s ' % self.identity)
        self.worker = self.ctx.socket(zmq.XREQ)
        self.worker.setsockopt(zmq.IDENTITY, self.identity)
        self.worker.connect('tcp://%s' % CONFIG['ROUTER'])
        self.worker.send('READY')

if __name__ == '__main__':

    twiggy.quickSetup(twiggy.levels.INFO)
    logger = twiggy.log

    cpu = multiprocessing.cpu_count()
    logger.info('DETECTED %s CPUs STARTING %s WORKERS' % (cpu, cpu))
    processes = [multiprocessing.Process(target=Worker, args=()) for i in range(cpu)]
    [p.start() for p in processes]  
    [p.join() for p in processes]



Exemple #22
0
import requests
import json
import random
import time
import twiggy as tw
import serial
import sqlite3
import datetime as dt
import beaglebone as bb

# database objects
db_connection = sqlite3.connect('./sawtooth.db')
db_cursor = db_connection.cursor()

# setup twiggy logging
tw.quickSetup(file='sawtooth.log')
tw.log.info('starting post_random.py')

nimbits_stream = "Test_Stream_2"
data_value = 0

# sleep for a minute, send random number to pachube in json format
while 1:
    tw.log.info("--- top of loop ---")
    time_stamp = dt.datetime.now()

    tw.log.info("data value = " + str(data_value))

    status_code = bb.post_nimbits_http(nimbits_stream, data_value)

    bb.write_to_db(time_stamp, data_value, status_code, db_cursor, db_connection)
Exemple #23
0
#! /usr/bin/env python
import twiggy

import tempfile
import os

fname = tempfile.mktemp()

twiggy.quickSetup(twiggy.levels.DEBUG, fname)
import timeit

loops = 100000

t = min(
    timeit.repeat(number=loops,
                  stmt="""log.debug('hello, ladies')""",
                  setup="""
import twiggy
log=twiggy.log.name('donjuan')
"""))
os.remove(fname)

print "{0:.3f} sec for {1:n} loops".format(t, loops)
Exemple #24
0
import beaglebone as bb

# logging variables
stream_name = '603_Test_Stream'

# modem hardware
s = serial.Serial('/dev/ttyUSB0',
                  baudrate=115200,
                  timeout=1)

# database objects
db_connection = sqlite3.connect('./database.db')
db_cursor = db_connection.cursor()

# set up logging
tw.quickSetup(file='kitchen.log')
tw.log.info('---------------------')
tw.log.info('starting kitchen_bb.py')
tw.log.info('---------------------')

while (1):
    tw.log.info('-- top of loop --')

    # get sensor reading and timestamp
    data_value = bb.read_ain2()
    time_stamp = dt.datetime.now().isoformat()

    tw.log.info('data_value = ' + str(data_value))

    # post to nimbits over gprs
    bb.initiate_modem_nimbits(s)
Exemple #25
0
import hashlib
import datetime, time


import twiggy
from twiggy import log
from termcolor import colored
import weakref
from _collections import defaultdict
from __builtin__ import issubclass
from unohelper import inspect
import inspect as insp

from yapsy.PluginManager import PluginManager as YPM, IPlugin

twiggy.quickSetup()
logger=log
logger.name('avlib')

cwd=sys.path[0]+'/'

def parsePage(link,pattern):
    page=urlopen(link).read()
    result=re.findall(pattern,page)
    return result

class di(object):
    def __getitem__(self,key):
        return self.__dict__[key]
    def __setitem__(self,key,value):
        self.__dict__[key]=value
Exemple #26
0
def main():
    # Parse options and ensuring existence of input and output paths.
    quickSetup()
    parser = get_parser()
    options = parser.parse_args()
    if options.pickle is not None:
        options.pickle = options.pickle[0]  # list -> string
        unpickle_all(options.pickle)
    else:
        # Do nothing; keep initial state.
        pass
    if options.email_map:
        for email_mapping in options.email_map:
            email_from, email_to = email_mapping.split(':')
            email_maps[email_from] = email_to
            log.fields(email_from=email_from, email_to=email_to).info('email mapping')
    if options.email_ignore:
        email_ignores.update(options.email_ignore)
    output_path = options.output_path[0]
    pathlog = log.fields(output_path=output_path)
    if os.path.isdir(output_path):
        pathlog.info('directory OK')
    elif os.path.exists(output_path):
        pathlog.error('is NOT a directory')
        sys.exit(1)
    else:
        pathlog.error('does NOT exist')
        sys.exit(1)
    all_repos_valid = True
    for repo_path in options.repos:
        repolog = log.fields(repo_path=repo_path)
        try:
            repo = git.Repo(repo_path)
        except git.InvalidGitRepositoryError:
            repolog.error('is NOT a repository')
            all_repos_valid = False
        except git.NoSuchPathError:
            repolog.error('does NOT exist')
            all_repos_valid = False
        else:
            repolog.info('repository OK')
            tree = repo.tree('master')
            transcription_json = load(tree['transcription.json'].data_stream)
            repo_name = os.path.split(repo_path)[-1]
            git_repos_by_name[repo_name] = repo
            if repo_path not in repo_infos_by_path:
                # Create new RepoInfo structure.
                repo_infos_by_path[repo_path] = repo_infos_by_name[repo_name] = RepoInfo(
                    name=repo_name,
                    transcription=transcription_json,
                    authors=set(),
                    snippets={},
                )
            else:
                # Keep existing RepoInfo structure.
                pass
    if not all_repos_valid:
        sys.exit(1)
    process_all_repos()
    process_all_authors()
    create_all_output(output_path)
    if options.pickle is not None:
        pickle_all(options.pickle)
Exemple #27
0
#! /usr/bin/env python
import twiggy

import tempfile
import os

fname = tempfile.mktemp()

twiggy.quickSetup(twiggy.levels.DEBUG, fname)
import timeit

loops = 100000

t = min(timeit.repeat( number = loops,
stmt="""log.debug('hello, ladies')""",
setup="""
import twiggy
log=twiggy.log.name('donjuan')
"""))
os.remove(fname)

print("{0:.3f} sec for {1:n} loops".format(t, loops))
Exemple #28
0
import requests
import json
import random
import time
import twiggy as tw
import serial

s = serial.Serial('/dev/ttyUSB0', baudrate=9600, timeout=1)

tw.quickSetup(file='pachube.log')
tw.log.info('starting pachube_post.py')

# authentication headers
headers = {"X-PachubeApiKey": "yKcC6HugqvNtshxI6qEreOPYs9qQG7gZfloc3JQWPbQ"}

def post_nimbits(value):
    nimbits_data = {"email":"*****@*****.**",
                    "secret":"01787ade-c6d6-4f9b-8b86-20850af010d9",
                    "point":"603_Kitchen",
                    "value":value}

    try:
        r = requests.post("http://app.nimbits.com/service/currentvalue", data=nimbits_data)
    except:
        tw.log.trace('error').error('bad post to nimbits')
    log_message = 'nimbits response value = ' + str(r.status_code)
    if r.status_code == 200:
        tw.log.info(log_message)
    else:
        tw.log.error(log_message)
Exemple #29
0
import requests
import json
import random
import time
import twiggy as tw
import serial
import sqlite3
import datetime as dt

# set up database connection
db_connection = sqlite3.connect('./random.db')
db_cursor = db_connection.cursor()

# setup twiggy logging
tw.quickSetup(file='random.log')
tw.log.info('starting post_random.py')


def post_nimbits(value):
    nimbits_data = {"email":"*****@*****.**",
                    "secret":"01787ade-c6d6-4f9b-8b86-20850af010d9",
                    "point":"603_Test_Stream",
                    "value":value}

    try:
        r = requests.post("http://app.nimbits.com/service/currentvalue", data=nimbits_data)
    except:
        tw.log.trace('error').error('bad post to nimbits')
    log_message = 'nimbits response value = ' + str(r.status_code)
    if r.status_code == 200:
        tw.log.info(log_message)
Exemple #30
0
import sys

import twiggy


log = twiggy.log
min_log_level = twiggy.levels.INFO
log_file = sys.stderr

try:
    from local_config import *
except ImportError:
    pass

twiggy.quickSetup(min_level=min_log_level, file=log_file)
Exemple #31
0
import beaglebone as bb

# logging variables
stream_name = 'Modi_Lab'

# modem hardware
s = serial.Serial('/dev/ttyUSB0',
                  baudrate=115200,
                  timeout=1)

# database objects
db_connection = sqlite3.connect('./database.db')
db_cursor = db_connection.cursor()

# set up logging
tw.quickSetup(file='modilab.log')
tw.log.info('---------------------')
tw.log.info('starting modilab_bb.py')
tw.log.info('---------------------')

while (1):
    tw.log.info('-- top of loop --')

    # get sensor reading and timestamp
    data_value = bb.read_ain2()
    time_stamp = dt.datetime.now().isoformat()

    tw.log.info('data_value = ' + str(data_value))

    # post to nimbits over gprs
    bb.initiate_modem_nimbits(s)
Exemple #32
0
# Gateway between Xively and JeeNodes sensors
# Programmed by Igor Steiner
# 2014-03-15	correct the log and diagnostic code
# 2014-03-22	bug fixes
# 2014-12-26	read cumulative gas values (day, month) from JeeNode instead calculate on RPi, add battery value B22
# 2015-12-06    change the payload of external RoomNode and other optimizations
# 2017-03-17	add in requests.put(...  verify=False) otherwise is ssl error

import serial, os
import sys
import requests
import json
import time
import twiggy as tw

tw.quickSetup(file='/home/pi/pachube/pachube.log')
tw.log.info('starting pachube_post.py')
firstStart = True
previousGasMeterHour = previousGasMeterDay = previousGasMeterMonth = 0
diffGasMeterHour = diffGasMeterDay = diffGasMeterMonth = 0
t0_hour = t0_day = t0_month = time.localtime()
print "time: ", time.asctime()


class SimpleSensor:
    def __init__(self, input_string):
        self.get_string_split = input_string[:52].split(
        )  # split string but only first 52 characters
        self.temperature = float(
            int(self.get_string_split[3]) * 0x100 +
            int(self.get_string_split[2])) / 10
Exemple #33
0
from wsgiref.simple_server import make_server
import twiggy as tw
import sqlite3
from config import host_ip
import datetime as dt

server_ip = host_ip

# example of post code at
# http://webpython.codepoint.net/wsgi_request_parsing_post

db_connection = sqlite3.connect('./database.db')
db_cursor = db_connection.cursor()


tw.quickSetup(file='log_simple_server.log')
tw.log.info('starting simple_server.py')

def app(environ, start_response):

    '''
    for key in environ.keys():
        print key, environ[key]
    '''

    if environ.get('REQUEST_METHOD') == 'POST':
        tw.log.info('POST received')
        # if post, parse and insert into database
        body = ''
        try:
            length = int(environ.get('CONTENT_LENGTH', '0'))