Check tweet length
[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
063f6bb1 24def format_prefix(listname='', keyword=''):
b85ec13a
LP
25 """
26 Format the custom prefix
27 """
28 formattedPrefix = c['PREFIX']
d8fab2ca 29 owner = '@' + c['original_name']
b85ec13a 30 place = ''
063f6bb1 31 # Public stream
879a9448 32 if keyword:
063f6bb1 33 formattedPrefix = ''.join(formattedPrefix.split('#owner'))
34 formattedPrefix = ''.join(formattedPrefix.split('#place'))
35 formattedPrefix = ''.join(formattedPrefix.split('#me'))
36 # List stream
37 elif listname:
38 formattedPrefix = ''.join(formattedPrefix.split('#keyword'))
39 formattedPrefix = ''.join(formattedPrefix.split('#me'))
d8fab2ca 40 owner, place = listname.split('/')
063f6bb1 41 place = '/' + place
42 # Personal stream
43 else:
44 formattedPrefix = ''.join(formattedPrefix.split('#keyword'))
45 formattedPrefix = ''.join(formattedPrefix.split('#owner'))
46 formattedPrefix = ''.join(formattedPrefix.split('#place'))
b85ec13a 47
f07cfb6b 48 formattedPrefix = formattedPrefix.replace('#owner', owner)
49 formattedPrefix = formattedPrefix.replace('#place', place)
50 formattedPrefix = formattedPrefix.replace('#keyword', keyword)
51 formattedPrefix = formattedPrefix.replace('#me', '@' + c['original_name'])
b85ec13a
LP
52
53 return formattedPrefix