Dec-01-2017, 03:06 PM
I want to create a file with each second a logging of the data with a timestamp. instead of always overwriting it like the script underneath does. Perhaps in csv ?
But how to import the data that this script is reading into such a file ? I can not find exactly what I'm looking for

Thanks for any kind of help
#!/usr/bin/env python3 # coding=utf-8 """ ... """ import sys, time from daemon3x import daemon3x from configparser import SafeConfigParser import smaem #read configuration parser = SafeConfigParser() parser.read('/etc/smaemd/config') smaemserials=parser.get('SMA-EM', 'serials') serials=smaemserials.split(' ') smavalues=parser.get('SMA-EM', 'values') values=smavalues.split(' ') pidfile=parser.get('DAEMON', 'pidfile') class MyDaemon(daemon3x): def run(self): emparts = {} while True: emparts=smaem.readem() for serial in serials: #print(serial) #print(emparts['serial']) if serial==format(emparts['serial']): #print("match") for value in values: file = open("/run/shm/em-"+format(serial)+"-"+format(value), "w") file.write('%.4f' % emparts[value]) file.close() if __name__ == "__main__": daemon = MyDaemon(pidfile) if len(sys.argv) == 2: if 'start' == sys.argv[1]: daemon.start() elif 'stop' == sys.argv[1]: daemon.stop() elif 'restart' == sys.argv[1]: daemon.restart() else: print ("Unknown command") sys.exit(2) sys.exit(0) else: print ("usage: %s start|stop|restart" % sys.argv[0]) print (pidfile) sys.exit(2)