From 974bad79747efa6cca1090c128f68104cb36eb68 Mon Sep 17 00:00:00 2001 From: pictuga Date: Wed, 14 May 2014 15:01:41 +0200 Subject: [PATCH] Fix and strip down facebook Remove unstable non-working facebook semi-automatic token renewal (a simple warning on morss.it should be enough). Also commited some forgotten stuff. --- morss/feedify.py | 32 -------------------------------- morss/morss.py | 17 ++--------------- 2 files changed, 2 insertions(+), 47 deletions(-) diff --git a/morss/feedify.py b/morss/feedify.py index c82cbd6..d205d88 100644 --- a/morss/feedify.py +++ b/morss/feedify.py @@ -78,24 +78,6 @@ def formatString(string, getter, error=False): return out def PreWorker(url, cache): - if urlparse.urlparse(url).netloc == 'graph.facebook.com': - facebook = cache.new('facebook', persistent=True, dic=True) - token = urlparse.parse_qs(urlparse.urlparse(url).query)['access_token'][0] - - if token not in facebook['token']: - return - - # hey look for a newer token and use it - token = urlparse.parse_qs(urlparse.urlparse(url).query)['access_token'][0] - user_id = facebook['token'][token]['user'] - last = facebook['user'][user_id]['token'] - original = facebook['user'][user_id]['original'] - - nurl = url.replace(token, last) - ncache = url.replace(token, original) - cache.set('redirect', nurl) - cache.set('cache', ncache) - if urlparse.urlparse(url).netloc == 'itunes.apple.com': match = re.search('/id([0-9]+)(\?.*)?$', url) if match: @@ -199,17 +181,3 @@ class Builder(object): self.feed.items.append(feedItem) - - if urlparse.urlparse(self.link).netloc == 'graph.facebook.com': - if self.cache: - facebook = self.cache.new('facebook', True) - token = urlparse.parse_qs(urlparse.urlparse(self.link).query)['access_token'][0] - expires = facebook['token'][token]['expires'] - lifespan = expires - time.time() - - if lifespan < 5*24*3600: - new = self.feed.items.append() - new.title = "APP AUTHORISATION RENEWAL NEEDED" - new.link = "https://www.facebook.com/dialog/oauth?client_id={app_id}&redirect_uri=http://test.morss.it/:facebook/".format(app_id=morss.FBAPPID) - new.desc = "Please renew your Facebook app token for this app to keep working for this feed.
Go!".format(new.link) - new.time = expires diff --git a/morss/morss.py b/morss/morss.py index 44d3709..19f6116 100644 --- a/morss/morss.py +++ b/morss/morss.py @@ -722,7 +722,7 @@ def cgi_app(environ, start_response): url, cache = Init(url, os.getcwd() + '/cache', options) if options.facebook: - doFacebook(url, headers, options, cache) + doFacebook(url, environ, headers, options, cache) start_response(headers['status'], headers.items()) return @@ -774,7 +774,7 @@ def cli_app(): log('done') -def doFacebook(url, headers, options, cache): +def doFacebook(url, environ, headers, options, cache): log('fb stuff') facebook = cache.new('facebook', persistent=True, dic=True) @@ -793,19 +793,6 @@ def doFacebook(url, headers, options, cache): ltoken = values['access_token'][0] expires = int(time.time() + int(values['expires'][0])) - # get user id - iurl = "https://graph.facebook.com/me?fields=id&access_token={token}".format(token=ltoken) - user_id = json.loads(urllib2.urlopen(iurl).read())['id'] - - # do sth out of it - if user_id not in facebook['user']: - facebook['user'][user_id] = {'original': ltoken} - - facebook['token'][ltoken] = {'user': user_id, 'expires': expires} - facebook['user'][user_id]['token'] = ltoken - - facebook.save() - headers['set-cookie'] = 'token={token}; Path=/'.format(token=ltoken) # headers