Ejemplo n.º 1
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])
Ejemplo n.º 2
0
def check(ip, port):
    ssdb = SSDB(ip, port)
    try:
        ssdb.request('set', ['zabbix', '123'])
        ssdb.request('get', ['zabbix'])
        return 1
    except:
        return 0
Ejemplo n.º 3
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)
Ejemplo n.º 4
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
Ejemplo n.º 5
0
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
Ejemplo n.º 6
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'
Ejemplo n.º 7
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
Ejemplo n.º 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
Ejemplo n.º 9
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'
Ejemplo n.º 10
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
Ejemplo n.º 11
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'
Ejemplo n.º 12
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
Ejemplo n.º 13
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
Ejemplo n.º 14
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)
Ejemplo n.º 15
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
Ejemplo n.º 16
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)
Ejemplo n.º 17
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
Ejemplo n.º 18
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
Ejemplo n.º 19
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])

    """......此处省略一万个方法"""
Ejemplo n.º 20
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
Ejemplo n.º 21
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
Ejemplo n.º 22
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
Ejemplo n.º 23
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'
Ejemplo n.º 24
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'
Ejemplo n.º 25
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
Ejemplo n.º 26
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'
Ejemplo n.º 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'
Ejemplo n.º 28
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'
Ejemplo n.º 29
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'
Ejemplo n.º 30
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'
Ejemplo n.º 31
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')
Ejemplo n.º 32
0
				pass
				flushdb.flushdb(link, args[0])
			sys.stderr.write('(%.3f sec)\n'%(timespan(stime)))
			continue
	except Exception , e:
		pass
		sys.stderr.write((("error! - " + str(e)) + "\n"))
		continue
	retry = 0
	max_retry = 5
	stime = datetime.datetime.now()

	while True:
		pass
		stime = datetime.datetime.now()
		resp = link.request(cmd, args)

		if resp.code=='disconnected':
			pass
			link.close()
			time.sleep(retry)
			retry += 1

			if retry>max_retry:
				pass
				sys.stderr.write('cannot connect to server, give up...\n')
				break
			sys.stderr.write('[%d/%d] reconnecting to server... '%(retry, max_retry))
			try:
				pass
				link = SSDB(host, port)
Ejemplo n.º 33
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")
Ejemplo n.º 34
0
Archivo: demo.py Proyecto: gabrii/ssdb
# 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]))
countdict = {}
for filepath in filelist:
    if os.path.isfile(filepath):
        logger.info("read file : %s" % filepath)
        with open(filepath) as fr:
            while 1:
                lineT = fr.readline()
                if lineT == "": break
                line = lineT.strip()
                datas_impurities = line.split("\t")
                if len(datas_impurities) > 1:
                    platform = datas_impurities[0]
                    apk = datas_impurities[1].split(" ")[0]
                    if not (apk.replace(".", "").isalnum()): continue
                    if len(apk.split(".")[-1]) > 20: continue
                    info_ismember = ssdb_save.request('hexists',
                                                      [platform, apk])
                    #crawed_ismember =  ssdb_wait.request('zexists', [platform, apk])
                    logger.debug("\t".join([
                        platform,
                        apk,
                        "have_info:%s,%s" %
                        (info_ismember, info_ismember.data),
                    ]))
                    #if crawed_ismember.data == 0  and info_ismember.data == 0:
                    if info_ismember.data == 0:
                        logger.debug("save:%s,%s" % (platform, apk))
                        status = ssdb_wait.request("qpush_back",
                                                   [platform + "-1", apk])
                        logger.debug("save info:%s" % str(status))
                        countdict.setdefault(platform, 0)
                        countdict[platform] += 1
Ejemplo n.º 36
0
def get_stats(ip, port):
    ssdb = SSDB(ip, port)
    info = ssdb.request('info', ['cmd'])
    result = info.data[1:]
    return result
Ejemplo n.º 37
0
countdict = {}
for filepath in filelist:
    if os.path.isfile(filepath):
        logger.info("read file : %s" % filepath)
        with open(filepath) as fr:
            while 1:
                lineT = fr.readline()
                if lineT == "": break
                line = lineT.strip()
                datas_impurities = line.split("\t")
                if len(datas_impurities) > 1:
                    platform = datas_impurities[0]
                    apk = datas_impurities[1].split(" ")[0]
                    if not (apk.replace(".", "").isalnum()): continue
                    if len(apk.split(".")[-1]) > 20: continue
                    info_ismember = ssdb_save.request('hexists',
                                                      [platform, apk])
                    crawed_ismember = ssdb_wait.request(
                        'zexists', [platform, apk])
                    logger.debug("\t".join([
                        platform,
                        apk,
                        "have_info:%s,%s" %
                        (info_ismember, crawed_ismember.data),
                        "exists:%s,%s" % (crawed_ismember, info_ismember.data),
                    ]))
                    if crawed_ismember.data == 0 and info_ismember.data == 0:
                        logger.info("save:%s,%s" % (platform, apk))
                        status = ssdb_wait.request("zset",
                                                   [platform + "-1", apk, 1])
                        logger.debug("save info:%s" % str(status))
                        countdict.setdefault(platform, 0)
Ejemplo n.º 38
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'])
Ejemplo n.º 39
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])