Skip to content

Instantly share code, notes, and snippets.

@garettmd
Created June 9, 2015 02:32
Show Gist options
  • Save garettmd/3794f379a5b86b393e3f to your computer and use it in GitHub Desktop.
Save garettmd/3794f379a5b86b393e3f to your computer and use it in GitHub Desktop.
Trouble Code
class PickitSession(FlaskView):
route_base = '/'
def __init__(self):
self.CONSUMER_KEY = '41815-cd31a16ee9750c7a782f9cde'
self.ACCESS_TOKEN = ''
self.REDIRECT_URI = 'http://127.0.0.1:5000'
self.OAUTH_REQUEST_URL = 'https://getpocket.com/v3/oauth/request'
self.AUTH_URL = 'https://getpocket.com/auth/authorize'
self.OAUTH_ACCESS_URL = 'https://getpocket.com/v3/oauth/authorize'
self.HEADERS = {'Content-Type': 'application/json; charset=UTF-8', 'X-Accept': 'application/json'}
self.USERNAME = ''
self.GET_URL = 'https://getpocket.com/v3/get'
def authenticate(self):
data = {'consumer_key': self.CONSUMER_KEY, 'redirect_uri': self.REDIRECT_URI}
response = r.post(self.OAUTH_REQUEST_URL, headers=self.HEADERS, data=json.dumps(data))
json_response = json.loads(response.text)
self.AUTH_URL = self.AUTH_URL + '?request_token=' + json_response[
'code'] + '&redirect_uri=' + self.REDIRECT_URI + '/auth_redirect/' + json_response['code']
webbrowser.open_new_tab(self.AUTH_URL)
@route('/auth_redirect/<code>')
def authorize(self, code):
# TODO finally redirect page to success.html - Might need to change the whole redirect URI and update the
# route to point to /success.html or something like that
data = {'consumer_key': self.CONSUMER_KEY, 'code': code}
auth_response = r.post(self.OAUTH_ACCESS_URL, headers=self.HEADERS, data=json.dumps(data))
json_response = json.loads(auth_response.text)
self.ACCESS_TOKEN = json_response['access_token']
self.USERNAME = json_response['username']
print(self.ACCESS_TOKEN, self.USERNAME)
main_menu()
shutdown_server()
return
def view_articles(self):
data = {'count': 20, 'detailType': 'simple', 'consumer_key': self.CONSUMER_KEY,
'access_token': self.ACCESS_TOKEN}
print(data)
print(self.USERNAME)
articles = r.post(self.GET_URL, headers=self.HEADERS, data=json.dumps(data))
# TODO articlesappend('list next article')
# msg = 'Choose \"list next article\" to get the next articles chronologically.'
print(articles.text)
return articles.text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment