Merge pull request #8 from mjepronk/master
Two new modules (battery status and clock)
This commit is contained in:
commit
e44770ef14
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
import json
|
import json
|
||||||
import urllib.request, urllib.error, urllib.parse
|
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
import time
|
import time
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
|
@ -44,7 +44,7 @@ mailsettings = {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
mailchecker = mailchecker.MailChecker(mailsettings)
|
mailchecker = mailchecker.MailChecker(mailsettings)
|
||||||
status.register_module(mailchecker)
|
status.register(mailchecker)
|
||||||
|
|
||||||
# the mods.de forum new bookmarks module
|
# the mods.de forum new bookmarks module
|
||||||
mdesettings = {
|
mdesettings = {
|
||||||
@ -52,17 +52,28 @@ mdesettings = {
|
|||||||
"password": "your_password"
|
"password": "your_password"
|
||||||
}
|
}
|
||||||
mde = modsde.ModsDeChecker(mdesettings)
|
mde = modsde.ModsDeChecker(mdesettings)
|
||||||
status.register_module(mde)
|
status.register(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"
|
||||||
nm = notmuch.NotmuchMailChecker(db_path)
|
nm = notmuch.NotmuchMailChecker(db_path)
|
||||||
status.register_module(nm)
|
status.register(nm)
|
||||||
|
|
||||||
|
|
||||||
# the thunderbird dbus new mail checker module
|
# the thunderbird dbus new mail checker module
|
||||||
tb = thunderbirdnewmail.ThunderbirdMailChecker()
|
tb = thunderbirdnewmail.ThunderbirdMailChecker()
|
||||||
status.register_module(tb)
|
status.register(tb)
|
||||||
|
|
||||||
|
|
||||||
|
# the battery status checker module
|
||||||
|
battery = batterychecker.BatteryChecker()
|
||||||
|
status.register(battery)
|
||||||
|
|
||||||
|
|
||||||
|
# the clock
|
||||||
|
clock = clock.Clock()
|
||||||
|
status.register(clock)
|
||||||
|
|
||||||
|
|
||||||
# start the handler
|
# start the handler
|
||||||
status.run()
|
status.run()
|
||||||
|
46
i3pystatus/batterychecker.py
Normal file
46
i3pystatus/batterychecker.py
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from i3pystatus import IntervalModule
|
||||||
|
|
||||||
|
class BatteryChecker(IntervalModule):
|
||||||
|
"""
|
||||||
|
This class uses the /proc/acpi/battery interface to check for the
|
||||||
|
battery status
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, battery_ident="BAT0"):
|
||||||
|
self.battery_ident = battery_ident
|
||||||
|
self.base_path = "/sys/class/power_supply/%s" % self.battery_ident
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
urgent = False
|
||||||
|
color = "#ffffff"
|
||||||
|
status = open('%s/status' % self.base_path, 'r').readline().strip()
|
||||||
|
energy_now = float(open('%s/energy_now' % self.base_path, 'r').readline())
|
||||||
|
|
||||||
|
if status == 'Full':
|
||||||
|
full_text = 'fully charged'
|
||||||
|
elif status == 'Charging':
|
||||||
|
energy_full = float(open('%s/energy_full' % self.base_path, 'r').readline())
|
||||||
|
energy_percentage = (energy_now / energy_full) * 100
|
||||||
|
full_text = '%.2f%% charged'
|
||||||
|
elif status == 'Discharging':
|
||||||
|
power_now = float(open('%s/power_now' % self.base_path, 'r').readline())
|
||||||
|
remaining_time_secs = (energy_now / power_now) * 3600
|
||||||
|
hours, remainder = divmod(remaining_time_secs, 3600)
|
||||||
|
minutes, seconds = divmod(remainder, 60)
|
||||||
|
full_text = "%ih %im %is remaining" % (hours, minutes, seconds)
|
||||||
|
if remaining_time_secs < (15*60):
|
||||||
|
urgent = True
|
||||||
|
color = "#ff0000"
|
||||||
|
else:
|
||||||
|
full_text = 'n/a'
|
||||||
|
|
||||||
|
self.output = {
|
||||||
|
"full_text": full_text,
|
||||||
|
"name": "pybattery",
|
||||||
|
"instance": self.battery_ident,
|
||||||
|
"urgent": urgent,
|
||||||
|
"color": color
|
||||||
|
}
|
34
i3pystatus/clock.py
Normal file
34
i3pystatus/clock.py
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import os, locale, datetime
|
||||||
|
|
||||||
|
from i3pystatus import IntervalModule
|
||||||
|
|
||||||
|
class Clock(IntervalModule):
|
||||||
|
"""
|
||||||
|
This class shows a clock
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, format_string=None):
|
||||||
|
lang = os.environ.get('LANG', None)
|
||||||
|
if lang:
|
||||||
|
locale.setlocale(locale.LC_ALL, lang)
|
||||||
|
if not format_string:
|
||||||
|
lang = locale.getlocale()[0]
|
||||||
|
if lang == 'en_US':
|
||||||
|
# MDY format - United States of America
|
||||||
|
format_string = "%a %b %-d %X"
|
||||||
|
else:
|
||||||
|
# DMY format - almost all other countries
|
||||||
|
format_string = "%a %-d %b %X"
|
||||||
|
self.format_string = format_string
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
full_text = datetime.datetime.now().strftime(self.format_string)
|
||||||
|
self.output = {
|
||||||
|
"full_text": full_text,
|
||||||
|
"name": "pyclock",
|
||||||
|
"urgent": False,
|
||||||
|
"color": "#ffffff"
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user