Skip to content

Instantly share code, notes, and snippets.

@makotoworld
Created August 6, 2010 08:05
Show Gist options
  • Save makotoworld/511025 to your computer and use it in GitHub Desktop.
Save makotoworld/511025 to your computer and use it in GitHub Desktop.
DeafNewsJp Python
import datetime
from google.appengine.ext import db
from google.appengine.api import users
class Deafnewsdb(db.Model):
keyword = db.StringProperty(required=True)
title = db.StringProperty(required=True)
url = db.StringProperty(required=True)
bitly_url = db.StringProperty(required=True)
publisher = db.StringProperty(required=True)
publisheddate = db.StringProperty(required=True)
flag = db.StringProperty(required=True)
created_at = db.DateProperty()
e = Deafnewsdb(keyword="",
title="",
url="",
bitly_url="",
publisher="",
publisher="",
flag="0")
e.created_at = datetime.datetime.now()
e.put()
#!/usr/bin/python
# -*- coding: utf-8 -*-
import urllib
import simplejson
def deafnews(keyword):
for a in range(8):
postdata = {
'v' : '1.0',
'rsz' : 'large',
'hl' : 'ja',
'scoring' : 'd',
'ned' : 'jp',
'q' : keyword,
'start' : a
}
params = urllib.urlencode(postdata)
url = 'http://ajax.googleapis.com/ajax/services/search/news?%s'
news_results = urllib.urlopen(url % params)
json = simplejson.loads(news_results.read())
results = json['responseData']['results']
for i in results:
print unicode('keyword :', 'utf-8') + keyword.decode('utf-8')
print unicode("タイトル :", 'utf-8') + i['titleNoFormatting']
print unicode("URL :", 'utf-8') + bit_ly(i['unescapedUrl'])
print unicode("出典 :", 'utf-8') + i['publisher']
print unicode("言語 :", 'utf-8') + translate(i['titleNoFormatting'].encode('utf_8'))
def bit_ly(longurl):
postdata = {
'version' : '2.0.1',
'login' : 'makotoworld',
'longUrl' : longurl,
'apiKey' : 'R_c06a815b89dc6fc962df85f3f5680f99',
}
params = urllib.urlencode(postdata)
url = 'http://api.bit.ly/shorten?%s'
shorturl_results = urllib.urlopen(url % params)
json = simplejson.loads(shorturl_results.read())
#print json
results = "http://j.mp/" + json['results'][longurl]['userHash']
return results
def translate(query):
postdata = {
'v' : '1.0',
'langpair' : '|ja',
'q' : query,
}
params = urllib.urlencode(postdata)
url = 'http://ajax.googleapis.com/ajax/services/language/translate?%s'
shorturl_results = urllib.urlopen(url % params)
json = simplejson.loads(shorturl_results.read())
results = json['responseData']['detectedSourceLanguage']
return results
key = ["手話", "聴覚障害", "聴覚障がい", "聴力障害", "ろうあ者"]
for i in key:
deafnews(i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment