Advertisement
Guest User

Untitled

a guest
Oct 5th, 2018
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.76 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import os,mysql.connector,shutil
  4.  
  5. pathfiles="/1/rec/monitor/"
  6.  
  7. files=[f for f in os.listdir(pathfiles) if os.path.isfile(os.path.join(pathfiles, f))]
  8.  
  9. cnx = mysql.connector.connect(user='root', password='', host='127.0.0.1', database='pbxanalytics')
  10.  
  11. curA = cnx.cursor(buffered=True)
  12.  
  13.  
  14. for fx in files:
  15.    fy=fx[:-4]
  16.    query= ("select calldate from analytics where linkedid=\"%s\" limit 1;" % (fy))
  17.    curA.execute(query)
  18.    x=curA.fetchall()
  19.    if not x:
  20.       continue
  21.    date=x[0][0]
  22.    fpath = pathfiles+date.strftime("%Y/%m/%d/")
  23.    if not os.path.exists(fpath):
  24.      os.makedirs(fpath)
  25.    fileA=pathfiles+fx
  26.    if os.path.isfile(fpath+fx):
  27.       os.remove(fileA)
  28.    else:
  29.       shutil.move(fileA, fpath)
  30.  
  31. cnx.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement