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')
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
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
def on_taskFinished(self): logger.info('taskFinished!');
def on_writeJSON(self, obj): logger.info('on_writeJSON') writeFile(obj['savename'], obj.get('savedir'), obj['data'], 'w')
def recv_disconnect(self): logger.info('client disconnect!'); if(self._chrombot_log): self._chrombot_log.close() self._chrombot_log = None
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')
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()
def __afterDownload(self): logger.info('download finished!')
def __beforeDownload(self): logger.info('download begin...')