Skip to content

Commit

Permalink
Merge pull request #311 from giloser/Info_history
Browse files Browse the repository at this point in the history
Info history
  • Loading branch information
giloser authored Nov 9, 2020
2 parents fab73b9 + 0267dcc commit d033b5a
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 15 deletions.
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
This plugin integrates Telegram Messenger with Octoprint. It sends messages (with photos if available) on print start, end and failure. Also it sends messages during the print at configurable intervals. That way you don't have to remember to regularly have a look at the printing process.
Also, you can control Octoprint via messages (settings, start a print and much more). Send `/status` to get the current printer status or `/abort` to abort the current print. Send `/help` for a list of all recognized commands. You may also use this bot in groups.

**Latest release: [1.6.0](https://github.com/fabianonline/OctoPrint-Telegram/releases)**
**Latest release: [1.6.1](https://github.com/fabianonline/OctoPrint-Telegram/releases)**

<!-- omit in toc -->
## Contents
Expand Down Expand Up @@ -68,7 +68,7 @@ If you already have a bot, you only need your bot token to proceed. GOTO `4.` (o
print - Lets you start a print. A confirmation is required.
togglepause - Pause/Resume current Print.
con - Connect/disconnect printer.
upload - You can just send me a gcode file to save it to my library.
upload - You can just send me a gcode file to save it to my library. Also accept zip file.
sys - Execute Octoprint System Commands.
ctrl - Use self defined controls from Octoprint.
tune - Set feed- and flowrate. Control temperatures.
Expand Down Expand Up @@ -96,6 +96,8 @@ If you already have a bot, you only need your bot token to proceed. GOTO `4.` (o
5. Hit "Save" at the bottom of the settings dialog.

6. If you want to create gif and receive them as notification we use ffmpeg like timelapse (if problem please check timelapse is configured).
you'll have to install CpuLimit to be able to create gif so please for raspberry connect to your raspberry with putty (for exemple) and execute
sudo apt-get install cpulimit

Congratulations! Your printer is now connected to your Telegram bot.

Expand Down Expand Up @@ -231,7 +233,7 @@ In this section you can configure the content of the notification messages.

**`/con`** - Connect/disconnect printer. Choose between auto connect, use defaults to connect or manual connect (select port/baudrate/printer profile). You are also able to change the connection defaults and turn auto connect on/off.

**`/upload`** - You can just send a gcode file to the bot to save it in upload folder of Octoprint. If you send this command, the bot will tell you the same :) NOTE: This will NOT work in groups.
**`/upload`** - You can just send a gcode file or a zip file to the bot to save it in upload folder of Octoprint. If you send this command, the bot will tell you the same :) NOTE: This will NOT work in groups.

**`/sys`** - Execute Octoprint System Comamnds you defined in *config.yaml*. If a confirmation is defined for the system command, it will be displayed before execution. See [Octoprint documentation](http://docs.octoprint.org/en/master/configuration/config_yaml.html#system) for details on setting up system commands. There is also a [plugin](http://plugins.octoprint.org/plugins/systemcommandeditor/) for doing this.

Expand All @@ -243,9 +245,11 @@ In this section you can configure the content of the notification messages.

**`/help`** - Displays a help message with all accepted commands and a short description.

**`/gif`** - Send a gif create from 20 images.
**`/gif`** - Send a gif create from 20 images. You'll have to install CpuLimit to be able to create gif so please for raspberry connect to your raspberry with putty (for exemple) and execute
sudo apt-get install cpulimit

**`/supergif`** - Send a gif create from 60 images.
**`/supergif`** - Send a gif create from 60 images. You'll have to install CpuLimit to be able to create gif so please for raspberry connect to your raspberry with putty (for exemple) and execute
sudo apt-get install cpulimit

<!-- omit in toc -->
#### Notes:
Expand All @@ -272,3 +276,4 @@ If you want to talk to other users of this plugin and maybe have some influence
you can join the [Octoprint-Telegram-Users-Group](https://telegram.me/joinchat/CXFirQjl9XTp5dr4OZqH9Q).

This software is licensed under [AGPLv3](http://www.gnu.org/licenses/agpl-3.0.txt)

28 changes: 22 additions & 6 deletions octoprint_telegram/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1147,20 +1147,32 @@ def _send_msg(self, message="", with_image=False,with_gif=False,responses=None,
try:
curr = self._settings.global_get(["plugins","multicam","multicam_profiles"])
self._logger.debug("multicam_profiles : "+ str(curr))
ListGif = []
for li in curr:
try:
self._logger.debug("multicam profile : "+ str(li))
url = li.get("URL")
self._logger.debug("multicam URL : "+ str(url))
ret = self.create_gif_new(chatID,0,li)
if ret != "":
if not sendOneInLoop:
self.send_file(chatID, ret,message)
else:
self.send_file(chatID, ret,"")
sendOneInLoop = True
ListGif.append(ret)
#if not sendOneInLoop:
# self.send_file(chatID, ret,message)
#else:
# self.send_file(chatID, ret,"")
#sendOneInLoop = True
except Exception as ex:
self._logger.exception("Exception loop multicam URL to create gif: "+ str(ex) )
ret = ListGif[-1]
self._logger.debug("ListGif: "+str(ListGif))
for x in ListGif:
try:
if x != ret:
self._logger.debug("send_file whithout message: "+str(x))
self.send_file(chatID, x,"")
except Exception as ex:
self._logger.exception("Exception loop multicam URL to send gif: "+ str(ex) )

except Exception as ex:
self._logger.exception("Exception occured on getting multicam options: "+ str(ex) )
else:
Expand All @@ -1170,6 +1182,7 @@ def _send_msg(self, message="", with_image=False,with_gif=False,responses=None,
ret = self.create_gif_new(chatID,0,0)

if ret != "" and not sendOneInLoop:
self._logger.debug("send_file whith message: "+str(ret))
self.send_file(chatID, ret,message)
#ret = self.create_gif_new(chatID,0,0)
#if ret != "":
Expand Down Expand Up @@ -1478,7 +1491,10 @@ def create_gif_new(self,chatID,sec=7,multicam_prof=0):
# saveDir = os.getcwd()
# os.chdir(self.get_plugin_data_folder()+"/tmpgif")

outPath = self.get_plugin_data_folder()+"/tmpgif/gif.mp4"
if multicam_prof != 0:
outPath = self.get_plugin_data_folder()+"/tmpgif/gif_"+multicam_prof.get("name").replace(" ", "_") + ".mp4"
else:
outPath = self.get_plugin_data_folder()+"/tmpgif/gif.mp4"

try:
os.remove(outPath)
Expand Down
47 changes: 44 additions & 3 deletions octoprint_telegram/telegramCommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ def cmdFiles(self,chat_id,from_id,cmd,parameter):
self.main.send_msg(self.gEmo('warning') + " Command failed with exception: %s!" % e,chatID = chat_id, msg_id = self.main.getUpdateMsgId(chat_id))
############################################################################################
def cmdUpload(self,chat_id,from_id,cmd,parameter):
self.main.send_msg(self.gEmo('info') + " To upload a gcode file, just send it to me.\nThe file will be stored in 'TelegramPlugin' folder.",chatID=chat_id)
self.main.send_msg(self.gEmo('info') + " To upload a gcode file (also accept zip file), just send it to me.\nThe file will be stored in 'TelegramPlugin' folder.",chatID=chat_id)
############################################################################################
def cmdSys(self,chat_id,from_id,cmd,parameter):
if parameter and parameter != "back":
Expand Down Expand Up @@ -820,7 +820,7 @@ def cmdHelp(self,chat_id,from_id,cmd,parameter):
"/print - Lets you start a print. A confirmation is required.\n"
"/togglepause - Pause/Resume current Print.\n"
"/con - Connect/disconnect printer.\n"
"/upload - You can just send me a gcode file to save it to my library.\n"
"/upload - You can just send me a gcode file or a zip file to save it to my library.\n"
"/sys - Execute Octoprint System Commands.\n"
"/ctrl - Use self defined controls from Octoprint.\n"
"/tune - Set feed- and flowrate. Control temperatures.\n"
Expand Down Expand Up @@ -851,7 +851,26 @@ def fileList(self,pathHash,page,cmd,chat_id,wait = 0):
for key,val in sorted(iter(L.items()), key=lambda x: x[1]['date'] , reverse=True):
try:
self._logger.debug("should get info on item " )
vfilename = self.main.emojis['page facing up']+" "+('.').join(key.split('.')[:-1])
try:
#Giloser 30/10/2020 get info from history to show last state of print
if(len(val['history']) > 0):
HistList = val['history']
HistList.sort(key=lambda x: x['timestamp'] , reverse=True)
try:
if(HistList[0]['success'] == True):
#vfilename = self.main.emojis['party face']+" "+('.').join(key.split('.')[:-1])
vfilename = self.main.emojis['party popper']+" "+('.').join(key.split('.')[:-1])
else:
#vfilename = self.main.emojis['disappointed but relieved face']+" "+('.').join(key.split('.')[:-1])
vfilename = self.main.emojis['warning sign']+" "+('.').join(key.split('.')[:-1])
except Exception as ex:
vfilename = self.main.emojis['page facing up']+" "+('.').join(key.split('.')[:-1])
else:
vfilename = self.main.emojis['squared new']+" "+('.').join(key.split('.')[:-1])
except Exception as ex:
vfilename = self.main.emojis['squared new']+" "+('.').join(key.split('.')[:-1])
self._logger.debug("An Exception in fileList loop file items : " + str(ex))

self._logger.debug("vfilename : {}".format(vfilename))
vhash = self.hashMe(pathWoDest + key)
self._logger.debug("vhash : " + str(vhash) )
Expand Down Expand Up @@ -910,6 +929,28 @@ def fileDetails(self,pathHash,page,cmd,fileHash,chat_id,from_id,wait=0):
msg += "\n<b>"+self.main.emojis['clock face twelve oclock']+"Uploaded:</b> " + datetime.datetime.fromtimestamp(file['date']).strftime('%Y-%m-%d %H:%M:%S')
except Exception as ex:
self._logger.info("An Exception in get upload time : " + str(ex) )

self._logger.debug("val : " + str(file) )
self._logger.debug("meta : " + str(meta) )
try:
#Giloser 30/10/2020 get info from history to show last state of print
if(len(file['history']) > 0):
HistList = file['history']
HistList.sort(key=lambda x: x['timestamp'] , reverse=True)
try:
if(HistList[0]['success'] == True):
#vfilename = self.main.emojis['party face']+" "+('.').join(key.split('.')[:-1])
msg += "\n<b>"+ self.main.emojis['party popper']+"Number of Print:</b> " + str(len(file['history']))
else:
#vfilename = self.main.emojis['disappointed but relieved face']+" "+('.').join(key.split('.')[:-1])
msg += "\n<b>"+ self.main.emojis['warning sign']+"Number of Print:</b> " + str(len(file['history']))
except Exception as ex:
msg += "\n<b>"+ self.main.emojis['page facing up']+"Number of Print:</b> " + str(len(file['history']))
else:
msg += "\n<b>"+ self.main.emojis['squared new']+"Number of Print:</b> 0"
except Exception as ex:
msg += "\n<b>"+ self.main.emojis['squared new']+"Number of Print:</b> 0"

msg += "\n<b>"+self.main.emojis['flexed biceps']+"Size:</b> " + self.formatSize(file['size'])
filaLen = 0
printTime = 0
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
plugin_name = "OctoPrint-Telegram"

# The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module
plugin_version = "1.6.0"
plugin_version = "1.6.1"

# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin
# module
Expand Down

0 comments on commit d033b5a

Please sign in to comment.