Custom prefix with formatting
[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 """
5531923e 12 try:
62058715 13 # twitterException.response_data can be byte string on Python 3
14 # or nornal dict on Python 2
15 loadedJson = json.loads(twitterException.response_data.decode('utf8'))
5531923e 16 for m in loadedJson.get('errors', dict()):
9e38891f 17 info = "Error " + str(m.get('code')) + ": " + m.get('message')
18 printNicely(yellow(info))
62058715 19 except:
20 info = "Error: " + twitterException.response_data.decode('utf8')
9e38891f 21 printNicely(yellow(info))
b85ec13a
LP
22
23
24def format_prefix(listname = '', keyword = ''):
25 """
26 Format the custom prefix
27 """
28 formattedPrefix = c['PREFIX']
29 username = '@' + c['original_name']
30 place = ''
31 if keyword != '':
32 place = '/public'
33 keyword = '#' + keyword
34
35 if listname != '':
36 username, place = listname.split('/')
37 place = "/" + place
38
39 formattedPrefix = formattedPrefix.replace("#username", username)
40 formattedPrefix = formattedPrefix.replace("#place", place)
41 formattedPrefix = formattedPrefix.replace("#keyword", keyword)
42
43 return formattedPrefix