Ejemplo n.º 1
0
def main():
    beijing_time = time.gmtime(time.mktime(time.localtime())+28800)
    bejjing_date = time.strftime(ISOTIMEFORMAT, beijing_time)
    bejjing_monthday = time.strftime('%m-%d', beijing_time)
    out_str = ''
    sql = """
            SELECT ad.ac_date_year, ad.ac_date, COUNT(DISTINCT ac_author_id) as author,
            COUNT( * ) AS post, SUM( ac_article_view ) AS view, SUM( ac_article_comment) AS comment
            FROM ac_article AS aa
            INNER JOIN ac_date AS ad ON aa.ac_article_date = ad.ac_date
            WHERE ad.ac_date != %s AND ad.ac_date_monthday = %s
            GROUP BY ad.ac_date_year, ad.ac_date_month ORDER BY ad.ac_date DESC"""

    cursor.execute(sql, (bejjing_date, bejjing_monthday))
    results = cursor.fetchall()

    date_summary = []
    for row in results:
        date_summary.append(row)

    for stat in date_summary:
        out_str += '\t<div class="sidebar_section_subtitle">\n\t\t%s\n'%time.strftime('%Y年%m月%d日',time.strptime(str(stat[1]), ISOTIMEFORMAT))
        out_str += '\t</div>\n'
        out_str += '\t<div class="sidebar_section_today_content">\n\t\t'
        sql = "SELECT ac_article_link, ac_article_name, ac_author_name, ac_article_view FROM ac_article WHERE ac_article_date = '"+str(stat[1])+"' ORDER BY ac_article_view DESC LIMIT 3"
        cursor.execute(sql)
        results = cursor.fetchall()
        top = True
        for row in results:
            red = 'class="sidebar_section_today_item_top"'
            if top == True:
                top = False
            else:
                red = ''
            out_str += '\t\t<li class="sidebar_section_today_item">\n\t\t\t<a '+red+' href="http://www.acfun.tv/v/%s/" target="_blank">%s</a>\n\t\t</li>\n'%(row[0].encode('utf-8'), row[1].encode('utf-8'))

        out_str += '\t</div>\n'

    ac_core.cache("today", out_str, False)

    try:
        cursor.close()
        conn.close()
    except:
        pass
Ejemplo n.º 2
0
def main():
    date = 7
    title = u'本周热门'
    type = 'week'
    type_arr = {'week':7, 'month':30, 'year': 365, 'all': 3650}
    title_arr = {'week':u'本周热门', 'month':u'月度热门', 'year': u'年度热门', 'all': u'坟'}

    out_str = ''
    if(len(sys.argv) == 2):
        if sys.argv[1] in type_arr:
            date = type_arr[sys.argv[1]]
            title = title_arr[sys.argv[1]]
            type = sys.argv[1]

    out_str += "<div class='hot_header'></div>"

    sql = "SELECT ac_category_name, ac_category_tid, ac_category_address FROM `ac_category` ORDER BY `ac_category_tid`"

    # 结果集为 0:名称; 1: id;2:地址
    cursor.execute(sql)
    results = cursor.fetchall()
    cate_arr = {}
    for result in results:
        cate_arr[result[1]] = result

    index = 0
    articles_arr = {}
    for category in cate_arr:
        sql = """SELECT ac_article_id, ac_article_name, ac_article_link, ac_article_view
                FROM `ac_article`
                WHERE `ac_article_category` = %s AND `ac_article_date` >= ( NOW() - INTERVAL %s DAY )
                ORDER BY `ac_article_view` DESC
                LIMIT 15"""
        cursor.execute(sql, (cate_arr[category][1], date))
        results = cursor.fetchall()
        stat = []
        for result in results:
            stat.append(result)
        articles_arr[cate_arr[category][1]] = stat

    i = 0;
    for category in cate_arr:
        margin = ''
        if i%3 == 0:
            out_str += "<div style='width: 100%'>";
        elif i%3 == 2:
            margin = 'style="margin-right: 0 !important"'

        cate = ''
        if i == 0:
            cate = 'album'
        elif i == 1:
            cate = 'music'
        elif i == 2:
            cate = 'games'
        elif i == 4:
            cate = 'pencil'
        elif i == 3:
            cate = 'youtube'
        elif i == 5:
            cate = 'movie'
        icon = "<img src='images/metro/"+cate+".png' class='cate_section_icon' />"
        out_str += """<div class='cate_section' """+margin+">"+icon+"""
                <table>
                    <tr>
                        <th colspan='2' class='cate_section_title'><a href='http://www.acfun.tv/"""+cate_arr[category][2]+"""' target='_blank'>"""+cate_arr[category][0]+"""</a></th>
                    </tr>"""
        for article in articles_arr[category]:
            ac_article_name = article[1];
            ac_article_shortname = article[1]
            if len(article[1])> 15:
                ac_article_shortname = article[1][0:15]
            out_str += """<tr>
                    <td class='art_title'>
                        <a href='http://www.acfun.tv/v/"""+article[2]+"""/' target='_blank' title='"""+ cgi.escape(ac_article_name)+"""'>"""+ cgi.escape(ac_article_shortname)+"""</a>
                    </td>
                    <td class='art_count'>"""+str(article[3])+"""</td>
                </tr>"""
        out_str += "</table></div>";
        if i%3 == 2:
            out_str += "</div>"
        i+=1

        ac_core.cache("hot_"+type, out_str);

        try:
            cursor.close()
            conn.close()
        except:
            pass
