本文整理汇总了Python中session.Session.send_sms方法的典型用法代码示例。如果您正苦于以下问题:Python Session.send_sms方法的具体用法?Python Session.send_sms怎么用?Python Session.send_sms使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类session.Session
的用法示例。
在下文中一共展示了Session.send_sms方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: str
# 需要导入模块: from session import Session [as 别名]
# 或者: from session.Session import send_sms [as 别名]
for phone_number in farmers:
s = Subscription.objects.select_related().filter(phone_number_id=phone_number).order_by('market')
market_id = 0
substring = ''
substrings_list = []
for item in s:
if market_id != item.market_id:
market_id = item.market_id
if substring:
substrings_list.append(substring[:-1])
substring = market_abbr[market_id] + '-'
substring += str(item._crop_cache) + ':' + quotes[market_id][item.crop_id] + ','
substrings_list.append(substring[:-1])
message = '/'.join(substrings_list)
try:
response = session.send_sms(phone_number, message)
if not response['Queued']:
syslog.syslog('Error - Failed to send message to %s. - %s' % (phone_number,response['SMSError']))
sms = SMS(phone_number = Farmer.objects.get(phone_number=phone_number),
message = message,
posttime = timezone.now(),
cdyne_posttime = response['SentDateTime'],
cdyne_sms_id = response['MessageID'],
cancelled = response['Cancelled'],
error = response['SMSError'],
queued = response['Queued'],
sent = response['Sent'])
sms.save()
except Exception, e:
syslog.syslog(str(e))
示例2: send_sms
# 需要导入模块: from session import Session [as 别名]
# 或者: from session.Session import send_sms [as 别名]
def send_sms(phone_number):
m = Market.objects.all()
market_abbr = {}
for item in m:
market_abbr[item.id] = item.abbreviation
f = Farmer.objects.all()
farmers = []
for item in f:
farmers.append(item.phone_number)
q = Quote.objects.filter(date=timezone.now().strftime('%Y-%m-%d')).order_by('market')
if not q:
return False
quotes = {}
market_id = 0
for item in q:
if market_id != item.market_id:
market_id = item.market_id
quotes[market_id] = {}
quotes[market_id][item.crop_id] = str(item.price)
license_key = get_license_key()
session = Session(license_key)
s = Subscription.objects.select_related().filter(phone_number_id=phone_number).order_by('market')
market_id = 0
substring = ''
substrings_list = []
for item in s:
if market_id != item.market_id:
market_id = item.market_id
if substring:
substrings_list.append(substring[:-1])
substring = market_abbr[market_id] + '-'
substring += str(item._crop_cache) + ':' + quotes[market_id][item.crop_id] + ','
substrings_list.append(substring[:-1])
message = '/'.join(substrings_list)
if not message:
return False
try:
response = session.send_sms(phone_number, message)
if not response['Queued']:
syslog.syslog('Error - Failed to send message to %s. - %s' % (phone_number,response['SMSError']))
sms = SMS(phone_number = Farmer.objects.get(phone_number=phone_number),
message = message,
posttime = timezone.now(),
cdyne_posttime = response['SentDateTime'],
cdyne_sms_id = response['MessageID'],
cancelled = response['Cancelled'],
error = response['SMSError'],
queued = response['Queued'],
sent = response['Sent'])
sms.save()
return message
except Exception, e:
syslog.syslog(str(e))
return False