2012/01/18


今天為了要處理簡訊的東西
花了一點時間
原來的log是  0912345678;message
要改成 0912345678,message
順便ftp傳到簡訊server
之後把檔案刪除
程式碼如下

#!/usr/bin/python
from ftplib import FTP
import sys,getpass,os.path,os
if os.path.exists("d:\sms.txt"):
f = open("d:\sms.txt")
lines=f.readlines()
f.close()
for line in lines:
new=line.replace(';',',')
print new
sms_ok_file = open("d:\sms_ok.txt",'a')
sms_ok_file.write(new)
sms_ok_file.close()
host = '127.0.0.1'
username ='anonymous'
password = 'a@'
localfile ='d:\sms_ok.txt'
remotepath ='/'
print "HELLO"
f = FTP(host)
f.login(username,password)
print "Welcome:",f.getwelcome()
f.cwd(remotepath)
fd = open(localfile,'rb')
f.storbinary('STOR %s' % os.path.basename(localfile),fd)
fd.close()
f.quit()
os.remove("d:\sms.txt")
os.remove("d:\sms_ok.txt")

沒有留言: