Python django.conf.settings.TWITTER_CONSUMER_SECRET Examples

The following are 5 code examples of django.conf.settings.TWITTER_CONSUMER_SECRET(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module django.conf.settings , or try the search function .
Example #1
Source Project: pytrader   Author: owocki   File:    License: MIT License 6 votes vote down vote up
def handle(self, *args, **options):

        api = twitter.Api(consumer_key=settings.TWITTER_CONSUMER_KEY,

        for currency_symbol in settings.SOCIAL_NETWORK_SENTIMENT_CONFIG['twitter']:
            results = api.GetSearch("$" + currency_symbol, count=200)
            for tweet in results:

                if SocialNetworkMention.objects.filter(network_name='twitter', == 0:
                    snm = SocialNetworkMention.objects.create(
Example #2
Source Project: baobab   Author: Gandi   File:    License: GNU General Public License v3.0 5 votes vote down vote up
def is_configured(cls):
        return all([
            hasattr(settings, 'TWITTER_CONSUMER_KEY'),
            hasattr(settings, 'TWITTER_CONSUMER_SECRET'),
            hasattr(settings, 'TWITTER_ACCESS_TOKEN'),
            hasattr(settings, 'TWITTER_ACCESS_TOKEN_SECRET'),
            hasattr(settings, 'TWITTER_URL_API'),
            hasattr(settings, 'TWITTER_ALLOWED_CHAR'),
Example #3
Source Project: baobab   Author: Gandi   File:    License: GNU General Public License v3.0 5 votes vote down vote up
def __init__(self):
        if not self.is_configured():
            raise RuntimeError('Twitter is not configured')
        if not self.url_api:
            self.url_api = settings.TWITTER_URL_API.rstrip('/')
        super(Twitter, self).__init__(settings.TWITTER_CONSUMER_KEY,
Example #4
Source Project: digihel   Author: City-of-Helsinki   File:    License: MIT License 5 votes vote down vote up
def get_tweepy_api():
        auth = tweepy.OAuthHandler(
    except AttributeError:
        print('No Twitter tokens found in settings')
        return None
    return tweepy.API(auth) 
Example #5
Source Project: zulip   Author: zulip   File:    License: Apache License 2.0 4 votes vote down vote up
def fetch_tweet_data(tweet_id: str) -> Optional[Dict[str, Any]]:
    if settings.TEST_SUITE:
        from . import testing_mocks
        res = testing_mocks.twitter(tweet_id)
        creds = {
            'consumer_key': settings.TWITTER_CONSUMER_KEY,
            'consumer_secret': settings.TWITTER_CONSUMER_SECRET,
            'access_token_key': settings.TWITTER_ACCESS_TOKEN_KEY,
            'access_token_secret': settings.TWITTER_ACCESS_TOKEN_SECRET,
        if not all(creds.values()):
            return None

        # We lazily import twitter here because its import process is
        # surprisingly slow, and doing so has a significant impact on
        # the startup performance of `` commands.
        import twitter

            api = twitter.Api(tweet_mode='extended', **creds)
            # Sometimes Twitter hangs on responses.  Timing out here
            # will cause the Tweet to go through as-is with no inline
            # preview, rather than having the message be rejected
            # entirely. This timeout needs to be less than our overall
            # formatting timeout.
            tweet = timeout(3, api.GetStatus, tweet_id)
            res = tweet.AsDict()
        except AttributeError:
            markdown_logger.error('Unable to load twitter api, you may have the wrong '
                                  'library installed, see')
            return None
        except TimeoutExpired:
            # We'd like to try again later and not cache the bad result,
            # so we need to re-raise the exception (just as though
            # we were being rate-limited)
        except twitter.TwitterError as e:
            t = e.args[0]
            if len(t) == 1 and ('code' in t[0]) and (t[0]['code'] == 34):
                # Code 34 means that the message doesn't exist; return
                # None so that we will cache the error
                return None
            elif len(t) == 1 and ('code' in t[0]) and (t[0]['code'] == 88 or
                                                       t[0]['code'] == 130):
                # Code 88 means that we were rate-limited and 130
                # means Twitter is having capacity issues; either way
                # just raise the error so we don't cache None and will
                # try again later.
                # It's not clear what to do in cases of other errors,
                # but for now it seems reasonable to log at error
                # level (so that we get notified), but then cache the
                # failure to proceed with our usual work
                markdown_logger.exception("Unknown error fetching tweet data")
                return None
    return res