Exemple #1
0
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
Exemple #2
0
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
Exemple #3
0
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'
Exemple #4
0
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
Exemple #5
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])
Exemple #6
0
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'
Exemple #7
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'
Exemple #8
0
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
Exemple #9
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)
    except Exception, e:
        pass
        print e
        sys.exit(0)
def save_weibo_tree(mid, whole_g, whole_stats, sub_g, sub_stats):
    try:
        ssdb = SSDB(SSDB_HOST, SSDB_PORT)
        result = ssdb.request('set', ['weibo_%s' % str(mid),whole_g + '_\/' + json.dumps(whole_stats) + '_\/' + sub_g + '_\/' + json.dumps(sub_stats)])
        if result.code == 'ok':
            print time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())), 'weibo %s save into SSDB' % str(mid), result.code
        else:
            print time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())), 'weibo %s save into SSDB failed' % str(mid)
    except Exception, e:
        print time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())), 'SSDB ERROR : %s ' % str(e)
Exemple #11
0
def save_weibo_tree(_id, whole_g):
    try:
        ssdb = SSDB(SSDB_HOST, SSDB_PORT)
        result = ssdb.request('set', ['topic_%s' % str(_id),whole_g])
        if result.code == 'ok':
            print time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())), ' topic %s save into SSDB' % str(_id), result.code
        else:
            print time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())), ' topic %s save into SSDB failed' % str(_id)
    except Exception, e:
        print time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())), 'SSDB ERROR : %s ' % str(e)
Exemple #12
0
def get_weibo_tree(_id):
    try:
        ssdb = SSDB(SSDB_HOST, SSDB_PORT)
        result = ssdb.request('get', ['topic_%s' % str(_id)])
        if result.code == 'ok' and result.data:
            return result.data
        return None
    except Exception, e:
        print e
        return None
Exemple #13
0
def graph_from_elevator(mid):
    try:
        ssdb = SSDB(SSDB_HOST, SSDB_PORT)
        result = ssdb.request('get', ['weibo_%s' % str(mid)])
        if result.code == 'ok' and result.data:
            return result.data
        return None
    except Exception, e:
        print e
        return None
Exemple #14
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 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
Exemple #16
0
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
Exemple #17
0
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
class symbol_dao(singleton):
    def __init__(self):
        try:
            self.ssdb = SSDB(SSDB_SERVER, SSDB_PORT)
        except:
            self.ssdb = None

    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 insert(self, _id, symbol):
        json = JSON.dumps(symbol)
        logging.debug("insert|%r", json)
        self.request('set', [_id, json])

    def delete(self, _id):
        logging.debug("delete|%r", _id)
        self.request('del', [_id])

    def find(self, _id):
        resp = self.request('get', [_id])
        logging.debug("select|%r|%r", _id, resp)
        if resp and resp.data:
            return JSON.loads(resp.data)
        else:
            return None
Exemple #19
0
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)
Exemple #20
0
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
Exemple #21
0
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
Exemple #22
0
class ssdb_connect():
    def __init__(self):
        self.ssdb = SSDB(host=ssdb_host, port=ssdb_port)

    def ssdb_save_hashmap(self, ssdb_save_participle_result_hashmap, key,
                          value):
        status = self.ssdb.request(
            "hset", [ssdb_save_participle_result_hashmap, key, value])
        logging.debug("ssdb,hset,hashmap:%s,key:%s,status:%s" %
                      (ssdb_save_participle_result_hashmap, key, status))
        return status

    def ssdb_get_hashmap(self, ssdb_save_participle_result_hashmap, key):
        result = self.ssdb.request("hget",
                                   [ssdb_save_participle_result_hashmap, key])
        logging.debug("ssdb,hget,hashmap:%s,key:%s,value:%s" %
                      (ssdb_save_participle_result_hashmap, key, result))
        return result
Exemple #23
0
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'
Exemple #24
0
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'
Exemple #25
0
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'
Exemple #26
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'
Exemple #27
0
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'
Exemple #28
0
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'
Exemple #29
0
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'
Exemple #30
0
def check(ip, port):
    ssdb = SSDB(ip, port)
    try:
        ssdb.request('set', ['zabbix', '123'])
        ssdb.request('get', ['zabbix'])
        return 1
    except:
        return 0
Exemple #31
0
class MySSDB():
	_ssdb = None

	def __init__(self, host='127.0.0.1', port = 8888):
		self._ssdb = SSDB(host, port)

	def isHItemInDB(self, dbname, item):
		req = self._ssdb.request('hget', [dbname, item])
		return req.code == 'ok'

	def getHItem(self, dbname, item):
		req = self._ssdb.request('hget', [dbname, item] )
		if req.code == 'ok':
			return req.data
		else:
			return ''

	def getHValueByItem(self, dbname, item):
		req = self._ssdb.request('hget', [dbname, item] )
		if req.code == 'ok':
			return req.data
		else:
			return ''

	def getHSize(self, dbname):
		req = self._ssdb.request('hsize',[dbname])
		if req.code == 'ok':
			return req.data
		else:
			return 0

	def setHItem(self, dbname, item, value):
		try:
			req = self._ssdb.request('hset',[dbname, item, value])
		except Exception, e:
			print e
Exemple #32
0
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")))
Exemple #33
0
class SSDBHelper(object):
    def __init__(self):
        try:
            self.ssdb = SSDB('127.0.0.1', 8888)
        except Exception as e:
            print(e)
            sys.exit(0)

    def set(self, key, value):
        self.ssdb.request('set', [key, value])

    def get(self, key):
        self.ssdb.request('get', [key])

    def incr(self, key, incr_num):
        self.ssdb.request('incr', [key, incr_num])

    def decr(self, key, decr_num):
        self.ssdb.request('decr', [key, decr_num])

    def delete(self, key):
        self.ssdb.request('del', [key])

    """......此处省略一万个方法"""
Exemple #34
0
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)
Exemple #35
0
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
Exemple #36
0
class SsdbClient(object):
    """
    SSDB client
    """
    def __init__(self, host, port):
        self.__conn = SSDB(host, port)

    def put(self, tablename, key, value):
        self.__conn.request('hset', [tablename, key, value])

    def get(self, tablename, key):
        return self.__conn.request('hget', [tablename, key]).data

    def delete(self, tablename, key):
        return self.__conn.request('hdel', [tablename, ('%s' % key)])

    def getAll(self, tablename):
        return self.__conn.request('hgetall', [tablename]).data

    def deleteAll(self):
        return self.__conn.request('flushdb')
Exemple #37
0
			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 = ''
 def __init__(self):
     try:
         self.ssdb = SSDB(SSDB_SERVER, SSDB_PORT)
     except:
         self.ssdb = None
Exemple #39
0
	def __init__(self, host='127.0.0.1', port = 8888):
		self._ssdb = SSDB(host, port)
Exemple #40
0
                                        (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()
Exemple #41
0
# encoding=utf-8
# Generated by cpy
# 2013-01-26 21:04:47.984000
import os, sys
from sys import stdin, stdout

from SSDB import SSDB
try:
	pass
	ssdb = SSDB('127.0.0.1', 8888)
except Exception , e:
	pass
	print e
	sys.exit(0)
print ssdb.request('set', ['test', '123'])
print ssdb.request('get', ['test'])
print ssdb.request('incr', ['test', '1'])
print ssdb.request('decr', ['test', '1'])
print ssdb.request('scan', ['a', 'z', 10])
print ssdb.request('rscan', ['z', 'a', 10])
print ssdb.request('keys', ['a', 'z', 10])
print ssdb.request('del', ['test'])
print ssdb.request('get', ['test'])
print "\n"
print ssdb.request('zset', ['test', 'a', 20])
print ssdb.request('zget', ['test', 'a'])
print ssdb.request('zincr', ['test', 'a', 20])
print ssdb.request('zdecr', ['test', 'a', 20])
print ssdb.request('zscan', ['test', 'a', 0, 100, 10])
print ssdb.request('zrscan', ['test', 'a', 100, 0, 10])
print ssdb.request('zkeys', ['test', 'a', 0, 100, 10])
Exemple #42
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")
Exemple #43
0
# encoding=utf-8
# Generated by cpy
# 2013-01-26 21:04:47.984000
import os, sys
from sys import stdin, stdout

from SSDB import SSDB
try:
	pass
	ssdb = SSDB('127.0.0.1', 8888)
except Exception as e:
	pass
	print(e)
	sys.exit(0)
print( ssdb.request('set', ['test', '123']))
print( ssdb.request('get', ['test']))
print( ssdb.request('incr', ['test', '1']))
print( ssdb.request('decr', ['test', '1']))
print( ssdb.request('scan', ['a', 'z', 10]))
print( ssdb.request('rscan', ['z', 'a', 10]))
print( ssdb.request('keys', ['a', 'z', 10]))
print( ssdb.request('del', ['test']))
print( ssdb.request('get', ['test']))
print( "\n")
print( ssdb.request('zset', ['test', 'a', 20]))
print( ssdb.request('zget', ['test', 'a']))
print( ssdb.request('zincr', ['test', 'a', 20]))
print( ssdb.request('zdecr', ['test', 'a', 20]))
print( ssdb.request('zscan', ['test', 'a', 0, 100, 10]))
print( ssdb.request('zrscan', ['test', 'a', 100, 0, 10]))
print( ssdb.request('zkeys', ['test', 'a', 0, 100, 10]))
    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)