Ejemplo n.º 3
0
#!/usr/bin/env python2.7
# -*- coding: UTF-8 -*-
# enable debugging

import sys, os, cgi
import ac_core
import tag_cloud

conn = ac_core.connect()
cursor = conn.cursor()
out_str = ''

ac_core.cache('tag_cloud_week', tag_cloud.get_cloud('', 7), False)
ac_core.cache('tag_cloud_month', tag_cloud.get_cloud('', 30), False)
ac_core.cache('tag_cloud_year', tag_cloud.get_cloud('',365), False)
ac_core.cache('tag_cloud_all', tag_cloud.get_cloud('', 3650), False)

try:
    cursor.close()
    conn.close()
except:
    pass
Ejemplo n.º 4
0
def main():
    date = 7
    title = u'周最佳UP主'
    type = 'week'
    type_arr = {'week':7, 'month':30, 'year': 365, 'all': 3650}
    title_arr = {'week':u'周最佳UP主', 'month':u'月度UP主', 'year': u'年度UP主', 'all': u'基友堂'}
    out_str = ''
    if(len(sys.argv) == 2):
        if sys.argv[1] in type_arr:
            date = type_arr[sys.argv[1]]
            title = title_arr[sys.argv[1]]
            type = sys.argv[1]

    sql = """SELECT `ac_author_name` AS name, `ac_author_id` AS id, SUM( `ac_article_view` ) AS view, COUNT( * ) AS post
            FROM `ac_article`
            WHERE `ac_article_date` >= ( NOW() - INTERVAL """ + str(date) + """ DAY )
            GROUP BY `ac_author_id`
            ORDER BY view DESC
            LIMIT 21 """;

    # 结果集为 0:姓名; 1: id;2:所有投稿的总点击量;3:投稿总数
    cursor.execute(sql)
    results = cursor.fetchall()
    data_arr = []
    for result in results:
        data_arr.append(result)

    # 过去的排名
    oldnum_arr = {}
    # 除了名人堂不用比较趋势,其他三项都需要比较,所以要再取一次以前的(昨天的)数据
    if date != 3650:
        sql = """SELECT `ac_author_name` AS name, `ac_author_id` AS id, SUM( `ac_article_view` ) AS view, COUNT( * ) AS post
            FROM `ac_article`
            WHERE `ac_article_date` <= ( NOW() - INTERVAL 1 DAY )
                  AND `ac_article_date` >= (NOW() - INTERVAL """ + str(date + 1) + """ DAY)
            GROUP BY `ac_author_id`
            ORDER BY view DESC
            LIMIT 20 """;
        cursor.execute(sql)
        results = cursor.fetchall()
        num = 0
        for result in results:
            oldnum_arr[result[1]] = num
            num = num + 1

    out_str += '<div class="main">'
    for i in range(0, 21):
        trend = "";
        if date != 3650:
            trend = "<img src='images/metro/"
            if data_arr[i][1] not in oldnum_arr:
                trend += "arrow_up"
            else:
                if i < oldnum_arr[data_arr[i][1]]:
                    trend += "arrow_up"
                elif i > oldnum_arr[data_arr[i][1]]:
                    trend += "arrow_down"
                else:
                    trend += "minus"
            trend += ".png' class='trend_icon'>"
        if i < 3:
            out_str += '<div class="up_top">';
            out_str += '<div class="up_top_info">'+trend+'<table width="100%"><tr><td class="up_top_titile"><a href="http://wiki.acfun.tv/index.php/'+cgi.escape(data_arr[i][0])+'" target="_blank"><span style="font-size: ' + str(26 - 2 * i) + 'px">' + cgi.escape(data_arr[i][0]) + """</span></a></td></tr>
                    <tr><td class="up_top_stat">View:&nbsp;&nbsp;""" + str(data_arr[i][2]) + """</td></tr>
                    <tr><td class="up_posts">""" + top_posts(str(data_arr[i][1]), str(date)) + '</td></tr></table></div>'
            out_str += '</div>';
        else:
            font_size = (i < 7) and (25 - i) or 18
            out_str += '<div class="up_normal">';
            out_str += '<div class="up_normal_info">'+trend+'<table width="100%"><tr><td class="up_normal_titile"><a href="http://wiki.acfun.tv/index.php/'+ cgi.escape(data_arr[i][0])+'" target="_blank"><span style="font-size:' + str(font_size) + 'px">' + cgi.escape(data_arr[i][0]) + """</span></a></td></tr>
                    <tr><td class="up_normal_stat">View:&nbsp;&nbsp; """ + str(data_arr[i][2]) + """</td></tr>
                    <tr><td class="up_posts">""" + top_posts(str(data_arr[i][1]), str(date)) + '</td></tr></table></div>'
            out_str += '</div>';

    out_str += '</div>';
    
    ac_core.cache("up_"+type, out_str)
    try:
        cursor.close()
        conn.close()
    except:
        pass