Skip to content
Browse files

add action: update sms

  • Loading branch information...
1 parent 59152c5 commit dc709d8d5880cf1b6b96fdf3917e8ce2318ee652 @alswl committed Jan 24, 2012
Showing with 40 additions and 0 deletions.
  1. 0 action/__init__.py
  2. +34 −0 action/update_sms.py
  3. +6 −0 smsir.py
View
0 action/__init__.py
No changes.
View
34 action/update_sms.py
@@ -0,0 +1,34 @@
+#!/usr/bin/env python
+#coding=utf-8
+
+# desc: 更新短信联系人为空的短信
+# author: alswl
+# date: 2011-01-22
+
+from sqlalchemy import and_
+
+from model.sms import Sms
+from config import Base, session, engine
+
+def update_sms():
+ """更新短信联系人为空的短信"""
+ number_rows = session.execute("""
+select distinct number, phone_id, contact_id
+from sms
+where contact_id is null;""")
+ for row in number_rows.fetchall():
+ number = row['number']
+ sms = session.query(Sms).filter(
+ and_(Sms.number.like('%' + number), Sms.contact_id != None)
+ ).first()
+ if sms is not None:
+ session.execute(
+ """
+update sms
+set contact_id = :contact_id, phone_id = :phone_id
+where number =:number;""",
+ {'contact_id': sms.contact_id,
+ 'phone_id': sms.phone_id,
+ 'number': sms.number}
+ )
+ session.commit()
View
6 smsir.py
@@ -12,6 +12,7 @@
from model.contact import Contact
from parser.best_message_storer_parser import Best_message_storer_parser
from parser.sms_backup_and_restore_parser import SmsBackupAndRestoreParser
+from action.update_sms import update_sms
logger = logging.getLogger(__name__)
@@ -33,6 +34,9 @@ def run(self):
parser.add_argument('--list-messages', '-l',
action='store_true',
help='list all messages')
+ parser.add_argument('--update-contact', '-u',
+ action='store_true',
+ help='update sms that contact is none')
parser.add_argument('--import-best-message-storer', '-B',
type=argparse.FileType('r'),
metavar='FILE',
@@ -49,6 +53,8 @@ def run(self):
self.create_all()
elif args.list_messages:
self.list_messages()
+ elif args.update_contact:
+ update_sms()
elif args.import_best_message_storer != None:
for text in args.import_best_message_storer:
best_message_storer_parser = Best_message_storer_parser(

0 comments on commit dc709d8

Please sign in to comment.
Something went wrong with that request. Please try again.