Thinkai's Blog

Autohotkey|Python|php|aardio|VOIP|IT 爱好者

# encoding: utf-8
#!/usr/bin/python

import os
import time
import MySQLdb
#设置目录
timearray = time.localtiime(time.time())
timedir = time.strftime("%Y/%m/%d/",timearray)
monitordir = "/var/spool/asterisk/monitor/"+timedir
vi conv.p
# 打开数据库连接
db = MySQLdb.connect("localhost","root","Elastixdb","asteriskcdrdb" )

# 使用cursor()方法获取操作游标 
cursor = db.cursor()

sql = "SELECT recordingfile from cdr where recordingfile like '%.wav';"
try:
   # 执行SQL语句
   cursor.execute(sql)
   # 获取所有记录列表
   results = cursor.fetchall()
   for row in results:
      recordingfile = row[0]
      if os.path.exists(monitordir+recordingfile):
      	  print "转换:%s" % monitordir+recordingfile
      	  os.system("sox "+monitordir+recordingfile+" "+monitordir+recordingfile.replace('wav','gsm'))
      	  os.remove(monitordir+recordingfile.replace('gsm','wav'))
      	  sql = "update cdr set recordingfile=replace(recordingfile,'wav','gsm') where recordingfile='"+recordingfile+"';"
      	  cursor.execute(sql)
      	  db.commit()
      else:
      	  print "找不到文件:%s" % monitordir+recordingfile
except:
   print "Error: unable to fecth data"

# 关闭数据库连接
db.close()



来了就留个评论吧! 3个评论




友情链接:Autohotkey中文帮助Autohotkey官网Autohotkey中文网联系作者免GooglePlay APK下载

 主题设计 • skyfrit.com  Thinkai's Blog | 保留所有权利

65 queries in 3.324 seconds |