Merge pull request #131 from moehabib/patch-1
[rainbowstream.git] / rainbowstream / util.py
CommitLineData
5531923e
LP
1import json
2
3from twitter.util import printNicely
8daad13d 4from .colors import *
b85ec13a 5from .config import *
5531923e
LP
6
7
9e38891f 8def detail_twitter_error(twitterException):
8daad13d 9 """
10 Display Twitter Errors nicely
11 """
5b5f261a 12 data = twitterException.response_data
5531923e 13 try:
5b5f261a 14 for m in data.get('errors', dict()):
15 printNicely(yellow(m.get('message')))
16 except:
17 printNicely(yellow(data))
b85ec13a
LP
18
19
063f6bb1 20def format_prefix(listname='', keyword=''):
b85ec13a
LP
21 """
22 Format the custom prefix
23 """
24 formattedPrefix = c['PREFIX']
d8fab2ca 25 owner = '@' + c['original_name']
b85ec13a 26 place = ''
063f6bb1 27 # Public stream
879a9448 28 if keyword:
063f6bb1 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'))
d8fab2ca 36 owner, place = listname.split('/')
063f6bb1 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'))
b85ec13a 43
f07cfb6b 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'])
b85ec13a
LP
48
49 return formattedPrefix