It is a script that Python monitors the stop of the 3D printer Mojo and notifies you via Skype.
Monitor Mojo's logs and send all logs via Skype chat for the time being. I will make a phone call when it stops.
Since Mojo stops frequently in a restartable state, I will notify you when it stops. It does not restart automatically because it is necessary to visually check for print abnormalities.
Just set the path to the Mojo log and your Skype contacts If you execute it, monitoring will start
python
# -*- coding: utf-8 -*-
import time
import os
import re
import numpy as np
from watchdog.events import FileSystemEventHandler
from watchdog.observers import Observer
import Skype4Py
#Path to Mojo's log
BASEDIR = "C:/ProgramData/Mojo/Mojo 3D Printer Software/Log/"
log_filename = "SystemLog.log"
#contact information
user_name = 'Frend name'
#-------Skype4Py examples->callfriend.Copy from py(For call)--------->
# This variable will get its actual value in OnCall handler
CallStatus = 0
# Here we define a set of call statuses that indicate a call
# has been either aborted or finished
CallIsFinished = set([Skype4Py.clsFailed, Skype4Py.clsFinished,
Skype4Py.clsMissed, Skype4Py.clsRefused,
Skype4Py.clsBusy, Skype4Py.clsCancelled]);
def AttachmentStatusText(status):
return skype.Convert.AttachmentStatusToText(status)
def CallStatusText(status):
return skype.Convert.CallStatusToText(status)
# This handler is fired when status of Call object has changed
def OnCall(call, status):
global CallStatus
CallStatus = status
print 'Call status: ' + CallStatusText(status)
# This handler is fired when Skype attatchment status changes
def OnAttach(status):
print 'API attachment status: ' + AttachmentStatusText(status)
if status == Skype4Py.apiAttachAvailable:
skype.Attach()
#<--Copy and paste so far----------------------------------------------------
#Attach chat settings to Skype
skype = Skype4Py.Skype()
if not skype.Client.IsRunning:
print 'Starting Skype..'
skype.Client.Start()
skype.Attach()
skype.OnAttachmentStatus = OnAttach
skype.OnCallStatus = OnCall
chat = skype.CreateChatWith(user_name)
chat.SendMessage('Mojo''s watchdog has been started!')
#Mojo log monitoring
class ChangeHandler(FileSystemEventHandler):
def on_modified(self, event):
if event.is_directory:
return
else:
time.sleep(5)
data = np.loadtxt(
os.path.join(BASEDIR, log_filename),
delimiter="\n", dtype=str)
#-Last line at 1(Latest log information)Only output
print(data[-1])
chat.SendMessage(data[-1])
#Make a call when Pause is included
n = len(re.findall('pause', data[-1])) + \
len(re.findall('Paused', data[-1]))
if n > 0:
skype.PlaceCall(user_name)
while not CallStatus in CallIsFinished:
pass
#"Watchdog is quite useful for file monitoring"Copy the code of
if __name__ in '__main__':
while 1:
event_handler = ChangeHandler()
observer = Observer()
observer.schedule(event_handler, BASEDIR, recursive=True)
observer.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join()
Recommended Posts