本文整理汇总了Python中boto.ses.SESConnection.get_send_quota方法的典型用法代码示例。如果您正苦于以下问题:Python SESConnection.get_send_quota方法的具体用法?Python SESConnection.get_send_quota怎么用?Python SESConnection.get_send_quota使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boto.ses.SESConnection
的用法示例。
在下文中一共展示了SESConnection.get_send_quota方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: dashboard
# 需要导入模块: from boto.ses import SESConnection [as 别名]
# 或者: from boto.ses.SESConnection import get_send_quota [as 别名]
def dashboard(request):
"""
Graph SES send statistics over time.
"""
cache_key = 'vhash:django_ses_stats'
cached_view = cache.get(cache_key)
if cached_view:
return cached_view
region = RegionInfo(
name=getattr(settings, 'AWS_SES_REGION_NAME',
SESConnection.DefaultRegionName),
endpoint=getattr(settings, 'AWS_SES_REGION_ENDPOINT',
SESConnection.DefaultRegionEndpoint))
ses_conn = SESConnection(
aws_access_key_id=getattr(settings, 'AWS_ACCESS_KEY_ID', None),
aws_secret_access_key=getattr(settings, 'AWS_SECRET_ACCESS_KEY', None),
region=region)
quota_dict = ses_conn.get_send_quota()
verified_emails_dict = ses_conn.list_verified_email_addresses()
stats = ses_conn.get_send_statistics()
quota = quota_parse(quota_dict)
verified_emails = emails_parse(verified_emails_dict)
ordered_data = stats_to_list(stats)
summary = sum_stats(ordered_data)
extra_context = {
'title': 'SES Statistics',
'datapoints': ordered_data,
'24hour_quota': quota['Max24HourSend'],
'24hour_sent': quota['SentLast24Hours'],
'24hour_remaining': float(quota['Max24HourSend']) -
float(quota['SentLast24Hours']),
'persecond_rate': quota['MaxSendRate'],
'verified_emails': verified_emails,
'summary': summary,
'access_key': ses_conn.gs_access_key_id,
'local_time': True if pytz else False,
}
response = render_to_response(
'django_ses/send_stats.html',
extra_context,
context_instance=RequestContext(request))
cache.set(cache_key, response, 60 * 15) # Cache for 15 minutes
return response
示例2: dashboard
# 需要导入模块: from boto.ses import SESConnection [as 别名]
# 或者: from boto.ses.SESConnection import get_send_quota [as 别名]
def dashboard(request):
"""
Graph SES send statistics over time.
"""
cache_key = 'vhash:django_ses_stats'
cached_view = cache.get(cache_key)
if cached_view:
return cached_view
region = RegionInfo(
name=settings.AWS_SES_REGION_NAME,
endpoint=settings.AWS_SES_REGION_ENDPOINT)
ses_conn = SESConnection(
aws_access_key_id=settings.ACCESS_KEY,
aws_secret_access_key=settings.SECRET_KEY,
region=region,
proxy=settings.AWS_SES_PROXY,
proxy_port=settings.AWS_SES_PROXY_PORT,
)
quota_dict = ses_conn.get_send_quota()
verified_emails_dict = ses_conn.list_verified_email_addresses()
stats = ses_conn.get_send_statistics()
quota = quota_parse(quota_dict)
verified_emails = emails_parse(verified_emails_dict)
ordered_data = stats_to_list(stats)
summary = sum_stats(ordered_data)
extra_context = {
'title': 'SES Statistics',
'datapoints': ordered_data,
'24hour_quota': quota['Max24HourSend'],
'24hour_sent': quota['SentLast24Hours'],
'24hour_remaining': float(quota['Max24HourSend']) -
float(quota['SentLast24Hours']),
'persecond_rate': quota['MaxSendRate'],
'verified_emails': verified_emails,
'summary': summary,
'access_key': ses_conn.gs_access_key_id,
'local_time': True,
}
response = render(request, 'django_ses/send_stats.html', extra_context)
cache.set(cache_key, response, 60 * 15) # Cache for 15 minutes
return response
示例3: dashboard
# 需要导入模块: from boto.ses import SESConnection [as 别名]
# 或者: from boto.ses.SESConnection import get_send_quota [as 别名]
def dashboard(request):
"""
Graph SES send statistics over time.
"""
cache_key = "vhash:django_ses_stats"
cached_view = cache.get(cache_key)
if cached_view:
return cached_view
region = RegionInfo(name=settings.AWS_SES_REGION_NAME, endpoint=settings.AWS_SES_REGION_ENDPOINT)
ses_conn = SESConnection(
aws_access_key_id=settings.ACCESS_KEY,
aws_secret_access_key=settings.SECRET_KEY,
region=region,
boto_profile_name=settings.BOTO_PROFILE_NAME,
)
quota_dict = ses_conn.get_send_quota()
verified_emails_dict = ses_conn.list_verified_email_addresses()
stats = ses_conn.get_send_statistics()
quota = quota_parse(quota_dict)
verified_emails = emails_parse(verified_emails_dict)
ordered_data = stats_to_list(stats)
summary = sum_stats(ordered_data)
extra_context = {
"title": "SES Statistics",
"datapoints": ordered_data,
"24hour_quota": quota["Max24HourSend"],
"24hour_sent": quota["SentLast24Hours"],
"24hour_remaining": float(quota["Max24HourSend"]) - float(quota["SentLast24Hours"]),
"persecond_rate": quota["MaxSendRate"],
"verified_emails": verified_emails,
"summary": summary,
"access_key": ses_conn.gs_access_key_id,
"local_time": True if pytz else False,
}
response = render_to_response("django_ses/send_stats.html", extra_context, context_instance=RequestContext(request))
cache.set(cache_key, response, 60 * 15) # Cache for 15 minutes
return response
示例4: SESBackend
# 需要导入模块: from boto.ses import SESConnection [as 别名]
# 或者: from boto.ses.SESConnection import get_send_quota [as 别名]
#.........这里部分代码省略.........
# Failed silently
return
num_sent = 0
source = settings.AWS_SES_RETURN_PATH
for message in email_messages:
# Automatic throttling. Assumes that this is the only SES client
# currently operating. The AWS_SES_AUTO_THROTTLE setting is a
# factor to apply to the rate limit, with a default of 0.5 to stay
# well below the actual SES throttle.
# Set the setting to 0 or None to disable throttling.
if self._throttle:
global recent_send_times
now = datetime.now()
# Get and cache the current SES max-per-second rate limit
# returned by the SES API.
rate_limit = self.get_rate_limit()
# Prune from recent_send_times anything more than a few seconds
# ago. Even though SES reports a maximum per-second, the way
# they enforce the limit may not be on a one-second window.
# To be safe, we use a two-second window (but allow 2 times the
# rate limit) and then also have a default rate limit factor of
# 0.5 so that we really limit the one-second amount in two
# seconds.
window = 2.0 # seconds
window_start = now - timedelta(seconds=window)
new_send_times = []
for time in recent_send_times:
if time > window_start:
new_send_times.append(time)
recent_send_times = new_send_times
# If the number of recent send times in the last 1/_throttle
# seconds exceeds the rate limit, add a delay.
# Since I'm not sure how Amazon determines at exactly what
# point to throttle, better be safe than sorry and let in, say,
# half of the allowed rate.
if len(new_send_times) > rate_limit * window * self._throttle:
# Sleep the remainder of the window period.
delta = now - new_send_times[0]
total_seconds = (delta.microseconds + (delta.seconds +
delta.days * 24 * 3600) * 10**6) / 10**6
delay = window - total_seconds
if delay > 0:
sleep(delay)
recent_send_times.append(now)
# end of throttling
try:
response = self.connection.send_raw_email(
source=source or message.from_email,
destinations=message.recipients(),
raw_message=dkim_sign(message.message().as_string(),
dkim_key=self.dkim_key,
dkim_domain=self.dkim_domain,
dkim_selector=self.dkim_selector,
dkim_headers=self.dkim_headers)
)
message.extra_headers['status'] = 200
message.extra_headers['message_id'] = response[
'SendRawEmailResponse']['SendRawEmailResult']['MessageId']
message.extra_headers['request_id'] = response[
'SendRawEmailResponse']['ResponseMetadata']['RequestId']
num_sent += 1
except SESConnection.ResponseError as err:
# Store failure information so to post process it if required
error_keys = ['status', 'reason', 'body', 'request_id',
'error_code', 'error_message']
for key in error_keys:
message.extra_headers[key] = getattr(err, key, None)
if not self.fail_silently:
raise
if new_conn_created:
self.close()
return num_sent
def get_rate_limit(self):
if self._access_key_id in cached_rate_limits:
return cached_rate_limits[self._access_key_id]
new_conn_created = self.open()
if not self.connection:
raise Exception(
"No connection is available to check current SES rate limit.")
try:
quota_dict = self.connection.get_send_quota()
max_per_second = quota_dict['GetSendQuotaResponse'][
'GetSendQuotaResult']['MaxSendRate']
ret = float(max_per_second)
cached_rate_limits[self._access_key_id] = ret
return ret
finally:
if new_conn_created:
self.close()