Permalink
Browse files

add parser

  • Loading branch information...
alswl committed Jan 8, 2012
1 parent 901c370 commit 937bf78f545c737df5dd48ca9efc5e53e48b0e60
Showing with 37 additions and 0 deletions.
  1. +37 −0 parser/best_message_storer_parser.py
@@ -0,0 +1,37 @@
+#!/usr/bin/env python
+#coding=utf-8
+
+# desc: Parser
+# author: alswl
+# date: 2011-01-07
+
+import logging
+
+from model.sms import Sms
+from parser import Parser, IllegalFormatError
+
+logger = logging.getLogger(__name__)
+
+class Best_message_storer_parser(Parser):
+ def __init__(self, text):
+ self.text = text
+ self.smses = []
+
+ def parse(self):
+ for block in self.text.split('======================================================================'):
+ try:
+ self.process_block(block)
+ except IllegalFormatError, e:
+ logger.info('%s is not illegal format' %block)
+ continue
+ return self.smses
+
+ def process_block(self, text):
+ sms = Sms()
+ splits = text.split('----------------------------------------------------------------------')
+ if len(splits) != 2:
+ raise IllegalFormatError()
+ meta = splits[0]
+ content = splits[1].strip()
+ logger.debug(content)
+ # self.smses.append(sms)

0 comments on commit 937bf78

Please sign in to comment.