Regex module. Batteries... eh.. example included.
*gotta get some sleep. maybe.
This commit is contained in:
parent
d3228cc8be
commit
426f57d97d
@ -5,12 +5,22 @@ from i3pystatus import (
|
|||||||
I3statusHandler,
|
I3statusHandler,
|
||||||
mailchecker,
|
mailchecker,
|
||||||
modsde,
|
modsde,
|
||||||
notmuchmailchecker,
|
notmuch,
|
||||||
thunderbird,
|
thunderbird,
|
||||||
|
regex,
|
||||||
)
|
)
|
||||||
|
|
||||||
status = I3statusHandler()
|
status = I3statusHandler()
|
||||||
|
|
||||||
|
# Regular expression file watcher
|
||||||
|
# If you're using a thinkpad, chances are that this displays your fan speed and level
|
||||||
|
regexsettings = {
|
||||||
|
"regex": "speed:\s+([0-9]+)\nlevel:\s+([a-zA-Z0-9]+)",
|
||||||
|
"file": "/proc/acpi/ibm/fan",
|
||||||
|
"format": "{0} [{1}]",
|
||||||
|
}
|
||||||
|
status.register(regex.Regex(regexsettings))
|
||||||
|
|
||||||
# The imap checker module
|
# The imap checker module
|
||||||
mailsettings = {
|
mailsettings = {
|
||||||
"color": "#ff0000",
|
"color": "#ff0000",
|
||||||
@ -46,8 +56,9 @@ status.register_module(mde)
|
|||||||
|
|
||||||
# the notmuch mail checker module
|
# the notmuch mail checker module
|
||||||
db_path = "path_to_your_notmuch_database"
|
db_path = "path_to_your_notmuch_database"
|
||||||
notmuch = notmuchmailchecker.NotmuchMailChecker(db_path)
|
nm = notmuch.NotmuchMailChecker(db_path)
|
||||||
status.register_module(notmuch)
|
status.register_module(nm)
|
||||||
|
|
||||||
|
|
||||||
# the thunderbird dbus new mail checker module
|
# the thunderbird dbus new mail checker module
|
||||||
tb = thunderbirdnewmail.ThunderbirdMailChecker()
|
tb = thunderbirdnewmail.ThunderbirdMailChecker()
|
||||||
|
30
i3pystatus/regex.py
Normal file
30
i3pystatus/regex.py
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
import re
|
||||||
|
|
||||||
|
from i3pystatus import IntervalModule
|
||||||
|
|
||||||
|
class Regex(IntervalModule):
|
||||||
|
"""
|
||||||
|
Simple regex file watcher
|
||||||
|
|
||||||
|
Settings:
|
||||||
|
* flags — Python.re flags
|
||||||
|
* regex — regular expression
|
||||||
|
* file — file to search for regex matches
|
||||||
|
* format — new-style format string used for output, default is "{0}"
|
||||||
|
"""
|
||||||
|
|
||||||
|
flags = 0
|
||||||
|
format = "{0}"
|
||||||
|
|
||||||
|
def __init__(self, settings):
|
||||||
|
self.__dict__.update(settings)
|
||||||
|
|
||||||
|
self.re = re.compile(self.regex, self.flags)
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
with open(self.file, "r") as f:
|
||||||
|
match = self.re.search(f.read())
|
||||||
|
self.output = self.output = {
|
||||||
|
"full_text" : self.format.format(*match.groups()),
|
||||||
|
"name" : "regex",
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user