Added yet another module type, fixed notmuch module
(Yeah, I'm really lazy today)
This commit is contained in:
parent
59ab38d83b
commit
2c7b0fcef9
@ -4,6 +4,7 @@ import sys
|
|||||||
import json
|
import json
|
||||||
import urllib.request, urllib.error, urllib.parse
|
import urllib.request, urllib.error, urllib.parse
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
import time
|
||||||
|
|
||||||
class BaseModule:
|
class BaseModule:
|
||||||
output = None
|
output = None
|
||||||
@ -26,6 +27,17 @@ class AsyncModule(BaseModule):
|
|||||||
def mainloop(self):
|
def mainloop(self):
|
||||||
"""This is run in a separate daemon-thread"""
|
"""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:
|
class I3statusHandler:
|
||||||
modules = []
|
modules = []
|
||||||
|
|
||||||
|
@ -6,7 +6,9 @@
|
|||||||
import notmuch
|
import notmuch
|
||||||
import json
|
import json
|
||||||
|
|
||||||
class NotmuchMailChecker(object):
|
from i3pystatus import IntervalModule
|
||||||
|
|
||||||
|
class NotmuchMailChecker(IntervalModule):
|
||||||
"""
|
"""
|
||||||
This class uses the notmuch python bindings to check for the
|
This class uses the notmuch python bindings to check for the
|
||||||
number of messages in the notmuch database with the tags "inbox"
|
number of messages in the notmuch database with the tags "inbox"
|
||||||
@ -18,7 +20,7 @@ class NotmuchMailChecker(object):
|
|||||||
def __init__(self, db_path):
|
def __init__(self, db_path):
|
||||||
self.db_path = db_path
|
self.db_path = db_path
|
||||||
|
|
||||||
def output(self):
|
def run(self):
|
||||||
db = notmuch.Database(self.db_path)
|
db = notmuch.Database(self.db_path)
|
||||||
unread = notmuch.Query(db, 'tag:unread and tag:inbox').count_messages()
|
unread = notmuch.Query(db, 'tag:unread and tag:inbox').count_messages()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user