#!/bin/bash /usr/scripts/python.sh
# -*- coding: utf-8 -*-
import sys
from sip.asterisk import History

if __name__ == '__main__' :
    if len(sys.argv)>1:
        history = History("dbname='django' user='crans' host='pgsql.v4.adm.crans.org'", "voip_history", 99)
        if sys.argv[1] == "add":
            if len(sys.argv)>4:history.add(sys.argv[2], sys.argv[3], sys.argv[4])
            else:print >> sys.stderr, "Usage %s %s {id} {src} {dst}" % (sys.argv[0], sys.argv[1])
        elif sys.argv[1] =="delete":
             if len(sys.argv)>2:history.delete(sys.argv[2])
             else:print >> sys.stderr, "Usage %s %s {id}" % (sys.argv[0], sys.argv[1])
        elif sys.argv[1] =="update":
            if len(sys.argv)>3:history.update(sys.argv[2], sys.argv[3])
            else:print >> sys.stderr, "Usage %s %s {id} {duration}" % (sys.argv[0], sys.argv[1])
        elif sys.argv[1] =="quota":
             if len(sys.argv)>2:history.quota(sys.argv[2])
             else:print >> sys.stderr, "Usage %s %s {number}" % (sys.argv[0], sys.argv[1])
    else:
        print >> sys.stderr, "Usage %s {add | delete | update } ..." % sys.argv[0]
