hlrsync: Sync SMS from the web db to the hlr.
Bugs from me, fixes from Jan. ;)
This commit is contained in:
parent
15920de8ce
commit
5f8a78bd6c
|
@ -27,12 +27,17 @@ with web:
|
||||||
web_tokens = web.execute("""
|
web_tokens = web.execute("""
|
||||||
SELECT * FROM reg_tokens
|
SELECT * FROM reg_tokens
|
||||||
""").fetchall()
|
""").fetchall()
|
||||||
|
web_sms = web.execute("""
|
||||||
|
SELECT * FROM sms_queue
|
||||||
|
""").fetchall()
|
||||||
|
|
||||||
# index by subscr id
|
# index by subscr id
|
||||||
hlr_subscrs_by_id = {}
|
hlr_subscrs_by_id = {}
|
||||||
|
hlr_subscrs_by_ext = {}
|
||||||
hlr_tokens_by_subscr_id = {}
|
hlr_tokens_by_subscr_id = {}
|
||||||
for x in hlr_subscrs:
|
for x in hlr_subscrs:
|
||||||
hlr_subscrs_by_id[x['id']] = x
|
hlr_subscrs_by_id[x['id']] = x
|
||||||
|
hlr_subscrs_by_ext[x['extension']] = x
|
||||||
del hlr_subscrs
|
del hlr_subscrs
|
||||||
for x in hlr_tokens:
|
for x in hlr_tokens:
|
||||||
hlr_tokens_by_subscr_id[x['subscriber_id']] = x
|
hlr_tokens_by_subscr_id[x['subscriber_id']] = x
|
||||||
|
@ -95,6 +100,26 @@ with hlr:
|
||||||
WHERE id = ?
|
WHERE id = ?
|
||||||
""", (x['subscriber_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()
|
hlr.close()
|
||||||
web.close()
|
web.close()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue