Esempio n. 1
0
 def calc_count():
     WordCount.logger.info("start to count words")
     ip = Config.getProperty('mongo', 'addr')
     port = int(Config.getProperty('mongo', 'port'))
     client = pymongo.MongoClient(ip, port)
     db = client.spiderDB
     collection = db.spider
     collection.map_reduce(WordCount.mapper, WordCount.reducer, out="result", full_response=True)
Esempio n. 2
0
class MemcacheUtil:
    url = Config.getProperty("memcached", "addr")

    @staticmethod
    def get(key):
        mc = memcache.Client([MemcacheUtil.url])
        return mc.get(key)

    @staticmethod
    def add(key, value):
        mc = memcache.Client([MemcacheUtil.url])
        return mc.add(key, value)

    @staticmethod
    def set(key, value):
        mc = memcache.Client([MemcacheUtil.url])
        return mc.set(key, value)

    @staticmethod
    def delete(key):
        try:
            mc = memcache.Client([MemcacheUtil.url])
            mc.delete(key)
        except Exception as e:
            print e

    @staticmethod
    def clean():
        mc = memcache.Client([MemcacheUtil.url])
        return mc.flush_all()
Esempio n. 3
0
 def getlogger(name):
     logger = logging.getLogger(name)
     logger.setLevel(LogFactory.__get_logger_level(Config.getProperty("logger", "level")))
     return logger
Esempio n. 4
0
 def getlogger(name):
     logger = logging.getLogger(name)
     logger.setLevel(
         LogFactory.__get_logger_level(Config.getProperty(
             "logger", "level")))
     return logger
Esempio n. 5
0
 def __get_data_statics_collection(client):
     db = client.get_database(Config.getProperty('mongo','resultdb'))
     cl = db.get_collection(Config.getProperty('mongo','statisticCollection'))
     return cl
Esempio n. 6
0
 def __get_client():
     ip = Config.getProperty('mongo', 'addr')
     port = int(Config.getProperty('mongo', 'port'))
     client = pymongo.MongoClient(ip, port)
     return client
Esempio n. 7
0
 def __get_data_statics_collection(client):
     db = client.get_database(Config.getProperty('mongo', 'resultdb'))
     cl = db.get_collection(
         Config.getProperty('mongo', 'statisticCollection'))
     return cl
Esempio n. 8
0
 def __get_client():
     ip = Config.getProperty('mongo', 'addr')
     port = int(Config.getProperty('mongo', 'port'))
     client = pymongo.MongoClient(ip, port)
     return client