示例#1
0
文件: html.py 项目: yoshrote/Columns
def get_post_thumbnail(video_src, default_img=None):
    if video_src.find("vimeo.com") != -1:
        clip_id = dict(cgi.parse_qsl(urlparse.urlparse(video_src).query)).get("clip_id")
        resp = json.load(
            urllib2.urlopen(
                urllib2.Request(
                    "http://vimeo.com/api/v2/video/%s.json" % clip_id, headers={"User-Agent": "ColumnsAgent"}
                )
            )
        )
        return unicode(resp[0]["thumbnail_small"])
    elif video_src.find("youtube.com") != -1:
        parsed_url = urlparse.urlparse(video_src)
        clip_id = dict(cgi.parse_qsl(parsed_url.query)).get("v", parsed_url.path.split("/")[-1].split("&")[0])
        return unicode("http://img.youtube.com/vi/%s/default.jpg" % clip_id)
    else:
        return default_img
示例#2
0
	def _facebook_handler(pylons_obj):
		from columns.model import User, meta
		session = pylons_obj.session
		url = pylons_obj.url
		app_globals = pylons_obj.app_globals
		request = pylons_obj.request
		
		try:
			fbcode = request.params.get("code")
		except KeyError:
			redirect(url("login"))
		args = {
		'client_id':app_globals.settings(u'facebook_api_key', u'auth'),
		'redirect_uri':url('verify',qualified=True),
		'client_secret':app_globals.settings(u'facebook_secret', u'auth'),
		'code':fbcode,
		}
		fb_response = cgi.parse_qs(urllib.urlopen(
			"https://graph.facebook.com/oauth/access_token?" +
			urllib.urlencode(args)).read())
		try:
			access_token = fb_response["access_token"][-1]
		except KeyError:
			redirect(url('challenge', auth_type='facebook'))
			#return fb_login(g, session, request, response, 'facebook', None)
		
		# Download the user profile and cache a local instance of the
		# basic profile info
		profile = json.load(urllib.urlopen(
			"https://graph.facebook.com/me?" +
			urllib.urlencode(dict(access_token=access_token))))
		session['auth_type'] = 'facebook'
		session['auth_oid'] = profile["id"]
		try:
			return meta.Session.query(User).filter(User.fb_id==unicode(session['auth_oid'])).one()
		except:
			return None
示例#3
0
	def test_load(self):
		fp = StringIO('{"test": 1}')
		res = json.load(fp)
		self.assertEquals(res['test'],1)