Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

refatory struct

  • Loading branch information...
commit 436cbf790fd8d801da0987af196e1f70ee9d9efd 1 parent d8f2153
@alswl authored
View
17 README.asciidoc
@@ -0,0 +1,17 @@
+== SMSIR ==
+
+Smsir is a console helper to manage message backups.
+
+== Install ==
+
+Require:
+
+* Python2.x
+* Sqlalchemy
+* pyyaml
+
+== Usage ==
+
+// TODO
+
+// vim: set ft=asciidoc:
View
18 config.yml
@@ -0,0 +1,18 @@
+version: 1
+formatters:
+ simple:
+ format: '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
+handlers:
+ console:
+ class: logging.StreamHandler
+ level: DEBUG
+ formatter: simple
+ stream: ext://sys.stdout
+loggers:
+ simple:
+ level: DEBUG
+root:
+ level: DEBUG
+ handlers: [console]
+
+# vim: set ft=yaml:
View
0  data/__init__.py
No changes.
View
0  model/__init__.py
No changes.
View
3  contact.py → model/contact.py
@@ -12,8 +12,7 @@ class Contact(Base):
id = Column(Integer, primary_key=True)
name = Column(Unicode(50), nullable=False)
-
- #sms = relationship("Sms", order_by='Sms.id', backref='contact')
+ phone = Column(Integer(20), nullable=False)
def __init__(self, name):
self.name = name
View
7 meta.py → model/meta.py
@@ -1,12 +1,13 @@
# coding=utf8
+import logging
+import logging.config
+import yaml
+
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import scoped_session, sessionmaker
from sqlalchemy import create_engine
-__all__ = ['Base', 'Session']
-
-#engine = create_engine('sqlite:///:memory:', echo=True)
engine = create_engine('sqlite:///data.db', echo=True)
# SQLAlchemy session manager. Updated by model.init_model()
View
0  phone.py → model/phone.py
File renamed without changes
View
2  sms.py → model/sms.py
@@ -14,6 +14,8 @@ class Sms(Base):
id = Column(Integer, primary_key=True)
from_contact_id = Column(Integer, ForeignKey('contact.id'))
from_contact = relationship('Contact', backref='sms')
+ #to_contact_id = Column(Integer, ForeignKey('contact.id'))
+ #to_contact = relationship('Contact', backref='sms')
content = Column(String(500))
# TODO create_at
View
0  parser/__init__.py
No changes.
View
20 parser/parser.py
@@ -0,0 +1,20 @@
+#!/usr/bin/env python
+#coding=utf-8
+
+# desc: Parser
+# author: alswl
+# date: 2011-01-07
+
+from sms import Sms
+
+class TextParser(object):
+ def __init__(self):
+ pass
+
+ def parse(self, text):
+ sms = Sms()
+ for block in text.split('================================' \
+ '======================================'):
+ print line
+
+ pass
View
16 parser/textparser.py
@@ -0,0 +1,16 @@
+#!/usr/bin/env python
+#coding=utf-8
+
+# desc: Parser
+# author: alswl
+# date: 2011-01-07
+
+from model.sms import Sms
+
+def parse(text):
+ sms = Sms()
+ for block in text.split('================================' \
+ '======================================'):
+ print block
+
+ pass
View
74 smsir.py
@@ -1,19 +1,64 @@
#!/usr/bin/env python
# coding=utf8
+import argparse
+import logging
-from meta import session, Base
-from sms import Sms
-from contact import Contact
+from sqlalchemy.orm import scoped_session, sessionmaker
+from sqlalchemy import create_engine
+import yaml
+
+from model.meta import Base, session, engine
+from model.sms import Sms
+from model.contact import Contact
+import parser.textparser
+
+logger = logging.getLogger(__name__)
class Smsir(object):
"""A sms helper"""
- def __init__(self, session, Base):
- self.session = session
+ def __init__(self):
self.Base = Base
+ self.session = session
+ self.engine = engine
+
+ # Loging
+ config = yaml.load(open('config.yml', 'r'))
+ logging.config.dictConfig(config)
+
+ def run(self):
+ parser = argparse.ArgumentParser(
+ description='a sms console helper to manage sms'
+ )
+ parser.add_argument('--create', '-c',
+ action='store_true',
+ help='create a new database')
+ parser.add_argument('--list-messages', '-l',
+ action='store_true',
+ help='list all messages')
+ parser.add_argument('--import-sms-backup-restore', '-b',
+ type=argparse.FileType('r'),
+ metavar='FILE',
+ help='import messages from SMS Backup & Restore')
+ parser.add_argument('--import-best-message-storer', '-B',
+ type=argparse.FileType('r'),
+ metavar='FILE',
+ help='import messages from Best MessageStorer backups')
+ args = parser.parse_args()
+
+ if args.create:
+ self.create_all()
+ elif args.list_messages:
+ self.list_messages()
+ elif args.import_sms_backup_restore != None:
+ self.import_sms_backup_restore(args.import_sms_backup_restore.read())
+ elif args.import_best_message_storer != None:
+ self.import_best_message_storer(args.import_best_message_storer.read())
+ else:
+ parser.print_help()
def create_all(self):
- Base.metadata.create_all()
+ self.Base.metadata.create_all(self.engine)
def import_from_xml(self):
pass
@@ -21,7 +66,24 @@ def import_from_xml(self):
def import_from_txt(self):
pass
+ def list_messages(self):
+ print 'messages'
+ pass
+
+ def import_sms_backup_restore(self, texts):
+ pass
+
+ def import_best_message_storer(self, texts):
+ textparser.parse(texts)
+
def test(self):
sms = Sms()
sms.from_contact = Contact(u'路飞')
sms.add()
+
+def main():
+ smsir = Smsir()
+ smsir.run()
+
+if __name__ == '__main__':
+ main()
Please sign in to comment.
Something went wrong with that request. Please try again.