Last active
August 7, 2017 11:42
-
-
Save apalii/826145e4e89d835f317f5cce263d25ab to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # -*- coding: utf8 -*- | |
| import json | |
| from datetime import datetime | |
| import requests | |
| class MyShows(object): | |
| API_URL = 'https://api.myshows.me/v2/rpc/' | |
| TOKEN_URL = 'https://myshows.me/oauth/token' | |
| def __init__(self, username, password, client_id, secret): | |
| self._username = username, | |
| self._password = password, | |
| self._client_id = client_id | |
| self._secret = secret | |
| self._token = self._get_token() | |
| def _get_token(self): | |
| """ | |
| Response example: | |
| {u'access_token': u'aad45841b7ce73c9012a3e940a8ac7ad0076c927', | |
| u'expires_in': 1209600, | |
| u'refresh_token': u'd41a4ba500d8a0870ee0f27fa70a6c34690ff901', | |
| u'scope': u'basic', | |
| u'token_type': u'Bearer'} | |
| """ | |
| params = { | |
| "grant_type": "password", | |
| "client_id": self._client_id, | |
| "client_secret": self._secret, | |
| "username": self._username, | |
| "password": self._password, | |
| } | |
| token = requests.post(self.TOKEN_URL, data=params).json() | |
| return { | |
| "token": "{} {}".format(token['token_type'], token['access_token']), | |
| "expires": "{}".format(datetime.fromtimestamp(token['expires_in'])) | |
| } | |
| def _make_request(self, params, token): | |
| headers = {'accept-language': 'en', | |
| 'authorization': token, | |
| 'cache-control': 'no-cache', | |
| 'content-type': 'application/json'} | |
| response = requests.post(self.API_URL, data=json.dumps(params), headers=headers) | |
| return response.json() | |
| def unwatched(self): | |
| """ | |
| lists.Episodes method - Get User Episodes List | |
| """ | |
| params = {'id': 1, | |
| 'jsonrpc': '2.0', | |
| 'method': 'lists.Episodes', | |
| 'params': {'list': 'unwatched'} | |
| } | |
| return self._make_request(params, self._token['token']) | |
| def upcomming(self): | |
| pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment