Commit | Line | Data |
---|---|---|
5531923e LP |
1 | import json |
2 | ||
3 | from twitter.util import printNicely | |
8daad13d | 4 | from .colors import * |
b85ec13a | 5 | from .config import * |
5531923e LP |
6 | |
7 | ||
9e38891f | 8 | def 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'))) | |
05370a11 | 16 | except: |
5b5f261a | 17 | printNicely(yellow(data)) |
b85ec13a LP |
18 | |
19 | ||
063f6bb1 | 20 | def 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 | |
05370a11 MG |
50 | |
51 | ||
52 | def 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 |