Exemple #1
0
 def GET(self):
     mc_user = mc.get('users')
     if mc_user:
         users = mc_user
     else:
         users = get_users(active_users)
         has_error = False
         allrss = []
         for user in users:
             try:
                 rss = []
                 rss_url = user.rss_url
                 data = urllib.urlopen(rss_url)
                 data = data.read()
                 xml = minidom.parseString(data)
                 items = xml.getElementsByTagName('item')[:4]
                 for item in items:
                     rss_item = Rss()
                     title = get_xml_text(item.getElementsByTagName('title')[0].childNodes)
                     date = get_xml_text(item.getElementsByTagName('pubDate')[0].childNodes)
                     link = get_xml_text(item.getElementsByTagName('link')[0].childNodes)
                     rss_item.title = title.encode('utf-8')
                     rss_item.date = date.split('+')[0].encode('utf-8')
                     rss_item.link = link.encode('utf-8')
                     rss.append(rss_item)
                     allrss.append(rss_item)
                 user.rss = rss
             except:
                 has_error = True
                 user.rss = None
         if not has_error:
             mc.set('users', users, 3600 * 12)
     return st('blog.mako', **locals())
Exemple #2
0
def get_ids_of_cate(cate):
    ids = mc.get('ac:%s'%cate)
    if not ids:
        cursor = get_cursor()
        sql = 'select id from article '\
            'where cate=%s order by id desc'
        params = (cate)
        cursor.execute(sql, params)
        ids = [str(id) for (id, ) in cursor]
        mc.set('ac:%s'%cate, ids)
    return ids
Exemple #3
0
def get_ids_of_user(name):
    ids = mc.get('as:%s'%name)
    if not ids:
        cursor = get_cursor()
        sql = 'select id from article '\
            'where author=%s order by id desc'
        params = (name)
        cursor.execute(sql, params)
        ids = [str(id) for (id, ) in cursor]
        mc.set('as:%s'%name, ids)
    return ids
Exemple #4
0
def get_ids_of_user(name):
    ids = mc.get('as:%s' % name)
    if not ids:
        cursor = get_cursor()
        sql = 'select id from article '\
            'where author=%s order by id desc'
        params = (name)
        cursor.execute(sql, params)
        ids = [str(id) for (id, ) in cursor]
        mc.set('as:%s' % name, ids)
    return ids
Exemple #5
0
def get_ids_of_cate(cate):
    ids = mc.get('ac:%s' % cate)
    if not ids:
        cursor = get_cursor()
        sql = 'select id from article '\
            'where cate=%s order by id desc'
        params = (cate)
        cursor.execute(sql, params)
        ids = [str(id) for (id, ) in cursor]
        mc.set('ac:%s' % cate, ids)
    return ids
Exemple #6
0
 def get(cls, id):
     mc_article = mc.get('a:%s'%id)
     if mc_article:
         return mc_article
     cursor = get_cursor()
     sql = 'select cate, title, author, time, url, content from article ' \
         'where id=%s'
     params = (id)
     if cursor:
         cursor.execute(sql, params)
         r = cursor.fetchone()
         if r:
             article = cls(id, r[0], r[1], r[2], r[3], r[4], r[5])
             mc.set('a:%s'%id, article)
             return article
         return None
     return None
Exemple #7
0
 def get(cls, id):
     mc_article = mc.get('a:%s' % id)
     if mc_article:
         return mc_article
     cursor = get_cursor()
     sql = 'select cate, title, author, time, url, content from article ' \
         'where id=%s'
     params = (id)
     if cursor:
         cursor.execute(sql, params)
         r = cursor.fetchone()
         if r:
             article = cls(id, r[0], r[1], r[2], r[3], r[4], r[5])
             mc.set('a:%s' % id, article)
             return article
         return None
     return None