Example #1
0
def detail(id):
    if id == None:
        return '参数不能为空'

    thread = threading.Thread(target=increase, name='increase', args=(id, ))
    thread.start()

    db = Database('detail')
    data = db.query(
        """select * from detail where news_id = '%s' and status = 1""", (id, ),
        one=True)
    del db

    if data == None or len(data['content']) < 10:
        return script.error(id)

    p = re.compile('<[^>]+>')
    text = p.sub("", data['content'])
    data['description'] = text[0:150]
    data['description'] = re.sub(u'[\s\r\t\n\d]', '', data['description'])
    data['keywords'] = csynonym.divide(text)
    data['pubDate'] = time.strftime("%Y-%m-%dT%H:%M:%S", time.localtime())
    imgs = common.analysisImgs(data['content'])
    data['imgs'] = imgs[0:3]

    return data
Example #2
0
def hotList(max=5, type=6):
    db = Database('hotlist')
    if type != 6:
        re = db.query(
            """select * from news where type = %d and status = 1 order by read_count desc limit %d offset 0""",
            (type, max))
    else:
        re = db.query(
            """select * from news where status = 1 order by read_count desc limit %d offset 0""",
            (max, ))

    list = []
    for news in re:
        news['target'] = common.md5(news['source_url'])
        news['order'] = re.index(news) + 1
        list.append(news)

    return list
Example #3
0
def verify_user(username, password):
    db = Database('verify_user')
    re = db.query(
        """select password from account where number='%s' and status = 1 """,
        (username, ), True)
    if re and re.has_key('password') and re['password'] == common.md5(
            password):
        return True

    return False
Example #4
0
def banner():
    db = Database('banner')
    re = db.query(
        """select * from news where create_time in (select max(create_time) from `news` where status=1 group by type)"""
    )

    list = []
    types = []
    for n in re:
        if n['type'] not in types:
            types.append(n['type'])
            list.append(n)

    return manageNews(list)
Example #5
0
def test(retry=None):
    db = Database('test')
    if retry == None:
        sql = "select * from news where status = 1"
    else:
        sql = "select * from news where status = 1 and news_id not in (select news_id from detail)"

    re = db.query(sql)
    del db

    for news in re:
        print insert_detail(common.md5(news['source_url']), news['news_id'])

    return '<center><h1> %d </h1></center>' % len(re)
Example #6
0
def newslist(offset=0, count=10, type=1, PC=True):
    db = Database('newslist')
    if type == 6:
        # 推荐
        re = recommend(offset)
    else:
        re = db.query(
            """select * from news where type = %d and status = 1 order by create_time desc limit %d offset %d""",
            (type, count, offset))

    # print '----------------------- query data count: ' + str(len(re)) + ' -------------------------'

    list = manageNews(re, PC)
    random.shuffle(list)
    return list
Example #7
0
def search(keyword, offset=0, count=10, PC=True):
    db = Database('search')
    if keyword == None:
        return []

    newKey = '%'
    for c in keyword:
        newKey = newKey + c + '%'

    re = db.query(
        """select * from news where title like '%s' and status = 1 order by id desc limit %d offset %d""",
        (newKey, count, offset))
    # print '----------------------- query data count: ' + str(len(re)) + ' -------------------------'

    list = manageNews(re, PC)

    return list
Example #8
0
def add_news(title, content, imgs, type, username):
    import uuid
    news_id = str(uuid.uuid1())

    db = Database('add_news')
    user = db.query(
        """select nickname from account where number='%s' and status=1""",
        (username, ), True)
    del db

    imgs = imgs.split(',')
    re = script.insert_news(news_id, title, u'丽人资讯', 'wwww.somenews.cn',
                            user['nickname'], 0, '', int(type), imgs)
    if re == 1:
        dre = script.insert_detail(news_id, title, content, user['nickname'],
                                   '')
        if dre == 1:
            script.appendIDs((news_id, ))
            script.post_tongji()
            return news_id

    return False
Example #9
0
def manageNews(args=[], PC=True):
    db = Database('manageNews')
    if len(args) == 0:
        return args

    haveFullStyle = False
    list = []
    for news in args:
        news['is_pc'] = PC
        imgs = db.query("""select url from image where news_id = '%s'""",
                        (news['news_id'], ))
        srcs = []

        for img in imgs:
            srcs.append(img['url'])

        rdm = random.randint(0, 9)
        length = len(srcs)

        if PC:
            count = 1 if length < 4 else 4
            if rdm % 2 == 0 and news[
                    'summary'] != None and haveFullStyle == False:
                haveFullStyle = True
                count = 2
        else:
            count = 3
            if rdm % 2 == 0 and news[
                    'summary'] != None and haveFullStyle == False:
                haveFullStyle = True
                count = 2

        news['imgs'] = srcs[:count]
        list.append(news)

    return list
Example #10
0
def recommend(offset=0):
    db = Database('recommend')
    re = db.query(
        """select * from news where status = 1 order by create_time desc, read_count desc limit %d offset %d""",
        (20, offset))
    return re