def main(*args, **kwargs): bot = Spider() opts = {'database': kwargs['database']} bot.setup_cache(backend='mongo', **opts) ts = int(time.time()) count = 0 for item in bot.cache.db.cache.find({'timestamp': {'$exists': False}}, timeout=False): bot.cache.db.cache.update({'_id': item['_id']}, {'$set': {'timestamp': ts}}) count += 1 print('Records updated: %d' % count)
def main(*args, **kwargs): bot = Spider() opts = {'database': kwargs['database']} bot.setup_cache(backend='mongo', **opts) ts = int(time.time()) count = 0 for item in bot.cache.db.cache.find({'timestamp': { '$exists': False }}, timeout=False): bot.cache.db.cache.update({'_id': item['_id']}, {'$set': { 'timestamp': ts }}) count += 1 print('Records updated: %d' % count)
def main(*args, **kwargs): bot = Spider() opts = {'database': kwargs['database']} if kwargs.get('user'): opts['user'] = kwargs['user'] if kwargs.get('passwd'): opts['passwd'] = kwargs['passwd'] bot.setup_cache(backend='mysql', **opts) cursor = bot.cache.conn.cursor() cursor.execute('SELECT * FROM cache LIMIT 1') cols = [x[0] for x in cursor.description] ts = int(time.time()) if not 'timestamp' in cols: print 'Cache table does not have timestamp column. Adding it...' cursor.execute(''' ALTER TABLE cache ADD COLUMN timestamp INT NOT NULL DEFAULT %s''' % ts)
def main(*args, **kwargs): bot = Spider() opts = {'database': kwargs['database']} if kwargs.get('user'): opts['user'] = kwargs['user'] if kwargs.get('passwd'): opts['passwd'] = kwargs['passwd'] bot.setup_cache(backend='mysql', **opts) cursor = bot.cache.conn.cursor() cursor.execute('SELECT * FROM cache LIMIT 1') cols = [x[0] for x in cursor.description] ts = int(time.time()) if not 'timestamp' in cols: print('Cache table does not have timestamp column. Adding it...') cursor.execute(''' ALTER TABLE cache ADD COLUMN timestamp INT NOT NULL DEFAULT %s''' % ts)
def main(*args, **kwargs): bot = Spider() opts = {"database": kwargs["database"]} if kwargs.get("user"): opts["user"] = kwargs["user"] if kwargs.get("passwd"): opts["passwd"] = kwargs["passwd"] bot.setup_cache(backend="mysql", **opts) cursor = bot.cache.conn.cursor() cursor.execute("SELECT * FROM cache LIMIT 1") cols = [x[0] for x in cursor.description] ts = int(time.time()) if not "timestamp" in cols: print("Cache table does not have timestamp column. Adding it...") cursor.execute( """ ALTER TABLE cache ADD COLUMN timestamp INT NOT NULL DEFAULT %s""" % ts )