Skip to content

Instantly share code, notes, and snippets.

@amackera
Created March 29, 2012 16:40
Show Gist options
  • Save amackera/2239640 to your computer and use it in GitHub Desktop.
Save amackera/2239640 to your computer and use it in GitHub Desktop.
get_outgoing_number
def get_outgoing_number(provider, incoming_number):
'''
Returns the outgoing number associated with this incoming number.
'''
def get_sms_settings():
# Memcached closure returns outgoing number for this student
try:
settings = SmsSettings.objects.get(phone_number = incoming_number)
except SmsSettings.DoesNotExist:
# Create settings record for this number
outgoing_number = get_provider_outgoing_number(provider)
safe_call_task(tq_save_sms_settings,
[incoming_number, outgoing_number])
return outgoing_number
if settings.sms_reply_number == None:
# Settings exist but no sms_reply_number has been set. Set it
outgoing_number = get_provider_outgoing_number(provider)
safe_call_task(tq_save_sms_settings,
[incoming_number, outgoing_number])
return outgoing_number
else:
return settings.sms_reply_number
number = get_object_through_memcache("sms_reply_number_%s" %incoming_number,
get_sms_settings,
timeout = 120)
if number:
# settings exist, and outgoing number exists for setting
return number
else:
# Something bad happened...
return False
@amackera
Copy link
Author

A good improvement, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment