diff options
author | Ahmed Khanzada <me@enzu.ru> | 2023-09-05 22:29:26 -0400 |
---|---|---|
committer | Ahmed Khanzada <me@enzu.ru> | 2023-09-05 22:29:26 -0400 |
commit | 6bb36b8758cd1c1e5374dc729b66c972f44388a6 (patch) | |
tree | e067639d482c0c6ce3edb06ee0bc537a1a69d75a | |
parent | efea53efc22365ad15e61eb5e5ec22f8b48adc83 (diff) |
Better Python example
-rw-r--r-- | modeline/pianobar/README.org | 62 |
1 files changed, 31 insertions, 31 deletions
diff --git a/modeline/pianobar/README.org b/modeline/pianobar/README.org index b6fb1fd..27d4c9b 100644 --- a/modeline/pianobar/README.org +++ b/modeline/pianobar/README.org @@ -9,43 +9,43 @@ event_command = ~/.config/pianobar/event_command.py event_command.py should be executable and look like this: #+BEGIN_SRC python -#!/usr/bin/python - -import os -import sys -from os.path import expanduser, join - -path = os.environ.get('XDG_CONFIG_HOME') -if not path: - path = expanduser("~/.config") -else: - path = expanduser(path) -fn = join(path, 'pianobar', 'nowplaying') - -lines = sys.stdin.readlines() -cmd = sys.argv[1] - -if cmd == 'songstart': - with open(fn, 'w') as f: - title = None - artist = None - for line in lines: - if "title" in line: - split = line.split("=") - title = split[1] - elif "artist" in line: - split = line.split("=") - artist = split[1] - if title and artist: - nowplaying = "{} by {}".format(title, artist).replace("\n", "") - f.write(nowplaying) + #!/usr/bin/python + + import os + import sys + from os.path import expanduser, join + + path = os.environ.get('XDG_CONFIG_HOME') + if not path: + path = expanduser("~/.config") + else: + path = expanduser(path) + fn = join(path, 'pianobar', 'nowplaying') + + lines = sys.stdin.readlines() + cmd = sys.argv[1] + + if cmd == 'songstart': + with open(fn, 'w') as f: + title = None + artist = None + for line in lines: + if "title" in line: + split = line.split("=") + title = split[1] + elif "artist" in line: + split = line.split("=") + artist = split[1] + if title and artist: + nowplaying = "{} - {}".format(artist, title).replace("\n", "") + f.write(nowplaying) #+END_SRC ** Usage Put: #+BEGIN_SRC lisp -(load-module "pianobar") + (load-module "pianobar") #+END_SRC In your =~/.stumpwmrc= |