我用python为research编写了一个push通知调度器,它将处理通过NODE.js发送通知的问题。它在我的Mac电脑上运行得很好,没有问题。我在其他地方构建了一个服务器来处理调度程序,因为它一直处于运行状态。服务器运行Debian Wheezy,原因我无法控制。但是,每当我尝试运行代码时,我会得到:
File "scheduler.py", line 148, in send_notifications
s.enter(5, 1, notification, kwargs={'notify': 'Welcome to the Study!'})
TypeError: enter() got an unexpected keyword argument 'kwargs'
在我的Mac电脑上仍然工作得很好。我已经检查了所有导入的库是否都通过pip3下载了,但我就是不知道我的问题是什么。我在stackoverflow和其他各种源上检查过其他有这个错误的人,但我不确定他们是否有和我的问题类似的问题,主要是类调用问题,我不认为这是那样的。我已经附上了代码,虽然我不确定这是否有帮助。我的意思是,它不是世界上最干净的代码,但我在移动开发方面比python更流利。有什么建议吗?你知道吗
import time #this need is obvious
import datetime as dt
import sched
from datetime import datetime
from datetime import timedelta
from subprocess import call #needed to call terminal commands
#Don't forget to chmod +x this python application so that you can sudo out.
#this order of the notifications that will be run, in an array
listOfNotificationNames = ['weather', 'sched', 'thermo', 'manualKitchen', 'frontDoor', 'garage', 'window', 'solar', 'backDoor', 'garage', 'frontDoor',
'manualKitchen', 'solar', 'energyCom', 'alarm', 'weather', 'sched', 'solar', 'manualKitchen', 'thermo', 'frontDoor', 'garage', 'manualKitchen',
'autokitchen', 'backDoor', 'frontDoor', 'manualKitchen', 'garage', 'sensor', 'solar', 'window', 'energyCom', 'alarm', 'weather', 'sched', 'thermo',
'manualKitchen', 'frontDoor', 'garage', 'tvenergy', 'window', 'garage', 'backDoor', 'solar', 'frontDoor', 'manualKitchen', 'energyCom', 'alarm',
'weather', 'sched', 'solar', 'thermo', 'manualKitchen', 'frontDoor', 'manualKitchen', 'garage', 'backDoor', 'milk', 'garage', 'frontDoor', 'manualKitchen',
'autokitchen', 'energyCom', 'alarm', 'weather', 'solar', 'sched', 'thermo', 'manualKitchen', 'backDoor', 'garage', 'window', 'frontDoor', 'autokitchen',
'manualKitchen', 'frontDoor', 'solar', 'garage', 'energyCom', 'alarm']
#Dictionary of what the above short names connect to. Take short names, and connect them to full length notifications
listOfNotificationText = {'garage': 'Your garage door has opened', 'frontDoor': 'Your front door has opened', 'backDoor': 'Your back door has opened',
'energyCom': 'Your daily energy consumption is: 33.5 kWh', 'thermo': 'Your thermostat has been changed to 73 degrees', 'weather': 'The weather for the day is: Cloudy and cool',
'solar': 'The solar cell battery status is 52%', 'alarm': 'Tomorrow’s alarm is set for 9am', 'sched': 'Today’s schedule includes: ',
'milk': 'Don’t forget to get milk on your way home today.', 'manualKitchen': 'A light in the kitchen has been turned on',
'sensor': 'The sensor above the door is not responding. Please check on its status.',
'tvenergy': 'Your television utilizes 2 watts of energy when not in use. It will be powered off when not in use from now on.',
'window': 'The bedroom window has been opened to cool the room.'}
#test code, can be used to test the notification system
time1 = now+timedelta(seconds=30)
time2 = now+timedelta(seconds=60)
time3 = now+timedelta(seconds=90)
testList = [dt.datetime(now.year, now.month, now.day, time1.hour, time1.minute, time1.second),
dt.datetime(now.year, now.month, now.day, time2.hour, time2.minute, time2.second),
dt.datetime(now.year, now.month, now.day, time3.hour, time3.minute, time3.second)]
#empty list to be filled
listOfTimeDelays = [0, 0, 0]
#takes all the lists above, and figures out how long each of them are from when I started the study.
#This creates a giant list of delays from the day I hit start
def calculateMinutesIntoSeconds(testList, listOfTimeDelays):
i = 0
for member in testList:
print(member)
listOfTimeDelays[i] = ((member-dt.datetime(now.year, now.month, now.day, now.hour, now.minute, now.second)).total_seconds())
print(listOfTimeDelays[i])
i= i+1
# Note that you have to specify path to script
#This call runs the notification.
#Create a scheduler.
s = sched.scheduler(time.time, time.sleep)
#Takes a notification text and sends ends out the notification.
def notification(notify='failure to properly fill notification'):
call(["node", "app.js", notify, "send this data"])
#test code. Mostly ignore this
def print_time(a='default'):
print("From print_time", time.time(), a)
def send_notifications():
#calculate all of the many times delays
calculateMinutesIntoSeconds(testList, listOfTimeDelays)
# calculateMinutesIntoSeconds(listOfTimesDay1, listOfTimeDelays)
# calculateMinutesIntoSeconds(listOfTimesDay2, listOfTimeDelays)
# calculateMinutesIntoSeconds(listOfTimesDay3, listOfTimeDelays)
# calculateMinutesIntoSeconds(listOfTimesDay4, listOfTimeDelays)
# calculateMinutesIntoSeconds(listOfTimesDay5, listOfTimeDelays)
print("Time marker for beginning of study: ", time.time())
#counter needed for calls
i = 0
#Just notify people that the study has started.
s.enter(5, 1, notification, kwargs={'notify': 'Welcome to the Study!'})
#This for loop fills the scheduler with every notification that needs to be sent.
for member in listOfTimeDelays:
#takes one of the time delays, a priority (I just made them all 1), and then sends the right notification
s.enter(member, 1, notification, kwargs={'notify': listOfNotificationText[listOfNotificationNames[i]]})
#Incriments the counter to make sure you get the next notification
i = i+1
#runs the scheduler
s.run()
#Marks the end of the study
print("Time marker for end of study: ",time.time())
#Calls the above method
send_notifications()
更新:
嗯,在进一步检查,它看起来像喘息系统默认3.2,不会接受任何高于这一点的要求。看起来它接受“argument”,但正如Klaus所建议的,argument还需要notify与发送的通知位于同一区域。你知道吗
所以现在看起来
s.enter(5, 1, notification, argument={'notify: Welcome to the Study!'})
#This for loop fills the scheduler with every notification that needs to be sent.
for member in listOfTimeDelays:
notification = 'notify: ' + listOfNotificationText[listOfNotificationNames[i]]
#takes one of the time delays, a priority (I just made them all 1), and then sends the right notification
s.enter(member, 1, notification, argument={notification)
#Incriments the counter to make sure you get the next notification
i = i+1
谢谢你的帮助。你知道吗
sched.Scheduler
只接受kwargs
参数from Python 3.3 onwards。我猜你在Debian机器上运行的是旧版本。你知道吗相关问题 更多 >
编程相关推荐