-
Notifications
You must be signed in to change notification settings - Fork 0
/
interactive_console.py
43 lines (31 loc) · 1.03 KB
/
interactive_console.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
#!/usr/bin/python
import ShirtsIO
import yaml
import os
import code
def new_user(yaml_path):
'''
Return the consumer and oauth tokens with three-legged OAuth process and
save in a yaml file in the user's home directory.
'''
print 'Retrieve API Key from https://www.shirts.io/accounts/api_console/'
api_key = raw_input('Shirts.io API Key: ')
tokens = {
'api_key': api_key,
}
yaml_file = open(yaml_path, 'w+')
yaml.dump(tokens, yaml_file, indent=2)
yaml_file.close()
return tokens
if __name__ == '__main__':
yaml_path = os.path.expanduser('~') + '/.pyshirtsio'
if not os.path.exists(yaml_path):
tokens = new_user(yaml_path)
else:
yaml_file = open(yaml_path, "r")
tokens = yaml.safe_load(yaml_file)
yaml_file.close()
client = ShirtsIO.ShirtsIOClient(tokens['api_key'])
print 'You may run PyShirtsIO commands prefixed with "client."."'
print 'client = ShirtsIOClient()\n'
code.interact(local=dict(globals(), **{'client': client}))