def select_platform_and_get_apk(): try: pass ssdb_wait = SSDB(ssdb_host, ssdb_wait_port) ssdb_save = SSDB(ssdb_host, ssdb_save_port) except Exception, e: pass print e sys.exit(0)
def select_platform_and_get_apk(): try: pass ssdb_wait = SSDB(ssdb_host, ssdb_wait_port) ssdb_save = SSDB(ssdb_host, ssdb_save_port) logger.info("connect ssdb sucess !!!") except Exception, e: pass print e sys.exit(0)
def save_gexf_results(topic, identifyDate, identifyWindow, identifyGexf, gexf_type): '''保存gexf图数据到SSDB ''' #try: ssdb = SSDB(SSDB_HOST, SSDB_PORT) if ssdb: print 'ssdb yes' else: print 'ssdb no' if gexf_type == 1: key = _utf8_unicode(topic) + '_' + str(identifyDate) + '_' + str( identifyWindow) + '_' + 'source_graph' else: key = _utf8_unicode(topic) + '_' + str(identifyDate) + '_' + str( identifyWindow) + '_' + 'direct_superior_graph' print 'key', key.encode('utf-8') key = str(key) value = identifyGexf result = ssdb.request('set', [key, value]) if result.code == 'ok': print time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())), 'save Gexf success' else: print time.strftime('%Y-%m-%d %H:%M:%S', time.localtime( time.time())), 'Gexf save into SSDB failed'
def network_quota(): quota = request.args.get('quota', '') print 'quota:', quota topic = request.args.get('topic', '') start_ts = request.args.get('start_ts', '') start_ts = int(start_ts) end_ts = request.args.get('end_ts', '') end_ts = int(end_ts) date = ts2datetime(end_ts) windowsize = (end_ts - start_ts) / Day network_type = request.args.get('network_type', '') print 'network_type:', network_type key = _utf8_unicode(topic) + '_' + str(date) + '_' + str( windowsize) + '_' + quota + '_' + network_type try: ssdb = SSDB(SSDB_HOST, SSDB_PORT) value = ssdb.request('get', [key]) print 'value.code:', value.code if value.code == 'ok' and value.data: print 'ok' response = make_response(value.data) return response return None except Exception, e: print e return None
def network(): topic = request.args.get('topic', '') start_ts = request.args.get('start_ts', '') start_ts = int(start_ts) end_ts = request.args.get('end_ts', '') end_ts = int(end_ts) windowsize = (end_ts - start_ts) / Day windowsize = int(windowsize) end = ts2datetime(end_ts) network_type = request.args.get('network_type', '') module = 'identify' print 'topic, end_ts, windowsize, network_type:', topic.encode( 'utf-8'), end, windowsize, network_type topic_status = get_topic_status(topic, start_ts, end_ts, module) print 'graph_status:', topic_status if topic_status == COMPLETED_STATUS: query_key = _utf8_unicode(topic) + '_' + str(end) + '_' + str( windowsize) + '_' + network_type print 'key:', query_key.encode('utf-8') key = str(query_key) try: ssdb = SSDB(SSDB_HOST, SSDB_PORT) results = ssdb.request('get', [key]) print 'results.code:', results.code if results.code == 'ok' and results.data: print 'result_code ok' response = make_response(results.data) response.headers['Content-Type'] = 'text/xml' return response return None except Exception, e: print 'error', e return None
def process_deal(platform): #SSDB 链接 try: ssdb_save = [SSDB(ssdb_host, ssdb_save_port), ssdb_save_port] except Exception, e: logger.error(str(e), exc_info=True) sys.exit(0)
def getImages(self, model_id, album_id, image_count): # print 'start downloading album', album_id, image_count, '张' for page in xrange(1, int((int(image_count) - 1) / 16 + 2)): link = self.image_prefix.format(model_id, album_id, page) body = self.readHtml(link).decode('gbk') images = re.findall(self.image_pattern, body) # tried to use des as names, however, it duplicates times. So i chose pic ids. names = re.findall(self.image_name_pattern, body) for idx, image in enumerate(images): image = image.replace('290', '620') try: img_url = ('http://' + image).replace( 'jpg_620x10000.jpg', 'jpg') except Exception as e: img_url = ('http://' + image) print 'ssdb set dat error' try: ssdb = SSDB('127.0.0.1', 8888) except Exception, e: print e sys.exit(0) print ssdb.request( 'hset', ['imageurl', str(album_id) + str(idx), img_url])
def save_graph(topic, identifyDate, identifyWindow, graph, graph_type): ''' 保存make_network产生的没有增加attribute,以及未做cut和sampling的原始图结构 ''' ssdb = SSDB(SSDB_HOST, SSDB_PORT) if ssdb: print 'ssdb yes' else: print 'ssdb no' if graph_type == 'g': key = _utf8_unicode(topic) + '_' + str(identifyDate) + '_' + str( identifyWindow) + '_' + 'make_network_g' elif graph_type == 'ds_g': key = _utf8_unicode(topic) + '_' + str(identifyDate) + '_' + str( identifyWindow) + '_' + 'make_network_ds_g' elif graph_type == 'gg': key = _utf8_unicode(topic) + '_' + str(identifyDate) + '_' + str( identifyWindow) + '_' + 'make_network_gg' elif graph_type == 'ds_udg': key = _utf8_unicode(topic) + '_' + str(identifyDate) + '_' + str( identifyWindow) + '_' + 'make_network_ds_udg' print 'key:', key.encode('utf-8') key = str(key) value = graph result = ssdb.request('set', [key, value]) if result_code == 'ok': print time.strftime('%Y-%m-%d %H:%M:%S', time.localtime( time.time())), graph_type, 'save make_network_graph success' else: print time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time( ))), graph_type, ' save make_network_graph into SSDB failed'
def check(ip, port): ssdb = SSDB(ip, port) try: ssdb.request('set', ['zabbix', '123']) ssdb.request('get', ['zabbix']) return 1 except: return 0
def request(self, cmd, params): try: resp = self.ssdb.request(cmd, params) assert (resp.ok()) return resp except: try: self.ssdb = SSDB(SSDB_SERVER, SSDB_PORT) except: self.ssdb = None return None
def SSDB_test(): conn = SSDB(HOST, PORT) start_time = time() map(lambda x: conn.request('hset',['cssdbpy',str(i), 1]), [i for i in xrange(10000,90000)]) print 'hset', FIELDS/(time()-start_time) start_time = time() conn.request('hscan',['cssdbpy','','', -1]) print 'hscan', FIELDS/(time()-start_time) for action in ['hget', 'hdel']: start_time = time() map(lambda x: conn.request(action,['cssdbpy',str(i)]), [i for i in xrange(10000,90000)]) print action, FIELDS/(time()-start_time)
def SSDB_test(): conn = SSDB('127.0.0.1', 8888) start_time = time() map(lambda x: conn.request('hset', ['cssdbpy', str(i), 1]), [i for i in xrange(10000, 90000)]) print 'hset', time() - start_time start_time = time() conn.request('hscan', ['cssdbpy', '', '', -1]) print 'hscan', time() - start_time for action in ['hget', 'hdel']: start_time = time() map(lambda x: conn.request(action, ['cssdbpy', str(i)]), [i for i in xrange(10000, 90000)]) print action, time() - start_time
def init(): timestamp=datetime.datetime.now().strftime("%Y%m%d%H") g_conf.read("../conf/charge_python.conf") logging.basicConfig(level=logging.INFO, format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s', datefmt='[%Y-%m_%d %H:%M:%S]', filename='../charge_log/charge_python.'+timestamp+'.log', filemode='a') global g_idea_dict g_idea_dict={} load_idea_info(g_conf.get("file","idea_operate"),g_conf.get("file","idea")) global g_decryter g_decryter=ctypes.CDLL("./libdecrypter.so") global g_ssdb_obj g_ssdb_obj = SSDB(g_conf.get("ssdb","ip"),int(g_conf.get("ssdb","freq_control_port")))
def read_attribute_dict(graph_type): ''' 读取临时保存的attribute_dict ''' if graph_type: key = graph_type + '_attribute_dict' try: ssdb = SSDB(SSDB_HOST, SSDB_PORT) value = ssdb.request('get', [key]) if value.code == 'ok' and value.data: response = value.data # 这里的读取数据应该是怎样的?!!!!但是views文件中的make_response是几个意思?!! return response return None except Exception, e: print e return None
def read_graph(topic, identifyDate, identifyWindow, graph_type): ''' 读取make_network产生的原始图结构 ''' if graph_type: key = _utf8_unicode(topic) +'_' + str(identifyDate) + '_' + str(identifyWindow) + '_' + 'make_network_' + graph_type else: return None try: ssdb = SSDB(SSDB_HOST, SSDB_PORT) value = ssdb.request('get', [key]) if value.code == 'ok' and value.data: response = value.data # ???!!这里还需要进行确定 return response return None except Exception, e: print e return None
def save_quota(key, value): #print 'key, value:', key.encode('utf-8'), value try: ssdb = SSDB(SSDB_HOST, SSDB_PORT) if ssdb: print 'ssdb yes' else: print 'ssdb no' result = ssdb.request('set', [key, value]) if result.code == 'ok': print '6666666' print time.strftime('%Y-%m-%d %H:%M:%S', time.localtime( time.time())), 'save success', key.encode('utf-8'), value else: print '777777' print time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())), 'save failed' except Exception, e: print '******' print time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())), 'SSDB ERROR'
def save_gexf_results(topic, identifyDate, identifyWindow, identifyGexf): '''保存gexf图数据到SSDB ''' #try: ssdb = SSDB(SSDB_HOST, SSDB_PORT) if ssdb: print 'ssdb yes' else: print 'ssdb no' key = _utf8_unicode(topic) + '_' + str(identifyDate) + '_' + str( identifyWindow) print 'key', key key = str(key) value = identifyGexf result = ssdb.request('set', [key, value]) if result.code == 'ok': print time.strftime('%Y-%m-%d %H:%M:%S', time.localtime( time.time())), 'save success', _utf8_unicode(topic), str( identifyDate), str(identifyWindow) else: print time.strftime('%Y-%m-%d %H:%M:%S', time.localtime( time.time())), 'Gexf save into SSDB failed'
def save_attribute_dict(attribute_dict, graph_type): ''' 临时保存attribute_dict,所以不进行topic的唯一指定,使其每一次存储都会覆盖上一次的。 ''' ssdb = SSDB(SSDB_HOST, SSDB_PORT) if ssdb: print 'ssdb yes' else: print 'ssdb no' if graph_type == 'g': key = 'g_attribute_dict' elif graph_type == 'ds_g': key = 'ds_g_attribute_dict' print 'key:', key.encode('utf-8') value = json.dumps(attribute_dict) result = ssdb.request('set', [key, value]) if result.code == 'ok': print time.strftime('%Y-%m-%d %H:%M:%S', time.localtime( time.time())), key.encode('utf-8'), 'save success' else: print time.strftime('%Y-%m-%d %H:%M:%S', time.localtime( time.time())), key.encode('utf-8'), 'save failed'
from config.config import * import logging logger = logging.getLogger("census") import traceback import json import datetime nowtime = datetime.datetime.strptime( datetime.datetime.now().strftime("%Y-%m-%d") + " 00:00:00", "%Y-%m-%d %H:%M:%S") print nowtime from SSDB import SSDB try: pass ssdb_wait = [SSDB(ssdb_host, ssdb_wait_port), ssdb_wait_port] ssdb_save = [SSDB(ssdb_host, ssdb_save_port), ssdb_save_port] except Exception, e: pass print e sys.exit(0) for ssdb_bind in [ssdb_wait, ssdb_save]: list_keys = ssdb_bind[0].request("qlist", ["", "", -1]).data for list_key in list_keys: list_key_size = ssdb_bind[0].request("qsize", [list_key]).data logger.info("port:%s,list_key:%s,size:%s" % (ssdb_bind[1], list_key, str(list_key_size))) set_keys = ssdb_bind[0].request("zlist", ["", "", 100]).data for set_key in set_keys: set_key_size = ssdb_bind[0].request("zsize", [set_key]).data
def __init__(self): try: self.ssdb = SSDB(SSDB_SERVER, SSDB_PORT) except: self.ssdb = None
def __init__(self): try: self.ssdb = SSDB('127.0.0.1', 8888) except Exception as e: print(e) sys.exit(0)
import os import linecache import time from SSDB import SSDB import json ssdb = SSDB('127.0.0.1', 8888) print("start") start = time.perf_counter() cache_data = linecache.getlines("/usr/local/access.log") for line in range(len(cache_data)): ssdb.request('set', str(line).encode(), '0'.encode()) end = time.perf_counter() print("read: %f s" % (end - start)) print("ok")
logger.setLevel(logging.INFO) return logger logger = init_logger('test', 'log.txt') """ try: # 业务代码 except Exception as e: logger.error(str(e), exc_info=True) """ from SSDB import SSDB try: pass ssdb_wait = SSDB(ssdb_host, ssdb_wait_port) ssdb_save = SSDB(ssdb_host, ssdb_save_port) except Exception, e: pass print e sys.exit(0) folderpath = sys.argv[1] logger.info("folder:%s" % folderpath) #if os.path.exists(folderpath) == False:os._exit() if os.path.isfile(folderpath): filelist = [folderpath] else: filelist = [ os.path.join(folderpath, filename) for filename in os.listdir(folderpath)
def __init__(self, host, port): self.__conn = SSDB(host, port)
(apk, appinfo_string)) else: logger.debug("platform:%s,app:%s,do not need update" % (platform, app)) break break try: ssdb_save[0].close() except Exception as e: logger.error(str(e), exc_info=True) pool = multiprocessing.Pool(multiprocessing.cpu_count()) try: ssdb_save = [SSDB(ssdb_host, ssdb_save_port), ssdb_save_port] except Exception, e: logger.error(str(e), exc_info=True) sys.exit(0) for platform in ssdb_save[0].request("hlist", ["", "", -1]).data: pool.apply_async(process_deal, (platform, )) #pool.map(process_deal,ssdb_save[0].request("hlist",["","",-1]).data) try: ssdb_save[0].close() except Exception as e: logger.error(str(e), exc_info=True) pool.close() pool.join()
break try: pass port = int(port) except Exception , e: pass sys.stderr.write('Invalid argument port: '%(port)) usage() sys.exit(0) sys.path.append('./api/python') sys.path.append('../api/python') sys.path.append('/usr/local/ssdb/api/python') from SSDB import SSDB try: pass link = SSDB(host, port) except socket.error , e: pass sys.stderr.write('Failed to connect to: %s:%d\n'%(host, port)) sys.stderr.write('Connection error: %s\n'%(str(e))) sys.exit(0) welcome() if sys.stdin.isatty(): pass show_version() password = False while True: pass line = ''
logger.setLevel(logging.INFO) return logger logger = init_logger('mylogger', 'log.txt') logger.info("start...") """ try: # 业务代码 except Exception as e: logger.error(str(e), exc_info=True) """ from SSDB import SSDB try: pass ssdb = SSDB(ssdb_host, ssdb_save_port) except Exception, e: pass print e # sys.exit(0) #redis_connect_dict = {} #for info,dbint in redis_db.iteritems(): # pool = redis.ConnectionPool(host=redis_host,port=redis_port,db=dbint) # redis_t = redis.Redis(connection_pool=pool) # redis_connect_dict[info] = redis_t @app.route(r"/api/appinfo/v1/getInfo") def get(): #global redis_host
def __init__(self): self.ssdb = SSDB(ssdb_host, ssdb_save_port)
def __init__(self): self.ssdb = SSDB(host=ssdb_host, port=ssdb_port)
def get_stats(ip, port): ssdb = SSDB(ip, port) info = ssdb.request('info', ['cmd']) result = info.data[1:] return result