本文整理匯總了Python中django.conf.settings.TWITTER_CONSUMER_KEY屬性的典型用法代碼示例。如果您正苦於以下問題:Python settings.TWITTER_CONSUMER_KEY屬性的具體用法?Python settings.TWITTER_CONSUMER_KEY怎麽用?Python settings.TWITTER_CONSUMER_KEY使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類django.conf.settings
的用法示例。
在下文中一共展示了settings.TWITTER_CONSUMER_KEY屬性的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: handle
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import TWITTER_CONSUMER_KEY [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()
示例2: is_configured
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import TWITTER_CONSUMER_KEY [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'),
])
示例3: __init__
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import TWITTER_CONSUMER_KEY [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)
示例4: get_tweepy_api
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import TWITTER_CONSUMER_KEY [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)
示例5: fetch_tweet_data
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import TWITTER_CONSUMER_KEY [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