Python django.conf.settings.TWITTER_CONSUMER_SECRET Examples

The following are 5 code examples for showing how to use django.conf.settings.TWITTER_CONSUMER_SECRET(). These examples are extracted from open source projects. 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 check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module django.conf.settings , or try the search function .

Example 1
Project: pytrader   Author: owocki   File: pull_twitter.py    License: MIT License 6 votes vote down vote up
def handle(self, *args, **options):

        api = twitter.Api(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)

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

                if SocialNetworkMention.objects.filter(network_name='twitter', network_id=tweet.id).count() == 0:
                    snm = SocialNetworkMention.objects.create(
                        network_name='twitter',
                        network_id=tweet.id,
                        network_username=tweet.user.screen_name,
                        network_created_on=datetime.datetime.fromtimestamp(tweet.GetCreatedAtInSeconds()),
                        text=tweet.text,
                        symbol=currency_symbol,
                    )
                    snm.set_sentiment()
                    snm.save() 
Example 2
Project: baobab   Author: Gandi   File: twitter.py    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
Project: baobab   Author: Gandi   File: twitter.py    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,
                                      settings.TWITTER_CONSUMER_SECRET,
                                      settings.TWITTER_ACCESS_TOKEN,
                                      settings.TWITTER_ACCESS_TOKEN_SECRET) 
Example 4
Project: digihel   Author: City-of-Helsinki   File: twitter_tags.py    License: MIT License 5 votes vote down vote up
def get_tweepy_api():
    try:
        auth = tweepy.OAuthHandler(
            consumer_key=settings.TWITTER_CONSUMER_KEY,
            consumer_secret=settings.TWITTER_CONSUMER_SECRET,
        )
        auth.set_access_token(
            key=settings.TWITTER_ACCESS_TOKEN,
            secret=settings.TWITTER_ACCESS_TOKEN_SECRET,
        )
    except AttributeError:
        print('No Twitter tokens found in settings')
        return None
    return tweepy.API(auth) 
Example 5
Project: zulip   Author: zulip   File: __init__.py    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)
    else:
        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 `manage.py` commands.
        import twitter

        try:
            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 https://github.com/zulip/zulip/issues/86')
            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)
            raise
        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.
                raise
            else:
                # 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