Skip to content

Instantly share code, notes, and snippets.

@taka2
Created July 15, 2010 07:50
Show Gist options
  • Select an option

  • Save taka2/476639 to your computer and use it in GitHub Desktop.

Select an option

Save taka2/476639 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
#!/usr/bin/env python
#
# Copyright 2007 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
from google.appengine.ext import webapp
from google.appengine.ext.webapp import util
from google.appengine.api import urlfetch
from google.appengine.ext.webapp import template
from django.utils import feedgenerator
import feedparser
class FeedHandler(webapp.RequestHandler):
def get(self):
# ソースフィードの取得
target_url = self.request.get('url')
res = urlfetch.fetch(target_url, deadline=20)
# ソースフィードの解析
d = feedparser.parse(res.content)
# フィルタ済みフィードの作成
f = feedgenerator.Rss201rev2Feed(
title=d.feed.title,
link=d.feed.link,
description=d.feed.description,
language=u"en")
for entry in d.entries:
if entry.title.startswith("PR"):
continue
if entry.title.startswith("AD"):
continue
if entry.title.find(u"のツッコミ") != -1:
continue
if entry.title.find(u"のツイート") != -1:
continue
if entry.title.find(u"Today’s つぶやき") != -1:
continue
if entry.title == u"[diary] 日記":
continue
if entry.title == u"[twitter] summary":
continue
f.add_item(title=entry.title,
link=entry.link,
description=entry.description)
# フィードを出力
self.response.out.write(f.writeString('utf8'))
def main():
application = webapp.WSGIApplication([('/feed/', FeedHandler)],
debug=True)
util.run_wsgi_app(application)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment