Last active
July 11, 2017 06:39
-
-
Save zvyn/a451d3fcabb1f1c7212d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=Create dynamic bg.svg in /tmp. | |
[Service] | |
User=nobody | |
Group=nobody | |
ExecStart=/usr/local/bin/dynbg.py /usr/local/etc/dynbg.svg /tmp/bg.svg | |
Restart=no | |
Type=oneshot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=Update /tmp/bg.svg | |
[Timer] | |
OnCalendar=*-*-* *:*:00 | |
Persistent=true | |
Unit=dynbg.service | |
[Install] | |
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/python | |
# Author: Milan Oberkirch <[email protected]> | |
import subprocess | |
from sys import argv, exit | |
from string import printable | |
from re import sub | |
def dynbg(template, output): | |
def bash(match): | |
cmd = match.group(0)[2:-1] | |
process = subprocess.Popen( | |
['bash', "-c", cmd], | |
stdout=subprocess.PIPE, | |
stderr=subprocess.PIPE | |
) | |
return ''.join( | |
filter(lambda x: x in printable, process.communicate()[0].decode()) | |
).replace('\n', '</tspan><tspan dy="1em">') | |
with open(template, 'r') as file: | |
file_content = file.read() | |
with open(output, 'w') as file: | |
file.write(sub(r'\$\(.+\)', bash, file_content)) | |
if __name__ == '__main__': | |
if len(argv) == 3: | |
this, template, output = argv | |
else: | |
print('Usage: %s template.svg output.svg' % argv[0]) | |
exit(1) | |
dynbg(template, output) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment