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.
master
pictuga 2014-05-14 15:01:41 +02:00
parent b7136f2056
commit 974bad7974
2 changed files with 2 additions and 47 deletions

View File

@ -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.<br/><a href='{}'>Go!</a>".format(new.link)
new.time = expires

View File

@ -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