Пример #1
0
def getRef(authorlist, year):
    """Returns a dictionary parsed from citeulike via YQL with title, reference etc"""

    querydict = {"format":"json"}

    querystring = "select item from xml where url='http://www.citeulike.org/rss/user/CameronNeylon/'"
    querystring = querystring + ' and item.date LIKE "%s%%"' % year
    for author in authorlist:
        querystring = querystring + ' and item.creator LIKE "%%%s%%"' % author

    querydict['q'] = querystring
    query = urllib.urlencode(querydict)
    result = urllib.urlopen('http://query.yahooapis.com/v1/public/yql?%s'
                                           % query)
    jsonresult = json.load(result)

    # The following will break if there is more than one result returned but will do for moment

    try: 
        jsonitem = jsonresult.get('query', None).get('results', None
                                  ).get('RDF', None).get('item', None)
    except:
        return
    citation = { 'authors'  : jsonitem.get('creator', None),
                 'title'    : jsonitem.get('title', None)[0],
                 'journal'  : jsonitem.get('publicationName', None),
                 'volume'   : jsonitem.get('volume', None),
                 'page'     : jsonitem.get('startingPage', None),
                 'year'     : year,
                 'link'     : jsonitem.get('about', None)}

    return citation
Пример #2
0
def translate(text, src, to):
	args = urllib.urlencode({ 'langpair' : '%s|%s' % (src, to), 'v' : '1.0', 'q' : text })
	url = 'http://ajax.googleapis.com/ajax/services/language/translate'
	resp = simplejson.load(urllib2.urlopen(url, data=args))
	return resp['responseData']['translatedText'].encode('utf8')