Changeset 18249
- Timestamp:
- 08/26/08 16:40:23 (5 years ago)
- Location:
- websites/wassr-fav.appspot.com
- Files:
-
- 2 modified
-
wassr-fav.py (modified) (2 diffs)
-
wassr-fav.rss (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
websites/wassr-fav.appspot.com/wassr-fav.py
r16738 r18249 4 4 import logging 5 5 import wsgiref.handlers 6 from BeautifulSoup import BeautifulSoup 6 from BeautifulSoup import BeautifulSoup,Tag 7 7 from google.appengine.api import urlfetch 8 8 from google.appengine.ext import webapp 9 9 from google.appengine.ext.webapp import template 10 10 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 '' 11 def 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 15 27 16 28 class MainPage(webapp.RequestHandler): … … 37 49 r2 = re.compile(r'(.*)\([^\)]+\) (.*)') 38 50 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']) 40 52 #name = to_text(page_fav.find('p', { 'class' : 'favorited_user noteTxt' }).find('a')) 41 53 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(), 43 55 'link' : 'http://wassr.jp%s' % page_fav.find('a', { 'class' : 'MsgDateTime' })['href'], 44 56 'guid' : 'http://wassr.jp%s#%s' % (page_fav.find('a', { 'class' : 'MsgDateTime' })['href'], author), -
websites/wassr-fav.appspot.com/wassr-fav.rss
r16738 r18249 6 6 <description>「{{ user|escape }}」がもらったイイネ</description>{% for fav in favs %} 7 7 <item> 8 <title>「{{ fav.title |escape}}」のイイネ</title>8 <title>「{{ fav.title }}」のイイネ</title> 9 9 <link>{{ fav.link|escape }}</link> 10 10 <author>{{ fav.author|escape }}</author>
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)