diff options
author | Stefan Schmidt <stefan@datenfreihafen.org> | 2009-08-14 21:33:34 +0200 |
---|---|---|
committer | Stefan Schmidt <stefan@datenfreihafen.org> | 2009-08-14 21:33:34 +0200 |
commit | 5f8a78bd6cfc4bd6fc02c03ebea458f68929a939 (patch) | |
tree | c8f3a1942dfce2983adee0652d356f72e4355d69 /hlrsync/hlrsync.py | |
parent | 15920de8ce9b9199f4ef4ad568b204af0f34b2f0 (diff) |
hlrsync: Sync SMS from the web db to the hlr.
Bugs from me, fixes from Jan. ;)
Diffstat (limited to 'hlrsync/hlrsync.py')
-rwxr-xr-x | hlrsync/hlrsync.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/hlrsync/hlrsync.py b/hlrsync/hlrsync.py index 4ff720bee..e4a495555 100755 --- a/hlrsync/hlrsync.py +++ b/hlrsync/hlrsync.py @@ -27,12 +27,17 @@ with web: web_tokens = web.execute(""" SELECT * FROM reg_tokens """).fetchall() + web_sms = web.execute(""" + SELECT * FROM sms_queue + """).fetchall() # index by subscr id hlr_subscrs_by_id = {} +hlr_subscrs_by_ext = {} hlr_tokens_by_subscr_id = {} for x in hlr_subscrs: hlr_subscrs_by_id[x['id']] = x + hlr_subscrs_by_ext[x['extension']] = x del hlr_subscrs for x in hlr_tokens: hlr_tokens_by_subscr_id[x['subscriber_id']] = x @@ -95,6 +100,26 @@ with hlr: WHERE id = ? """, (x['subscriber_id'],)) +# Sync SMS from web to hlr +with hlr: + for sms in web_sms: + subscr = hlr_subscrs_by_ext.get(sms['receiver_ext']) + if subscr is None: + print '%s not found' % sms['receiver_ext'] + continue + hlr.execute(""" + INSERT INTO SMS + (created, sender_id, receiver_id, reply_path_req, status_rep_req, protocol_id, data_coding_scheme, ud_hdr_ind, text) + VALUES + (?, 1, ?, 0, 0, 0, 0, 0, ?) + """, (sms['created'], subscr['id'], sms['text'])) +with web: + for sms in web_sms: + web.execute(""" + DELETE FROM sms_queue WHERE id = ? + """, (sms['id'],)) + + hlr.close() web.close() |