#!/usr/bin/python3
#
#
from __future__ import print_function
import sys
import os
import csv
import time
import re

XIVO_HOST = "10.181.1.10" 
URL_TIMEOUT = 10

filecsv=sys.argv[1]

phonelist = csv.reader(open("%s" %(filecsv),"rb"),delimiter='|')
for row in phonelist:
        print(row)
        COMMAND = ''
        
        model= 'snom%s' %(row[2])
        
        COMMAND = 'curl --insecure -X POST -H \'Content-Type: application/json\' -H \'Accept: application/json\' -d \'{"mac": "%s", "status": "autoprov", "vendor": "%s", "model": "%s", "plugin": "%s", "entity": "%s"}\' \'https://10.181.1.10:9486/1.1/devices\'' % (':'.join(re.findall('..', row[0])), row[1], row[2], row[3], row[4])

        if COMMAND != '':
                print(COMMAND)
                os.system(COMMAND)
                time.sleep(1)
