Changeset 18249

Show
Ignore:
Timestamp:
08/26/08 16:40:23 (5 years ago)
Author:
mattn
Message:

* 画面仕様変更に対応
* 絵文字だけのタイトルだと見えないのでtitleにはaltを使用

Location:
websites/wassr-fav.appspot.com
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • websites/wassr-fav.appspot.com/wassr-fav.py

    r16738 r18249  
    44import logging 
    55import wsgiref.handlers 
    6 from BeautifulSoup import BeautifulSoup 
     6from BeautifulSoup import BeautifulSoup,Tag 
    77from google.appengine.api import urlfetch 
    88from google.appengine.ext import webapp 
    99from google.appengine.ext.webapp import template 
    1010 
    11 def to_text(soup): 
    12   ret = ''.join([e for e in soup.recursiveChildGenerator() if isinstance(e,unicode)]).replace(' ', ' ') 
    13   soup = BeautifulSoup(ret, convertEntities=BeautifulSoup.HTML_ENTITIES) 
    14   return soup and soup.contents and soup.contents[0].encode('utf-8', 'replace').replace('\n', '') or '' 
     11def to_text(soup, use_img_alt=False): 
     12  ret = "" 
     13  for e in soup.recursiveChildGenerator(): 
     14    if isinstance(e,Tag) and e.name == 'img' and not "icn-balloon" in e['src']: 
     15      if use_img_alt: 
     16        ret += "(%s)" % e['alt'] 
     17      else: 
     18        e['src'] = "http://wassr.jp%s" % e['src'] 
     19        ret += unicode(e) 
     20    elif isinstance(e,unicode): 
     21      ret += e.strip() 
     22  ret = ret.replace(' ', ' ').replace('  ', '\n') 
     23  #ret = ' '.join([e.strip() for e in soup.recursiveChildGenerator() if isinstance(e,unicode) or (isinstance(e,Tag) and e.name == 'img')]).replace(' ', ' ').replace('  ', '\n') 
     24  #soup = BeautifulSoup(ret, convertEntities=BeautifulSoup.HTML_ENTITIES) 
     25  #return soup and soup.contents and soup.contents[0].encode('utf-8', 'replace').replace('\n', '') or '' 
     26  return ret 
    1527 
    1628class MainPage(webapp.RequestHandler): 
     
    3749      r2 = re.compile(r'(.*)\([^\)]+\) (.*)') 
    3850      for page_fav in page_favs: 
    39         author = r1.sub(lambda x: x.group(1), page_fav.find('p', { 'class' : 'favorited_user noteTxt' }).find('a')['href']) 
     51        author = r1.sub(lambda x: x.group(1), page_fav.find('form', { 'class' : 'followbutton favorited_user noteTxt' }).find('a')['href']) 
    4052        #name = to_text(page_fav.find('p', { 'class' : 'favorited_user noteTxt' }).find('a')) 
    4153        template_values['favs'].append({ 
    42           'title' : to_text(page_fav.find('p', { 'class' : 'message description' })).strip(), 
     54          'title' : to_text(page_fav.find('p', { 'class' : 'message description' }), True).strip(), 
    4355          'link' : 'http://wassr.jp%s' % page_fav.find('a', { 'class' : 'MsgDateTime' })['href'], 
    4456          'guid' : 'http://wassr.jp%s#%s' % (page_fav.find('a', { 'class' : 'MsgDateTime' })['href'], author), 
  • websites/wassr-fav.appspot.com/wassr-fav.rss

    r16738 r18249  
    66    <description>「{{ user|escape }}」がもらったイイネ</description>{% for fav in favs %} 
    77    <item> 
    8         <title>「{{ fav.title|escape }}」のイイネ</title> 
     8        <title>「{{ fav.title }}」のイイネ</title> 
    99        <link>{{ fav.link|escape }}</link> 
    1010        <author>{{ fav.author|escape }}</author>