-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStore.py
55 lines (52 loc) · 2.08 KB
/
Store.py
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import requests
import os
import configparser
import pprint as pp
class Store(object):
access_token = None
slack_webhook = None
client_id = None
client_secret = None
redirect_url = None
twitch_names = []
subscription_time = 864000
default_header = {}
@staticmethod
def refresh_access_token():
params = {
'client_id': Store.client_id,
'client_secret': Store.client_secret,
'grant_type': 'client_credentials'
}
if Store.access_token is None:
r = requests.post('https://id.twitch.tv/oauth2/token', params=params)
if r.status_code == 200:
pp.pprint(r.json())
Store.app_token = r.json()['access_token']
Store.default_header['Authorization'] = f'Bearer {Store.app_token}'
r = requests.get('https://api.twitch.tv/helix/webhooks/subscriptions', headers=Store.default_header)
if r.status_code == 200:
pp.pprint(r.json())
else:
# refresh token
pass
@staticmethod
def setup(configfile=None):
print( configfile )
if configfile is None:
Store.slack_webhook = os.environ['SLACK_WEBHOOK']
Store.client_id = os.environ['CLIENT_ID']
Store.client_secret = os.environ['CLIENT_SECRET']
Store.redirect_url = os.environ['REDIRECT_URL']
Store.twitch_names = os.environ['TWITCH_NAMES'].split(',')
Store.default_header['Client-ID'] = Store.client_id
else:
config = configparser.ConfigParser()
config.optionxform = str
config.read(configfile)
Store.slack_webhook = config['DEFAULT']['SLACK_WEBHOOK_DEV']
Store.client_id = config['DEFAULT']['CLIENT_ID']
Store.client_secret = config['DEFAULT']['CLIENT_SECRET']
Store.redirect_url = config['DEFAULT']['REDIRECT_URL']
Store.twitch_names = config['DEFAULT']['TWITCH_NAMES'].split(',')
Store.default_header['Client-ID'] = Store.client_id