当前位置: 首页>>代码示例>>Python>>正文


Python settings.TWITTER_CONSUMER_SECRET属性代码示例

本文整理汇总了Python中django.conf.settings.TWITTER_CONSUMER_SECRET属性的典型用法代码示例。如果您正苦于以下问题:Python settings.TWITTER_CONSUMER_SECRET属性的具体用法?Python settings.TWITTER_CONSUMER_SECRET怎么用?Python settings.TWITTER_CONSUMER_SECRET使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在django.conf.settings的用法示例。


在下文中一共展示了settings.TWITTER_CONSUMER_SECRET属性的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: handle

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import TWITTER_CONSUMER_SECRET [as 别名]
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() 
开发者ID:owocki,项目名称:pytrader,代码行数:25,代码来源:pull_twitter.py

示例2: is_configured

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import TWITTER_CONSUMER_SECRET [as 别名]
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'),
        ]) 
开发者ID:Gandi,项目名称:baobab,代码行数:11,代码来源:twitter.py

示例3: __init__

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import TWITTER_CONSUMER_SECRET [as 别名]
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) 
开发者ID:Gandi,项目名称:baobab,代码行数:11,代码来源:twitter.py

示例4: get_tweepy_api

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import TWITTER_CONSUMER_SECRET [as 别名]
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) 
开发者ID:City-of-Helsinki,项目名称:digihel,代码行数:16,代码来源:twitter_tags.py

示例5: fetch_tweet_data

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import TWITTER_CONSUMER_SECRET [as 别名]
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 
开发者ID:zulip,项目名称:zulip,代码行数:60,代码来源:__init__.py


注:本文中的django.conf.settings.TWITTER_CONSUMER_SECRET属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。