Skip to content

Commit

Permalink
add action: update sms
Browse files Browse the repository at this point in the history
  • Loading branch information
alswl committed Jan 24, 2012
1 parent 59152c5 commit dc709d8
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
Empty file added action/__init__.py
Empty file.
34 changes: 34 additions & 0 deletions 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()
6 changes: 6 additions & 0 deletions smsir.py
Expand Up @@ -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__)

Expand All @@ -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',
Expand All @@ -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(
Expand Down

0 comments on commit dc709d8

Please sign in to comment.