Added #me for actual user's name
[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']
d8fab2ca 29 owner = '@' + c['original_name']
b85ec13a
LP
30 place = ''
31 if keyword != '':
32 place = '/public'
33 keyword = '#' + keyword
34
35 if listname != '':
d8fab2ca 36 owner, place = listname.split('/')
b85ec13a
LP
37 place = "/" + place
38
d8fab2ca 39 formattedPrefix = formattedPrefix.replace("#owner", owner)
b85ec13a
LP
40 formattedPrefix = formattedPrefix.replace("#place", place)
41 formattedPrefix = formattedPrefix.replace("#keyword", keyword)
d8fab2ca 42 formattedPrefix = formattedPrefix.replace("#me", '@' + c['original_name'])
b85ec13a
LP
43
44 return formattedPrefix