Merge pull request #165 from roskoff/master
[rainbowstream.git] / rainbowstream / util.py
1 import json
2
3 from twitter.util import printNicely
4 from .colors import *
5 from .config import *
6
7
8 def detail_twitter_error(twitterException):
9 """
10 Display Twitter Errors nicely
11 """
12 data = twitterException.response_data
13 try:
14 for m in data.get('errors', dict()):
15 printNicely(yellow(m.get('message')))
16 except:
17 printNicely(yellow(data))
18
19
20 def format_prefix(listname='', keyword=''):
21 """
22 Format the custom prefix
23 """
24 formattedPrefix = c['PREFIX']
25 owner = '@' + c['original_name']
26 place = ''
27 # Public stream
28 if keyword:
29 formattedPrefix = ''.join(formattedPrefix.split('#owner'))
30 formattedPrefix = ''.join(formattedPrefix.split('#place'))
31 formattedPrefix = ''.join(formattedPrefix.split('#me'))
32 # List stream
33 elif listname:
34 formattedPrefix = ''.join(formattedPrefix.split('#keyword'))
35 formattedPrefix = ''.join(formattedPrefix.split('#me'))
36 owner, place = listname.split('/')
37 place = '/' + place
38 # Personal stream
39 else:
40 formattedPrefix = ''.join(formattedPrefix.split('#keyword'))
41 formattedPrefix = ''.join(formattedPrefix.split('#owner'))
42 formattedPrefix = ''.join(formattedPrefix.split('#place'))
43
44 formattedPrefix = formattedPrefix.replace('#owner', owner)
45 formattedPrefix = formattedPrefix.replace('#place', place)
46 formattedPrefix = formattedPrefix.replace('#keyword', keyword)
47 formattedPrefix = formattedPrefix.replace('#me', '@' + c['original_name'])
48
49 return formattedPrefix