Exemple #45
0
import sys
import json
import heapq
import redis
import get_poi
import select_path
import time
sys.path.append('../script/common/')
sys.path.append('../script/google_transit/')
sys.setdefaultencoding('utf8')
from SSDB import SSDB
from toolLib import formatCoor
#score:烦躁度,客观指标结合主观喜恶而得,很明显,我们要寻找score最低最低最低的路线;烦躁度约等于交通时间
#r0 = redis.StrictRedis(host='localhost', port=6379, db=0)
#r1 = redis.StrictRedis(host='localhost', port=6379, db=1)
ssdb = SSDB('127.0.0.1', 8888)

PATHNUM = 10000
global_num = 0
prefers = {}
prefers["time"] = {}
prefers["time"]["walk_velo"] = 1.2  #正常人1.2m/s
prefers["time"]["transit_as_time"] = 3 * 60
prefers["time"]["trans_limit"] = 50
prefers["time"]["no"] = 2  #方便打印trans_type字段
prefers["best"] = {}
prefers["best"]["walk_velo"] = 1.2  #正常人1.2m/s
prefers["best"]["transit_as_time"] = 3 * 60
prefers["best"]["trans_limit"] = 50
prefers["best"]["no"] = 0
prefers["walk"] = {}
Exemple #46
0
 def __init__(self):
     self.ssdb = SSDB(ssdb_host, ssdb_save_port)
Exemple #47
0
# encoding=utf-8
# Generated by cpy
# 2012-12-18 00:21:56.078000
import os, sys
from sys import stdin, stdout

from SSDB import SSDB
try:
	pass
	ssdb = SSDB('127.0.0.1', 8888)
except Exception , e:
	pass
	print e
	sys.exit(0)
print ssdb.request('set', ['test', '123'])
print ssdb.request('get', ['test'])
print ssdb.request('incr', ['test', '1'])
print ssdb.request('decr', ['test', '1'])
print ssdb.request('scan', ['a', 'z', 10])
print ssdb.request('keys', ['a', 'z', 10])
print ssdb.request('del', ['test'])
print ssdb.request('get', ['test'])
print "\n"
print ssdb.request('zset', ['test', 'a', 20])
print ssdb.request('zget', ['test', 'a'])
print ssdb.request('zincr', ['test', 'a', 20])
print ssdb.request('zdecr', ['test', 'a', 20])
print ssdb.request('zscan', ['test', 'a', 0, 100, 10])
print ssdb.request('zkeys', ['test', 'a', 0, 100, 10])
print ssdb.request('zdel', ['test', 'a'])
print ssdb.request('zget', ['test', 'a'])
Exemple #48
0
class db():
    def __init__(self):
        self.ssdb = SSDB(ssdb_host, ssdb_save_port)

    def close(self):
        self.ssdb.close()