-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase.py
More file actions
33 lines (25 loc) · 1.08 KB
/
base.py
File metadata and controls
33 lines (25 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from statistics import mean
from requests import get
class PushbulletException(Exception):
"""Custom Exception Handler."""
pass
class Pushbullet(object):
"""Top level methods and header info."""
def __init__(self, access_token):
self.header = {'Access-Token': access_token, 'Content-Type': 'application/json'}
self.me = get(url='https://api.pushbullet.com/v2/users/me',
headers=self.header).json()
self.rl_reset = None # place holder for ratelimit.
self.rl_left = None
self.rl_reduce = []
def ratelimit(self, response):
# called at the end of a message send to update the remaining.
if None is not self.rl_left:
self.rl_reduce.append(
int(self.rl_left) - int(response.headers['x-ratelimit-remaining']))
self.rl_left = response.headers['x-ratelimit-remaining']
self.rl_reset = response.headers['x-ratelimit-reset']
return mean(self.rl_reduce) if len(self.rl_reduce) > 0 else 0
@property
def reduced(self):
return mean(self.rl_reduce)