Permalink
Browse files

add command to remove numbers, close #11

  • Loading branch information...
1 parent e751c5b commit 0d408a7146f48f8569176f15c838727052eee021 oau committed Oct 17, 2012
Showing with 25 additions and 6 deletions.
  1. +6 −6 core.py
  2. +19 −0 smskrupp
View
12 core.py
@@ -124,20 +124,20 @@ def get_group_members(self, group_id):
return [{'id':row[0], 'number':row[1], 'alias':row[2], 'sender':(row[3]==1),
'admin':(row[4]==1)} for row in c]
- def get_groups(self, phone=None, sender=None):
- ''' returns array of dicts describing groups (id, name keyword, phone)
+ def get_groups(self, phone=None, number=None):
+ ''' returns array of dicts describing groups (id, name keyword, phone) containing number
'''
c = self.cursor
- if phone and sender:
+ if phone and number:
c.execute('select g.id, g.name, g.keyword, g.phone from qq_groupMembers m '
+'join qq_groups g on g.id = m.groupId '
+'where m.number=? and g.phone=? order by g.name asc',
- (sender,phone))
- elif sender:
+ (number,phone))
+ elif number:
c.execute('select g.id, g.name, g.keyword, g.phone from qq_groupMembers m '
+'join qq_groups g on g.id = m.groupId '
+'where m.number=? order by g.name asc',
- (sender,))
+ (number,))
elif phone:
c.execute('select id,name, keyword, phone from qq_groups where phone=? order by name asc',
(phone,))
View
@@ -9,6 +9,7 @@ def usage():
print("%s list-groups"%sys.argv[0])
print("%s list-members <group>"%sys.argv[0])
print("%s add-member <number> <alias> <group>"%sys.argv[0])
+ print("%s rm-member <number> <group|ALL>"%sys.argv[0])
print("%s set-sender <number> <group>"%sys.argv[0])
print("%s set-admin <number> <group>"%sys.argv[0])
print("%s fake-incoming <src> <phone> <msg>"%sys.argv[0])
@@ -57,6 +58,24 @@ elif sys.argv[1] == 'add-member':
mid = data.add_number(number, alias, group_id)
if mid == None:
print "error: alias already exists"
+elif sys.argv[1] == 'rm-member':
+ if len(sys.argv) != 4:
+ usage()
+ number,group = sys.argv[2:]
+ number = core.normalize_number(number)
+ if not number:
+ print "number error!"
+ sys.exit(1)
+ if group == "ALL":
+ for g in data.get_groups(number=number):
+ data.remove_number(number=number, group_id=g['id'])
+ else:
+ # one number
+ group_id = data.get_group_id(group)
+ if not group_id:
+ print "group error!"
+ sys.exit(1)
+ mid = data.remove_number(number=number, group_id=group_id)
elif sys.argv[1] == 'set-sender':
if len(sys.argv) != 4:
usage()

0 comments on commit 0d408a7

Please sign in to comment.