Exemple #1
0
def create_app(config_name="dev"):
    app = Flask(__name__)
    config_model = config[config_name]
    config_model.init_config()
    app.config.from_object(config[config_name])
    setattr(app, "handlers", setup())
    setattr(app, "logger", logger)
    setattr(
        app, "statistic", {
            'cpu_util': [],
            'memory_util': {},
            'disk_util': {},
            'nic_util': {},
            'disk_io_util': {}
        })
    # app.logger.removerHandler(default_handler)
    register_extensions(app)
    register_blueprints(app)
    register_request_hook(app)
    # register_async_thread(app)
    # register_blueprints(app)
    # register_errors(app)

    # timer process
    # create a posix ipc queue
    timer_queue = posixmq.Queue('/timer_msq')
    setattr(app, "timer_msq", timer_queue)
    timer_start = threading.Timer(2, init_timer, [timer_queue, app])
    timer_start.start()
    logger.info(
        'create_app ok ................................................')
    return app
 def __init__(self):
     self.camera_queue = posixmq.Queue('/camera_control')
     self.segment_queue = Queue()
     self.identify_queue = Queue()
     self.thread1 = None
     self.thread2 = None
     self.thread3 = None
    def __init__(self, nets):
        super().__init__()
        self.exit_queue = posixmq.Queue('/signals')

        self.filter = Identificator('filter2')
        self.identificators = []
        if type(nets) == type([]):
            for net in nets:
                self.identificators += [Identificator(net)]
        elif type(nets) == type('string'):
            self.identificators += [Identificator(nets)]
        else:
            TypeError('The constructor param must be of type array or string')
def init():
    util.LoggerControl().get_logger('control_camera').info(
        'Camera control is initializing...')

    cap = cv2.VideoCapture(0)
    util.LoggerControl().get_logger('control_camera').debug(
        'Video capture initialized')

    queue = posixmq.Queue('/camera_control')
    util.LoggerControl().get_logger('control_camera').info(
        'Initialized posixmq queue')

    last_captured = None
    try:
        while cap.isOpened():
            time.sleep(1 / 60)
            read_flag, frame = cap.read()
            if last_captured is None or (datetime.now() -
                                         last_captured).microseconds > 500000:
                if not read_flag:
                    util.LoggerControl().get_logger('control_camera').error(
                        'Error while new frame was reading')
                else:
                    name = datetime.now().strftime('%Y%m%d%H%M%S%f')
                    util.put(
                        queue,
                        util.Message('control_camera', 'New frame',
                                     cv2.resize(frame, (0, 0), fx=0.5, fy=0.5),
                                     'New frame has been read', name),
                        'camera_control')
                    try:
                        requests.post('http://127.0.0.1:5000/current-frame',
                                      data={'frame': name})
                    except:
                        pass
                    last_captured = datetime.now()
    except:
        util.LoggerControl().get_logger('control_camera').error(
            'Un handler error', exc_info=True)
    finally:
        cap.release()
        util.LoggerControl().get_logger('control_camera').info(
            'Capture release')
Exemple #5
0
 def run(self):
     logging.info('run begin...')
     q = posixmq.Queue('/ipcmsg')
     itchat.load_login_status(fileDir='/opt/crontab/IpcToItchat/itchat.pkl')
     while True:
         rcvMsg = q.get()
         logging.debug('Get msg: {}'.format(rcvMsg))
         itchat.send(rcvMsg[1], 'filehelper')
         if int(rcvMsg[0]) == 1:  # beatheart
             itchat.send(rcvMsg[1], 'filehelper')
         if int(rcvMsg[0]) == 2:  # spider
             for room in itchat.get_chatrooms():
                 nickName = room['NickName']
                 if room['NickName'] == "liuyi":
                     author = itchat.search_chatrooms(
                         userName=room['UserName'])
                     author.send(rcvMsg[1])
                     logging.debug('Send msg: {}'.format(rcvMsg[1]))
     logging.info('run exit')
Exemple #6
0
def create_app(config_name="dev"):
    app = Flask(__name__)
    config_model = config[config_name]
    config_model.init_config()
    app.config.from_object(config[config_name])
    setattr(app, "handlers", setup())
    setattr(app, "token_client", {})
    setattr(app, "mac_token", {})
    setattr(app, "token_status", {})
    setattr(app, "order_lock", threading.Lock())
    setattr(app, "db", db)
    register_extensions(app)
    register_blueprints(app)
    register_request_hook(app)
    # register_async_thread(app)
    # register_errors(app)

    # create a posix ipc queue
    thrift_queue = posixmq.Queue('/thrift_msq')
    setattr(app, "thrift_msq", thrift_queue)
    # thrift server process
    timer_start = threading.Timer(2, start_thrift_server, [app])
    timer_start.start()
    return app
from ipcqueue import posixmq

# create msg queue
#q = posixmq.Queue('/ipcmsg')

# recv message block and no timeout
#rcvMsg = q.get()
# send wechat
#itchat.send(rcvMsg[1], 'filehelper')

# send message
q = posixmq.Queue('/ipcmsg')
q.put([1, "Hi, I'm still here"])
q.close()
Exemple #8
0
def get_led_msg_queue():
    return posixmq.Queue(led_msg_queue_path)
