2014-11-22 61 views
1

我想讓自動出席我的android手機[這是由NFC觸發]。合併Python和Android SL4A代碼

from datetime import datetime 
s1 = '09:40:00' 
s2 = datetime.now().strftime('%H:%M:%S') 
s3 = datetime.now().strftime('%I:%M:%S %p') 
FMT = '%H:%M:%S' 
tdelta = datetime.strptime(s2, FMT) - datetime.strptime(s1, FMT) 
print ('I have arrived ['+str(tdelta)+']' 'HH:MM:SS'' late at ['+str(s3)+'].') 

並分別以下的Android代碼:

droid = android.Android 
import android 
number = "mycellnumber" 
message = "Hello" 
droid.smsSend(number, message.encode("utf-8")) 

我想是合併這兩個代碼發送以下內容作爲消息(和電子郵件,我已經在電腦上分別測試了以下Python代碼後來身體):

('I have arrived ['+str(tdelta)+']' 'HH:MM:SS'' late at ['+str(s3)+'].') 

回答

0

我能夠將這些代碼合併,現在它看起來是這樣的:

import android 
import datetime 
droid = android.Android() 
s1= '09:40:00' 
s2= datetime.datetime.now().strftime('%H:%M:%S') 
s3= datetime.datetime.now().strftime('%I:%M:%S %p') 
FMT = '%H:%M:%S' 
tdelta = datetime.datetime.strptime(s2,FMT) - datetime.datetime.strptime(s1,FMT) 
print ('I have arrived ['+str(tdelta)+']') 
number = "XXXXXXXXXX" 
message = str(tdelta) 
droid.smsSend(number, message.encode("utf"))