Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import os,mysql.connector,shutil
- pathfiles="/1/rec/monitor/"
- files=[f for f in os.listdir(pathfiles) if os.path.isfile(os.path.join(pathfiles, f))]
- cnx = mysql.connector.connect(user='root', password='', host='127.0.0.1', database='pbxanalytics')
- curA = cnx.cursor(buffered=True)
- for fx in files:
- fy=fx[:-4]
- query= ("select calldate from analytics where linkedid=\"%s\" limit 1;" % (fy))
- curA.execute(query)
- x=curA.fetchall()
- if not x:
- continue
- date=x[0][0]
- fpath = pathfiles+date.strftime("%Y/%m/%d/")
- if not os.path.exists(fpath):
- os.makedirs(fpath)
- fileA=pathfiles+fx
- if os.path.isfile(fpath+fx):
- os.remove(fileA)
- else:
- shutil.move(fileA, fpath)
- cnx.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement