我是python编程新手。我有个问题。我想每15分钟保存一次输入数据(要列出的原始数据)。15分钟后,列表将被删除并写入输入数据再来一次。可以吗有人帮我吗?谢谢你的好意。你知道吗
from autobahn.twisted.websocket import WebSocketServerProtocol, WebSocketServerFactory
def WriteListtoCSV (data):
with open ('tesdata.csv','a') as csvfile:
writer=csv.writer(csvfile)
for val in data:
writer.writerow([val])
class MyServerProtocol(WebSocketServerProtocol):
def onConnect(self, request):
print("Client connecting: {0}".format(request.peer))
def onOpen(self):
print("WebSocket connection open.")
def onMessage(self, payload, isBinary):
if isBinary:
print("Binary message received: {0} bytes".format(len(payload)))
else:
print("Text message received: {0}".format(payload.decode('utf8')))
# echo back message verbatim
self.sendMessage(payload, isBinary)
mins = 0
data_nilai = [ ]
while mins != 60: #change value with seconds
data_nilai.append(payload.decode('utf8'))
time.sleep(1)
mins+=1
WriteListtoCSV(data_nilai)
#ClearCSV()
def onClose(self, wasClean, code, reason):
print("WebSocket connection closed: {0}".format(reason))
if __name__ == '__main__':
import sys
import csv
import time
from twisted.python import log
from twisted.internet import reactor
log.startLogging(sys.stdout)
factory = WebSocketServerFactory(u"ws://192.168.1.23:9000", debug=False)
factory.protocol = MyServerProtocol
# factory.setProtocolOptions(maxConnections=2)
reactor.listenTCP(9000, factory)
reactor.run()
我只关注信息
下面是Algo的小代码。你知道吗
算法:
代码:
注意:
使用
input()
获取python3.x的用户信息使用
raw_input()
获取python2.x的用户信息[编辑1]
Crontab
参考号:http://www.thegeekstuff.com/2011/07/cron-every-5-minutes/
参考号:http://www.computerhope.com/unix/ucrontab.htm
操作系统:CentOS
要编辑crontab,请使用以下命令:
其中crontab条目结构是:
相关问题 更多 >
编程相关推荐