Created
December 18, 2017 17:43
-
-
Save vgallissot/98386a4c4fa578d8a4b943a154f7a3cd to your computer and use it in GitHub Desktop.
Generate XML for dynamic gnome wallpapers
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
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
""" | |
Generates a dynamic-gnome-wallpaper XML file on STDOUT | |
with images provided as arguments | |
To be called like: | |
$ python dynamic-gnome-wallpaper.py ~/Pictures/*.png > ~/Pictures/dynamic-gnome-wallpaper.xml | |
""" | |
import sys | |
import re | |
# if no args | |
if len(sys.argv) < 2: | |
print("Give this script some datas!") | |
exit(0) | |
else: | |
# keep only images in args list | |
R = re.compile(".*(jpg|gif|png)") | |
IMG_LIST = list(filter(R.match, sys.argv)) | |
XML = """<background> | |
<starttime> | |
<year>2011</year> | |
<month>11</month> | |
<day>24</day> | |
<hour>7</hour> | |
<minute>00</minute> | |
<second>00</second> | |
</starttime> | |
""" | |
for index, value in enumerate(IMG_LIST): | |
# loop final element with first | |
if index == len(IMG_LIST[:-1]): | |
next_element = IMG_LIST[0] | |
else: | |
next_element = IMG_LIST[index+1] | |
XML += """ | |
<static> | |
<duration>600.0</duration> | |
<file>{current_file}</file> | |
</static> | |
<transition type="overlay"> | |
<duration>1.0</duration> | |
<from>{current_file}</from> | |
<to>{next_file}</to> | |
</transition> | |
""".format(current_file=value, next_file=next_element) | |
XML += "</background>" | |
print(XML) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment