forked from pellepim/projectplace_workspace_sync
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
35 lines (28 loc) · 1.05 KB
/
config.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
import json
import voluptuous
import requests_oauthlib
class Config(object):
ConfSchema = voluptuous.Schema({
'consumer_key': str,
'consumer_secret': str,
'access_token': str,
'access_token_secret': str,
'host': str,
voluptuous.Optional('workspace_ids'): [int]
}, required=True)
def __init__(self):
with open('config.json') as conf:
conf_dict = self.ConfSchema(json.load(conf))
self.CONSUMER_KEY = conf_dict['consumer_key']
self.CONSUMER_SECRET = conf_dict['consumer_secret']
self.ACCESS_TOKEN = conf_dict['access_token']
self.ACCESS_TOKEN_SECRET = conf_dict['access_token_secret']
self.HOST = conf_dict['host']
self.WORKSPACE_IDS = conf_dict.get('workspace_ids', [])
def oauth(self):
return requests_oauthlib.OAuth1(
self.CONSUMER_KEY, client_secret=self.CONSUMER_SECRET, resource_owner_key=self.ACCESS_TOKEN,
resource_owner_secret=self.ACCESS_TOKEN_SECRET
)
conf = Config()
oauth = conf.oauth()