requirements for repeatable install
[rainbowstream.git] / rainbowstream / util.py
... / ...
CommitLineData
1import json
2
3from twitter.util import printNicely
4from .colors import *
5from .config import *
6
7
8def 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
20def 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
50
51
52def add_tweetmode_parameter(kwargs):
53 """
54 Add support for extended mode to Twitter API calls unless explicitly stated in config
55 """
56 if not c.get('DISABLE_EXTENDED_TWEETS'):
57 kwargs['tweet_mode'] = 'extended'
58 return kwargs