Exemple #9
0
    sio.emit("freq_change", data=data, skip_sid=sid)


def try_rm(path):
    try:
        os.remove(path)
    except OSError:
        ...


if __name__ == "__main__":
    try_rm("/tmp/log-capture")
    try_rm("/tmp/log-filter")
    try_rm("/tmp/log-playback")
    mq_settings = posixmq.Queue("/settings",
                                maxsize=10,
                                maxmsgsize=8,
                                serializer=RawSerializer)
    proc_capture = subprocess.Popen(["build/capture"],
                                    stdout=sys.stdout,
                                    stderr=sys.stderr)
    proc_filter = subprocess.Popen(["build/filter"],
                                   stdout=sys.stdout,
                                   stderr=sys.stderr)
    proc_playback = subprocess.Popen(["build/playback"],
                                     stdout=sys.stdout,
                                     stderr=sys.stderr)

    time.sleep(1)

    if proc_capture.poll() is None and proc_filter.poll(
    ) is None and proc_playback.poll() is None:
Exemple #10
0
class StockindexSpider(scrapy.Spider):
    name = 'stockIndex'
    indexCodeList = ['000001.SH', '000016.SH', '000300.SH', '000905.SH', '399001.SZ', '399006.SZ']
    start_urls = ['http://quote.eastmoney.com/zs' + code[0:6] + '.html' for code in indexCodeList]
    urlCodeDict = dict(zip(start_urls, indexCodeList))
    # connect to system msg queue
    q = posixmq.Queue('/ipcmsg')
    logger.debug(' 11111111 uurlCodeDict= {}'.format(urlCodeDict))

    def start_requests(self):
        for url in self.start_urls:
            logger.info('request url = {}'.format(url))
            #yield SplashRequest(url, callback=self.parse_test, args={'images':0, 'timeout':10})
            symbol = int(self.urlCodeDict[url][0:6])
            yield scrapy.Request(url=url, callback=self.parse, dont_filter=True, meta={
                'symbol': symbol,
                'oriUrl': url,
                'splash': {
                    'args': {
                        # set rendering arguments here
                        'html': 1,
                        'lua_source': lua_script
                    },
                    'cache_args': ['lua_source'],
                    'endpoint': 'execute',
                }
            })
            logger.info(' 11111111 url = {}'.format(url))

    def parse(self, response):
        item = DatacrawlsystemItem()
        item['date'] = response.xpath('//*[@id="hqday"]/text()').re_first('\d+\-\d+\-\d+')
        dateTime = response.xpath('//*[@id="hqday"]/text()').extract_first()
        indexName = response.xpath('//*[@id="name"]/text()').extract_first()
        item['symbol'] = response.meta["symbol"]
        item['open'] = response.xpath('//*[@id="rgt2"]/text()').extract_first()
        item['high'] = response.xpath('//*[@id="rgt3"]/text()').extract_first()
        item['low']  = response.xpath('//*[@id="rgt4"]/text()').extract_first()
        item['close'] = response.xpath('//*[@id="rgt1"]/text()').extract_first()
        item['change'] = response.xpath('//*[@id="rgt5"]/text()').re_first('\-?\d*\.?\d+')
        volume = response.xpath('//*[@id="rgt7"]/text()').re_first('\d+')
        volumeOrig = response.xpath('//*[@id="rgt7"]/text()').extract_first()
        logger.debug('volume = {}, volumeOrig = {}'.format(volume, volumeOrig))
        item['volume'] = int(volume) * 10000 * 100
        amount = response.xpath('//*[@id="rgt8"]/text()').re_first('\d+')
        amountOrig = response.xpath('//*[@id="rgt8"]/text()').extract_first()
        logger.debug('amount = {}, amountOrig = {}'.format(amount, amountOrig))
        item['amount'] = int(amount) * 100000000
        item['turnoverrate'] = response.xpath('//*[@id="rgt9"]/text()').re_first('\-?\d*\.?\d+')
        item['change_5'] = response.xpath('//*[@id="rgt17"]/text()').re_first('\-?\d*\.?\d+')
        item['change_20'] = response.xpath('//*[@id="rgt18"]/text()').re_first('\-?\d*\.?\d+')
        item['change_60'] = response.xpath('//*[@id="rgt19"]/text()').re_first('\-?\d*\.?\d+')
        item['change_year'] = response.xpath('//*[@id="rgt20"]/text()').re_first('\-?\d*\.?\d+')

        # check data nonetype 
        for element in item.keys():
            if item[element] is None:
                logger.error('Item: {} is None, request again.'.format(element))
                logger.info('item: {}'.format(item))
        # send wechat message
        sendMsg = indexName + ", " + dateTime + '\n'
        for element in item.keys():
            if element == 'volume':
                sendMsg = sendMsg + element + ": " + volumeOrig + " , " 
            elif element == 'amount':
                sendMsg = sendMsg + element + ": " + amountOrig + " , " 
            else:
                sendMsg = sendMsg + element + ": " + str(item[element]) + " , " 
        logger.info('sendMsg: {}'.format(sendMsg))
        self.q.put([2, sendMsg])
        #if (float(item['change']) < -2) or (float(item['change_5']) < -8) or (float(item['change_20']) < -15):
        #    self.q.put([2, sendMsg])
        time.sleep(8)
        return item