Beispiel #1
0
 def event_loop(self, screen):
     y, x = screen.getmaxyx()
     in_win = screen.subwin(y // 2, x, 0, 0)
     out_win = screen.subwin(y // 2 - 1, x, y // 2 + 1, 0)
     in_box = curses.textpad.Textbox(in_win)
     old_content = []
     new_content = []
     content = []
     while True:
         c = in_win.getch()
         in_box.do_command(c)
         pos = in_win.getyx()
         old_content = content
         new_content = [(word, None) for word in re.split(r'(\s+)', in_box.gather().replace('\n', ' '))]
         content = []
         for (old_word, new_word) in izip_longest(old_content, new_content):
             if new_word is None:
                 pass
             elif (old_word is None) or (old_word[0] != new_word[0]):
                 if not new_word[0]:
                     pass
                 elif re.match('\s+', new_word[0]):
                     content.append((new_word[0], new_word[0]))
                 else:
                     content.append((new_word[0], translate(new_word[0])))
             else:
                 content.append(old_word)
         out_win.clear()
         out_win.addstr(0, 0, ''.join(t for (w, t) in content))
         in_win.move(*pos)
         out_win.refresh()
Beispiel #2
0
 def do_translate(self, req):
     # Check the request has the required parameters
     if not 'msg_id' in req.params:
         raise exc.HTTPBadRequest('Missing msg_id parameter')
     if not 'from' in req.params:
         raise exc.HTTPBadRequest('Missing from parameter')
     if not 'content' in req.params:
         raise exc.HTTPBadRequest('Missing content parameter')
     msg_id = req.params['msg_id']
     recipient = req.params['from']
     sender = req.params['to']
     content = req.params['content']
     # If we've seen the message before it's a duplicate. Return 200 OK so
     # the server doesn't keep retrying but otherwise ignore it
     if msg_id in self.messages:
         raise exc.HTTPOk('Message already processed')
     self.messages.add(msg_id)
     self.sms.send(sender, recipient, translator.translate(content, manc))
     raise exc.HTTPOk('Message processed')
Beispiel #3
0
 def main(self, args):
     translate('')
     curses.wrapper(self.event_loop)
Beispiel #4
0
 def send(self, content):
     self.sms.send(
         self.sender, self.recipient,
         translator.translate(content, self.dialect))