Example #1
0
    def add(cls, user_id, origin_id, create_time, site, category, title, text=None, raw=None):
        status = None
        cursor = None
        try:
            cursor = db_conn.execute(
                """insert into status 
                    (user_id, origin_id, create_time, site, category, title)
                    values (%s,%s,%s,%s,%s,%s)""",
                (user_id, origin_id, create_time, site, category, title),
            )
            db_conn.commit()
            status_id = cursor.lastrowid
            if text is not None:
                mongo_conn.set(cls.STATUS_REDIS_KEY % status_id, json_encode(text))
            if raw is not None:
                mongo_conn.set(cls.RAW_STATUS_REDIS_KEY % status_id, raw)
            cls._clear_cache(user_id, None, cate=category)
            status = cls.get(status_id)
        except IntegrityError:
            # log.warning("add status duplicated, ignore...")
            db_conn.rollback()
        finally:
            cursor and cursor.close()

        return status
def move_user_profile():
    RAW_USER_REDIS_KEY = "/user/raw/%s" 

    cursor = db_conn.execute("select id from user order by id")
    rows = cursor.fetchall()
    cursor and cursor.close()
    for row in rows:
        print '--------user raw id:', row[0]
        sys.stdout.flush()
        r = redis_conn.get(RAW_USER_REDIS_KEY % row[0])
        if r:
            mongo_conn.set(RAW_USER_REDIS_KEY % row[0], r)
        r2 = redis_conn.get("/profile/%s" % row[0])
        if r2:
            mongo_conn.set("/profile/%s" % row[0], r2)
Example #3
0
def move_user_profile():
    RAW_USER_REDIS_KEY = "/user/raw/%s"

    cursor = db_conn.execute("select id from user order by id")
    rows = cursor.fetchall()
    cursor and cursor.close()
    for row in rows:
        print '--------user raw id:', row[0]
        sys.stdout.flush()
        r = redis_conn.get(RAW_USER_REDIS_KEY % row[0])
        if r:
            mongo_conn.set(RAW_USER_REDIS_KEY % row[0], r)
        r2 = redis_conn.get("/profile/%s" % row[0])
        if r2:
            mongo_conn.set("/profile/%s" % row[0], r2)
Example #4
0
 def add(cls, user_id, origin_id, create_time, site, category, title, 
         text=None, raw=None):
     status = None
     cursor = None
     try:
         cursor = db_conn.execute("""insert into status 
                 (user_id, origin_id, create_time, site, category, title)
                 values (%s,%s,%s,%s,%s,%s)""",
                 (user_id, origin_id, create_time, site, category, title))
         status_id = cursor.lastrowid
         try:
             if text is not None:
                 mongo_conn.set(cls.STATUS_REDIS_KEY %status_id, json_encode(text))
             if raw is not None:
                 mongo_conn.set(cls.RAW_STATUS_REDIS_KEY %status_id, raw)
         except Exception, e:
             log.warning('ERROR_MONGODB:%s' % e)
             db_conn.rollback()
         else:
Example #5
0
 def set_profile(self, profile):
     mongo_conn.set('/profile/%s' %self.id, json_encode(profile))
     return self.get_profile()
Example #6
0
 def set_profile(self, profile):
     mongo_conn.set("/profile/%s" % self.id, json_encode(profile))
     mc.delete("user_profile:%s" % self.id)
     return self.get_profile()