diff --git a/i3pystatus/__init__.py b/i3pystatus/__init__.py index c6cccff..ffeee6f 100644 --- a/i3pystatus/__init__.py +++ b/i3pystatus/__init__.py @@ -4,6 +4,7 @@ import sys import json import urllib.request, urllib.error, urllib.parse from threading import Thread +import time class BaseModule: output = None @@ -26,6 +27,17 @@ class AsyncModule(BaseModule): def mainloop(self): """This is run in a separate daemon-thread""" +class IntervalModule(AsyncModule): + interval = 5 # seconds + + def run(self): + """Called every self.interval seconds""" + + def mainloop(self): + while True: + self.run() + time.sleep(self.interval) + class I3statusHandler: modules = [] diff --git a/i3pystatus/notmuchmailchecker.py b/i3pystatus/notmuch.py similarity index 90% rename from i3pystatus/notmuchmailchecker.py rename to i3pystatus/notmuch.py index 51e59b0..2633bd9 100644 --- a/i3pystatus/notmuchmailchecker.py +++ b/i3pystatus/notmuch.py @@ -6,7 +6,9 @@ import notmuch import json -class NotmuchMailChecker(object): +from i3pystatus import IntervalModule + +class NotmuchMailChecker(IntervalModule): """ This class uses the notmuch python bindings to check for the number of messages in the notmuch database with the tags "inbox" @@ -18,7 +20,7 @@ class NotmuchMailChecker(object): def __init__(self, db_path): self.db_path = db_path - def output(self): + def run(self): db = notmuch.Database(self.db_path) unread = notmuch.Query(db, 'tag:unread and tag:inbox').count_messages()