Skip to content

Instantly share code, notes, and snippets.

@iwillig
Created December 9, 2010 15:03
Show Gist options
  • Select an option

  • Save iwillig/734792 to your computer and use it in GitHub Desktop.

Select an option

Save iwillig/734792 to your computer and use it in GitHub Desktop.
import re
from collections import namedtuple
from dispatch import consumer
class Message(object):
"""
"""
def __init__(self,text ):
"""
"""
self.text = text
msg = Message(text="bal.12324")
match = namedtuple('Match','matcher module function langauge')
matchers = [
match('^bal','dispatch.consumer','get_balance','en'),
match('^solde','dispatch.consumer','get_balance','fr'),
match('^prim','dispatch.consumer','set_primary_number','en'),
match('^tel','dispatch.consumer','get_primary_number','fr'),
match('^add','dispatch.consumer','add_credit','en'),
match('^recharge','dispatch.consumer','add_credit','fr'),
match('^on','dispatch.consumer','turn_circuit_on','fr'),
match('^off','dispatch.consumer','turn_circuit_off','fr'),
]
def match_message(message):
for match in matchers:
if re.match(match.matcher,message.text):
module = getattr(__import__(match.module.split(".")[0]),
match.module.split(".")[1])
getattr(module, match.function)(message)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment