示例#1
0
def bookmark_total_job(now=None):
    try:
        conn = MySQLdb.connect(**c.db_config)
        cursor = conn.cursor()
        
        # 今天
        if not now:
            now = datetime.datetime.now()
        now_str = now.strftime('%Y-%m-%d %H:%M:%S')
        
        remove_guide = " url not regexp '^http://kan.sohu.com/help/guide-' "
        sum = 0
        for i in range(64):
            sql = "select user_id, count(*) from bookmark_bookmark_%s where %s and \
            (gmt_create is null or gmt_create <= '%s') group by user_id" % (i, remove_guide, now_str)
            cursor.execute (sql)
            results = cursor.fetchall()
            for d in results:
                user_id = int(d[0])
                count = int(d[1])
                # 去掉测试用户添加的文章
                if not _is_test(user_id):
                    sum += count
        now = datetime.datetime.now()
        data = SomeTotal(name='bookmark', time=now, count=sum)
        data.save()
        return sum
    except Exception, e:
        c.logger.error(e)
        return str(e)
示例#2
0
def user_total_job(now=None):
    try:
        # TODO: there should be a dbhelper
        conn = MySQLdb.connect(**c.db_config)
        cursor = conn.cursor()

        #去掉测试用户的id
        tmp = ' where id !='
        tmp += ' and id !='.join(map(lambda x:str(x), c.test_id))
        
        # 今天
        if not now:
            now = datetime.datetime.now()
        now_str = now.strftime('%Y-%m-%d %H:%M:%S')
        
        sql = "select count(*) from account_user %s and (gmt_create is null or gmt_create <='%s')" % (tmp, now_str)
        print sql
        cursor.execute(sql)
        result = cursor.fetchone()
        
        data = SomeTotal(name='user', time=now, count=result[0])
        data.save()
        return result[0]
    except Exception, e:
        c.logger.error(e)
        return str(e)
示例#3
0
def fiction_total_job(now=None):
    try:
        conn = MySQLdb.connect(**c.db_config)
        cursor = conn.cursor()
        
        # 今天
        if not now:
            now = datetime.datetime.now()
        now_str = now.strftime('%Y-%m-%d %H:%M:%S')
        
        sum = 0
        sql = "select user_id, count(*) from user_fiction_r where \
            (gmt_create is null or gmt_create <= '%s') group by user_id" % (now_str)
        cursor.execute (sql)
        results = cursor.fetchall()
        for d in results:
            user_id = int(d[0])
            count = int(d[1])
            # 去掉测试用户添加的文章
            if not _is_test(user_id):
                sum += count
        data = SomeTotal(name='fiction', time=now, count=sum + 4)
        data.save()
        return sum
    except Exception, e:
        c.logger.error(e)
        return str(e)
示例#4
0
def set_public_total_job(now=None):
    try:
        # TODO: there should be a dbhelper
        conn = MySQLdb.connect(**c.db_self_config)
        cursor = conn.cursor()

        # 今天
        if not now:
            now = datetime.datetime.now()
        now_str = now.strftime('%Y-%m-%d %H:%M:%S')
        
        sql = "select count(*) from stats_oper s, stats_operobject o, stats_opertype t where s.oper_type_id=t.id and s.id=o.oper_id and (t.id=64 or t.id=65 or t.id=67)"
        cursor.execute(sql)
        result = cursor.fetchone()
        
        data = SomeTotal(name='set-public', time=now, count=result[0] + 1061)
        data.save()
        return result[0]
    except Exception, e:
        c.logger.error(e)
        return str(e)
示例#5
0
def shorturl_total_job(now=None):
    try:
        # TODO: there should be a dbhelper
        conn = MySQLdb.connect(**c.db_self_config)
        cursor = conn.cursor()

        # 今天
        if not now:
            now = datetime.datetime.now()
        now_str = now.strftime('%Y-%m-%d %H:%M:%S')
        
        sql = "select count(*) from stats_oper o, stats_opertype t where o.oper_type_id = t.id and t.path = '/j/'"
        print sql
        cursor.execute(sql)
        result = cursor.fetchone()
        
        data = SomeTotal(name='shorturl', time=now, count=(result[0] + 943))
        data.save()
        return result[0]
    except Exception, e:
        c.logger.error(e)
        return str(e)