Ejemplo n.º 1
0
 def on_downloadItems(self, obj):
     logger.info('on_downloadItems')
     for item in obj.get('downloadItems'):
         if(item.get('savename') and item.get('url')):
             ret = HttpUtil.download(item)
             if ret and type(ret) == dict:
                 item.update(ret)
             else:
                 logger.error('downloadItem error!')
     self.emit('downloadItemsFinished', obj)
     logger.info('on_downloadItems finished')
Ejemplo n.º 2
0
    def uploadStream(content, obj):
        if not UpyunUtil.up:
            UpyunUtil.up = upyun.UpYun(UpyunUtil._spaceName, UpyunUtil._userName, UpyunUtil._userPasswd)

        savedir = os.path.join(UpyunUtil._rootDir, obj.get('savedir')) if obj.get('savedir') else UpyunUtil._rootDir
        savename = os.path.join(savedir, obj['savename'])
        try:
            res = UpyunUtil.up.put(savename, content)
        except Exception as e:
            logger.exception(e.message)
            # namespace.emit('downloadError', obj)
            return None
        else:
            logger.info(simplejson.dumps(res, indent=4, ensure_ascii=False))
            obj['saveurl'] = UpyunUtil._rootUrl+savename
            # namespace.emit('uploadUpyun', obj)
            return obj
Ejemplo n.º 3
0
    def download(self, data):
        def scheduler(itemCount, itemSize, fileSize):
            percent = 100.0 * itemCount * itemSize / fileSize
            if percent > 100:
                percent = 100
            logger.debug('percent: %.2f%%' % percent)

        savedir = os.path.expanduser(data.get('savedir')) or os.path.expanduser('~')
        if not os.path.exists(savedir):
            os.makedirs(savedir)

        savename = data.get('savename')
        if data.get('url') and savename:
            st = os.path.join(savedir, savename)
            logger.info('download, url: '+data['url']+'  saveat: '+st)
            urllib.urlretrieve(data['url'], st)
            if(os.path.exists(st)):
                return st

        return False
Ejemplo n.º 4
0
 def on_taskFinished(self):
     logger.info('taskFinished!');
Ejemplo n.º 5
0
 def on_writeJSON(self, obj):
     logger.info('on_writeJSON')
     writeFile(obj['savename'], obj.get('savedir'), obj['data'], 'w')
Ejemplo n.º 6
0
 def recv_disconnect(self):
     logger.info('client disconnect!');
     if(self._chrombot_log):
         self._chrombot_log.close()
         self._chrombot_log = None
Ejemplo n.º 7
0
 def recv_connect(self):
     logger.info('client connected!');
     self.emit('connected')
     self._chrombot_log_name = 'log/'+time.ctime()+'.log'
     self._chrombot_log = open(self._chrombot_log_name, 'w')
Ejemplo n.º 8
0
                if ret and type(ret) == dict:
                    item.update(ret)
                else:
                    logger.error('downloadItem error!')
        self.emit('downloadItemsFinished', obj)
        logger.info('on_downloadItems finished')

    def on_taskFinished(self):
        logger.info('taskFinished!');

@app.route('/')
def onindex():
    return 'Hello, this is SafeSiteSuper.'

@app.route('/socket.io/<path:rest>')
def socketio(rest):
    try:
        socketio_manage(request.environ, {'/super': SuperNamespace}, request)
    except:
        logger.error('socketio_manage failed!!!')

    return Response()

if __name__ == '__main__':
    try:
        SocketIOServer(('0.0.0.0', 5000), app, namespace="socket.io", policy_server=False).serve_forever()
    except KeyboardInterrupt:
        logger.info('### KeyboardInterrupt...')
        gMan.exit()
        
Ejemplo n.º 9
0
 def __afterDownload(self):
     logger.info('download finished!')
Ejemplo n.º 10
0
 def __beforeDownload(self):
     logger.info('download begin...')