X-Git-Url: https://vcs.fsf.org/?p=rainbowstream.git;a=blobdiff_plain;f=rainbowstream%2Futil.py;h=a1a2a446123cd09c5ad08d9bc3aaa8b7b96b3810;hp=a3cd1272ad495d8fc8e2b8ece0bae06bdd9f09ec;hb=644dfe37a97bd19e9178d9fbaa9b888e2eea0a55;hpb=9e38891f4376bbe71f9e10d267fa5721e6e69194 diff --git a/rainbowstream/util.py b/rainbowstream/util.py index a3cd127..a1a2a44 100644 --- a/rainbowstream/util.py +++ b/rainbowstream/util.py @@ -2,17 +2,57 @@ import json from twitter.util import printNicely from .colors import * +from .config import * def detail_twitter_error(twitterException): """ Display Twitter Errors nicely """ + data = twitterException.response_data try: - loadedJson = json.loads(twitterException.response_data) - for m in loadedJson.get('errors', dict()): - info = "Error " + str(m.get('code')) + ": " + m.get('message') - printNicely(yellow(info)) - except ValueError: - info = "Error: " + twitterException.response_data - printNicely(yellow(info)) + for m in data.get('errors', dict()): + printNicely(yellow(m.get('message'))) + except: + printNicely(yellow(data)) + + +def format_prefix(listname='', keyword=''): + """ + Format the custom prefix + """ + formattedPrefix = c['PREFIX'] + owner = '@' + c['original_name'] + place = '' + # Public stream + if keyword: + formattedPrefix = ''.join(formattedPrefix.split('#owner')) + formattedPrefix = ''.join(formattedPrefix.split('#place')) + formattedPrefix = ''.join(formattedPrefix.split('#me')) + # List stream + elif listname: + formattedPrefix = ''.join(formattedPrefix.split('#keyword')) + formattedPrefix = ''.join(formattedPrefix.split('#me')) + owner, place = listname.split('/') + place = '/' + place + # Personal stream + else: + formattedPrefix = ''.join(formattedPrefix.split('#keyword')) + formattedPrefix = ''.join(formattedPrefix.split('#owner')) + formattedPrefix = ''.join(formattedPrefix.split('#place')) + + formattedPrefix = formattedPrefix.replace('#owner', owner) + formattedPrefix = formattedPrefix.replace('#place', place) + formattedPrefix = formattedPrefix.replace('#keyword', keyword) + formattedPrefix = formattedPrefix.replace('#me', '@' + c['original_name']) + + return formattedPrefix + + +def add_tweetmode_parameter(kwargs): + """ + Add support for extended mode to Twitter API calls unless explicitly stated in config + """ + if not c.get('DISABLE_EXTENDED_TWEETS'): + kwargs['tweet_mode'] = 'extended' + return kwargs