<commit_before>#!/usr/bin/env python
# vim: ai ts=4 sts=4 et sw=4

import rapidsms
from rapidsms.message import Message

# a pointless app to demonstrate the structure
# of sms applications without magic decorators
class App(rapidsms.app.App):

    def start(self):
        self.name = 'sms2irc'
                  
    def parse(self, message):
        # TODO move backend lookup into start() once load order is finalized
        self.backends = self.router.backends

        for backend in self.backends:
            print unicode(type(backend).__name__)
            if unicode(type(backend).__name__) == unicode('Irc'):
                self.irc_backend = backend
            
    def handle(self, message):
        self.forward(message)

    def outgoing(self, message):
        #self.forward(message)
        pass
        
    def forward(self, message):
        self.info("%s(%s): '%s' forwarded to %s" % (message.caller, message.backend.name, message.text, self.irc_backend.channels))
        txt = "(%s) says '%s'" % (message.backend.name, message.text)
        Message(self.irc_backend, message.caller, txt).send()<commit_msg>reworked sms2irc now that router is loading apps after backends<commit_after>#!/usr/bin/env python
# vim: ai ts=4 sts=4 et sw=4

import rapidsms
from rapidsms.message import Message

# a pointless app to demonstrate the structure
# of sms applications without magic decorators
class App(rapidsms.app.App):

    def start(self):
        self.name = 'sms2irc'
        self.irc_backend = None
        print self.router.backends
        for backend in self.router.backends:
            if backend.type == 'IRC':
                self.irc_backend = backend
                  
    def parse(self, message):
        pass
            
    def handle(self, message):
        if self.irc_backend is not None:
            self.forward(message)

    def outgoing(self, message):
        #self.forward(message)
        pass
        
    def forward(self, message):
        self.info("%s(%s): '%s' forwarded to %s" % (message.caller, message.backend.name, message.text, self.irc_backend.channels))
        txt = "(%s) says '%s'" % (message.backend.name, message.text)
        Message(self.irc_backend, message.caller, txt).send()

{'fraction_non_alphanumeric': 0.11076512455516015, 'fraction_numerical': 0.00400355871886121, 'mean_word_length': 2.4976671850699845, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3896429', 'n_tokens_mistral': 685, 'n_tokens_neox': 652, 'n_words': 183}