I recently joined the Plonator Sprint and helped working on new demosites for Plone. Here is a the german news on plone.de and here you can find the sprint report.
1 min read
I recently joined the Plonator Sprint and helped working on new demosites for Plone. Here is a the german news on plone.de and here you can find the sprint report.
1 min read
During the Plonator sprint i have started to replace Supervisor (a process manager) with systemd start/stop scripts.
Right now Supervisor does not work with Python 3 (Supervisor version 4 will work) and it has problems stopping a Zope4 instance (needs more testing).
A systemd script could look like this:
root@xxxy:~# cat /etc/systemd/system/demo-latest.service
[Unit]
Description=demo-latest.plone.de
After=network.target
[Service]
Type=simple
WorkingDirectory=/home/zope/demo-latest.plone.de/
User=zope
Group=zope
ExecStart=/home/zope/demo-latest.plone.de/bin/instance fg
[Install]
WantedBy=multi-user.target
I haven't digged deep into systemd start/stop scripts, but i think i will use it more often. Are you using Supervisor? Is systemd a good replacement?
2 min read
Seit ich ein 7,8 Zoll PocketBook Inkpad 3 besitze, lese ich auch die Zeit auf diesem Ebook-Reader. Um das wöchentlich erscheinde Epub auf den Reader zu bekommen, habe ich mir ein Download Python Script geschrieben.
Es versucht die Downlaod URL zu generieren und die Datei runterzuladen, im Fehlerfall schickt es mir eine E-Mail. Damit (und mit Hilfe meines alten Bash Scripts) bekomme ich die Zeit per Send-to-PocketBook auf meinen Reader.
Meine jetzige Lösung nutzt leider noch Server von dritten (Email über Sent-to-Pocket). Vielleicht bau ich es noch aus, um die Syncronisation über meine Nextcloud laufen zu lassen. Möglich scheint es zu sein.
# -*- coding: utf-8 -*-
"""
"""
import datetime
from email.mime.text import MIMEText
import requests
import smtplib
import sys
import os.path
email = sys.argv[1]
password = sys.argv[2]
def send_mail_to_me():
msg = MIMEText('nt')
msg['Subject'] = 'Zeit.de epub url does not exist'
msg['From'] = email
msg['To'] = email
s = smtplib.SMTP('localhost')
s.sendmail(msg['From'], [msg['To']], msg.as_string())
def download_file(url):
local_filename = url.split('/')[-1]
# NOTE the stream=True parameter
r = requests.get(url, auth=(email, password), stream=True)
with open(local_filename, 'wb') as f:
for chunk in r.iter_content(chunk_size=1024):
if chunk: # filter out keep-alive new chunks
f.write(chunk)
return local_filename
if __name__ == '__main__':
now = datetime.datetime.now()
wk = now.isocalendar()[1]
url = 'https://premium.zeit.de/system/files/{}-{}/epub/die_zeit_2018_{}.epub'.format(now.year, wk, wk+1)
local_filename = url.split('/')[-1]
full_script_path = os.path.dirname(os.path.abspath(__file__))
full_zeit_path = full_script_path + '/' + local_filename
if not os.path.isfile(full_zeit_path):
url_exits = requests.get(url, auth=(email, password))
if url_exits.status_code not in [200, 201]:
send_mail_to_me()
sys.exit(1)
else:
name = download_file(url)
print name
2 min read
I have started several years ago using FHEM to automate some of my devices. Last year though, I discovered Home Assistant. It fits much better my technology stack as it's written in Python instead of Perl, so I started to migrate to it.
As always I'm running against some walls. It was impossible to get my IR-bridge (which switches on the amp) running in Home Assistant, so I needed a way to use the existing FHEM within Home Assistant.
First I opened a new FHEMWEB port (bind only on localhost) with csrfToken check switched off:
fhem.cfg:
define WEBapi FHEMWEB 8086 global
attr WEBapi csrfToken none
attr WEBapi allowFrom 127.0.0.1
Now it's possible to add shell commands to Home Assistant, it could look like this:
configuration.yaml:
shell_command:
fhem_shutdown_all: /usr/bin/wget -q http:// 127.0.0.1:8086/ fhem?cmd.Stop_mediacenter= set%20Stop_mediacenter%20on
fhem_start_first: /usr/bin/wget -q http:// 127.0.0.1:8086/ fhem?cmd.wz_XBMC= set%20wz_XBMC%20on
As I use homeatic I need to wire everything together in scripts.yaml:
# Use scripts with homeatic keypress as there is no delay
# https:// github.com/ danielperna84/ pyhomematic/ issues/ 106
turn_all_off:
sequence:
- service: light.turn_off
entity_id: light.living_room
- service: shell_command.fhem_shutdown_all
And here I bind the turn_all_off to my Homematic Switch:
- alias: "Alle Geraete Aus"
trigger:
platform: event
event_type: homematic.keypress
event_data:
name: WohnzimmerSchalter
channel: 1
param: PRESS_SHORT
action:
- service: script.turn_on
entity_id: script.turn_all_off
This is my second post of my home automation series, I hope it helps someone :)
2 min read
Since ages I have worked sporadicly on my home automation system. My first and biggest motivation was to get ONE button to start the music system and play my music. Meanwhile I got a bigger plan: TELLING the system to play music.
And it should not be a kitchen radio with a lousy speaker. I got the button-press-music working, and it does a lot:
Right now it's buried into fhem (my old home automation software) and some custom python scripts. To be honest I don't know how it works anymore :)
So, to get the music played, I now only need to press ONE button :) But my plan is to tell the system "play music", just like Alexa in the tv spots. But of course, Alexa, Spotify and all the other cloud services are not an option as I want my system to be open source and to protect one's privacy.
That is why I've baked the Mycroft Mark II at Kickstarter and I plan to get my home automation setup ready for it! Here is what Mycroft wants to be:
The open answer to Amazon Echo and Google Home. Mycroft brings you the power of voice while maintaining privacy and data independence.
If all goes well Mycroft Mark II will be shipped by the end of the year. To get ready for it I plan to do a series of blog posts about it:
...