def check_updates(self): for backend in self.backends: key = backend.__class__.__name__ if key not in self.data: self.data[key] = "?" if key not in self.notif_body: self.notif_body[key] = "" self.output = { "full_text": formatp(self.format_working, **self.data).strip(), "color": self.color_working, } updates_count = 0 for backend in self.backends: name = backend.__class__.__name__ updates, notif_body = backend.updates updates_count += updates self.data[name] = updates self.notif_body[name] = notif_body or "" if updates_count == 0: self.output = {} if not self.format_no_updates else { "full_text": self.format_no_updates, "color": self.color_no_updates, } return self.data["count"] = updates_count self.output = { "full_text": formatp(self.format, **self.data).strip(), "color": self.color, }
def run(self): try: status = self._mpd_command(self.s, "status") playback_state = status["state"] if playback_state == "stop": currentsong = {} else: currentsong = self._mpd_command(self.s, "currentsong") or {} except Exception: if self.hide_inactive: self.output = { "full_text": "" } if hasattr(self, "data"): del self.data return fdict = { "pos": int(status.get("song", 0)) + 1, "len": int(status.get("playlistlength", 0)), "status": self.status[playback_state], "volume": int(status.get("volume", 0)), "title": currentsong.get("Title", ""), "album": currentsong.get("Album", ""), "artist": currentsong.get("Artist", ""), "album_artist": currentsong.get("AlbumArtist", ""), "song_length": TimeWrapper(currentsong.get("Time", 0)), "song_elapsed": TimeWrapper(float(status.get("elapsed", 0))), "bitrate": int(status.get("bitrate", 0)), } if not fdict["title"] and "file" in currentsong: fdict["filename"] = '.'.join( basename(currentsong["file"]).split('.')[:-1]) else: fdict["filename"] = "" if self.max_field_len > 0: for key in self.truncate_fields: if len(fdict[key]) > self.max_field_len: fdict[key] = fdict[key][:self.max_field_len - 1] + "…" self.data = fdict full_text = formatp(self.format, **fdict).strip() full_text_len = len(full_text) if full_text_len > self.max_len and self.max_len > 0: shrink = floor((self.max_len - full_text_len) / len(self.truncate_fields)) - 1 for key in self.truncate_fields: fdict[key] = fdict[key][:shrink] + "…" full_text = formatp(self.format, **fdict).strip() color_map = defaultdict(lambda: self.color, self.color_map) self.output = { "full_text": full_text, "color": color_map[playback_state], }
def run(self): try: status = self._mpd_command(self.s, "status") playback_state = status["state"] currentsong = self._mpd_command(self.s, "currentsong") except Exception: if self.hide_inactive: self.output = { "full_text": "" } if hasattr(self, "data"): del self.data return fdict = { "pos": int(status.get("song", 0)) + 1, "len": int(status.get("playlistlength", 0)), "status": self.status[playback_state], "volume": int(status.get("volume", 0)), "title": currentsong.get("Title", ""), "album": currentsong.get("Album", ""), "artist": currentsong.get("Artist", ""), "album_artist": currentsong.get("AlbumArtist", ""), "song_length": TimeWrapper(currentsong.get("Time", 0)), "song_elapsed": TimeWrapper(float(status.get("elapsed", 0))), "bitrate": int(status.get("bitrate", 0)), } if not fdict["title"] and "file" in currentsong: fdict["filename"] = '.'.join( basename(currentsong["file"]).split('.')[:-1]) else: fdict["filename"] = "" if self.max_field_len > 0: for key in self.truncate_fields: if len(fdict[key]) > self.max_field_len: fdict[key] = fdict[key][:self.max_field_len - 1] + "…" self.data = fdict full_text = formatp(self.format, **fdict).strip() full_text_len = len(full_text) if full_text_len > self.max_len and self.max_len > 0: shrink = floor((self.max_len - full_text_len) / len(self.truncate_fields)) - 1 for key in self.truncate_fields: fdict[key] = fdict[key][:shrink] + "…" full_text = formatp(self.format, **fdict).strip() color_map = defaultdict(lambda: self.color, self.color_map) self.output = { "full_text": full_text, "color": color_map[playback_state], }
def run(self): urgent = False color = self.color try: battery = Battery.create(self.path) except FileNotFoundError: self.output = { "full_text": self.not_present_text, "color": self.not_present_color, } return fdict = { "battery_ident": self.battery_ident, "percentage": battery.percentage(), "percentage_design": battery.percentage(design=True), "consumption": battery.consumption(), "remaining": TimeWrapper(0, "%E%h:%M"), "bar": make_bar(battery.percentage()), } status = battery.status() if status in ["Charging", "Discharging"]: remaining = battery.remaining() fdict["remaining"] = TimeWrapper(remaining * 60, "%E%h:%M") if status == "Discharging": fdict["status"] = "DIS" if battery.percentage() <= self.alert_percentage: urgent = True color = self.critical_color else: fdict["status"] = "CHR" color = self.charging_color else: fdict["status"] = "FULL" color = self.full_color if self.alert and fdict["status"] == "DIS" and fdict[ "percentage"] <= self.alert_percentage: DesktopNotification( title=formatp(self.alert_format_title, **fdict), body=formatp(self.alert_format_body, **fdict), icon="battery-caution", urgency=2, timeout=60, ).display() fdict["status"] = self.status[fdict["status"]] self.output = { "full_text": formatp(self.format, **fdict), "instance": self.battery_ident, "urgent": urgent, "color": color, }
def run(self): urgent = False color = self.color try: battery = Battery.create(self.path) except FileNotFoundError: self.output = { "full_text": self.not_present_text, "color": self.not_present_color, } return fdict = { "battery_ident": self.battery_ident, "percentage": battery.percentage(), "percentage_design": battery.percentage(design=True), "consumption": battery.consumption(), "remaining": TimeWrapper(0, "%E%h:%M"), "bar": make_bar(battery.percentage()), } status = battery.status() if status in ["Charging", "Discharging"]: remaining = battery.remaining() fdict["remaining"] = TimeWrapper(remaining * 60, "%E%h:%M") if status == "Discharging": fdict["status"] = "DIS" if battery.percentage() <= self.alert_percentage: urgent = True color = self.critical_color else: fdict["status"] = "CHR" color = self.charging_color else: fdict["status"] = "FULL" color = self.full_color if self.alert and fdict["status"] == "DIS" and fdict["percentage"] <= self.alert_percentage: DesktopNotification( title=formatp(self.alert_format_title, **fdict), body=formatp(self.alert_format_body, **fdict), icon="battery-caution", urgency=2, timeout=60, ).display() fdict["status"] = self.status[fdict["status"]] self.output = { "full_text": formatp(self.format, **fdict), "instance": self.battery_ident, "urgent": urgent, "color": color, }
def run(self): try: status = self._mpd_command(self.s, "status") currentsong = self._mpd_command(self.s, "currentsong") except Exception: if self.hide_inactive: self.output = { "full_text": "" } return fdict = { "pos": int(status.get("song", 0)) + 1, "len": int(status.get("playlistlength", 0)), "status": self.status[status["state"]], "volume": int(status.get("volume", 0)), "title": currentsong.get("Title", ""), "album": currentsong.get("Album", ""), "artist": currentsong.get("Artist", ""), "song_length": TimeWrapper(currentsong.get("Time", 0)), "song_elapsed": TimeWrapper(float(status.get("elapsed", 0))), "bitrate": int(status.get("bitrate", 0)), } if not fdict["title"] and "filename" in fdict: fdict["filename"] = '.'.join( basename(currentsong["file"]).split('.')[:-1]) else: fdict["filename"] = "" if self.max_field_len > 0: for key in self.truncate_fields: if len(fdict[key]) > self.max_field_len: fdict[key] = fdict[key][:self.max_field_len - 1] + "…" full_text = formatp(self.format, **fdict).strip() full_text_len = len(full_text) if full_text_len > self.max_len and self.max_len > 0: shrink = floor((self.max_len - full_text_len) / len(self.truncate_fields)) - 1 for key in self.truncate_fields: fdict[key] = fdict[key][:shrink] + "…" full_text = formatp(self.format, **fdict).strip() self.output = { "full_text": full_text, "color": self.color, }
def run(self): urgent = False color = "#ffffff" battery = Battery.create(self.path) fdict = { "battery_ident": self.battery_ident, "percentage": battery.percentage(), "percentage_design": battery.percentage(design=True), "consumption": battery.consumption(), "remaining": TimeWrapper(0, "%E%h:%M"), } icon=self.icon_full if fdict["percentage"] > 50 and fdict["percentage"] < 250: icon = self.icon_full elif fdict["percentage"] <= 50 and fdict["percentage"] > 10: icon = self.icon_half status = battery.status() if status in ["Charging", "Discharging"]: remaining = battery.remaining() fdict["remaining"] = TimeWrapper(remaining * 60, "%E%h:%M") if status == "Discharging": fdict["status"] = "DIS" if battery.percentage() <= self.alert_percentage: urgent = True color = "#ff0000" else: fdict["status"] = "CHR" else: fdict["status"] = "FULL" if self.alert and fdict["status"] == "DIS" and fdict["percentage"] <= self.alert_percentage: DesktopNotification( title=formatp(self.alert_format_title, **fdict), body=formatp(self.alert_format_body, **fdict), icon="battery-caution", urgency=2, timeout=60, ).display() fdict["status"] = self.status[fdict["status"]] self.output = { "full_text": formatp(self.format, **fdict).strip(), "instance": self.battery_ident, "urgent": urgent, "color": color, "icon": icon }
def run(self): response = self._query_cmus() if response: fdict = { 'file': response.get('file', ''), 'status': self.status[response['status']], 'title': response.get('tag_title', ''), 'stream': response.get('stream', ''), 'album': response.get('tag_album', ''), 'artist': response.get('tag_artist', ''), 'tracknumber': response.get('tag_tracknumber', 0), 'song_length': TimeWrapper(response.get('duration', 0)), 'song_elapsed': TimeWrapper(response.get('position', 0)), 'bitrate': int(response.get('bitrate', 0)), } if fdict['stream']: fdict['artist'], fdict['title'] = _extract_artist_title( fdict['stream']) elif not fdict['title']: filename = os.path.basename(fdict['file']) filebase, _ = os.path.splitext(filename) fdict['artist'], fdict['title'] = _extract_artist_title( filebase) self.output = { "full_text": formatp(self.format, **fdict), "color": self.color } else: self.output = { "full_text": self.format_not_running, "color": self.color_not_running }
def run(self): try: status = self._mpd_command(self.s, "status") currentsong = self._mpd_command(self.s, "currentsong") fdict = { "pos": int(status.get("song", 0)) + 1, "len": int(status["playlistlength"]), "status": self.status[status["state"]], "volume": int(status["volume"]), "title": currentsong.get("Title", ""), "album": currentsong.get("Album", ""), "artist": currentsong.get("Artist", ""), "song_length": TimeWrapper(currentsong.get("Time", 0)), "song_elapsed": TimeWrapper(float(status.get("elapsed", 0))), "bitrate": int(status.get("bitrate", 0)), } if not fdict["title"] and "filename" in fdict: fdict["filename"] = '.'.join( basename(currentsong["file"]).split('.')[:-1]) else: fdict["filename"] = "" self.output = { "full_text": formatp(self.format, **fdict).strip(), "color": self.color, } except Exception as e: self.output = {"full_text": "error connecting MPD", "color": self.color}
def run(self): status = self._query_cmus() fdict = { 'file': status.get('file', ''), 'status': self.status[status["status"]], 'title': status.get('tag_title', ''), 'stream': status.get('stream', ''), 'album': status.get('tag_album', ''), 'artist': status.get('tag_artist', ''), 'tracknumber': status.get('tag_tracknumber', 0), 'song_length': TimeWrapper(status.get('duration', 0)), 'song_elapsed': TimeWrapper(status.get('position', 0)), 'bitrate': int(status.get("bitrate", 0)), } if fdict['stream']: fdict['artist'], fdict['title'] = ( fdict['stream'].split('-') + [''] * 2)[:2] elif not fdict['title']: _, filename = os.path.split(fdict['file']) filebase, _ = os.path.splitext(filename) fdict['artist'], fdict['title'] = ( filebase.split('-') + [''] * 2)[:2] self.output = { "full_text": formatp(self.format, **fdict), "color": self.color }
def run(self): status = self._query_cmus() if not status: self.output = {"full_text": "Not running", "color": self.color} return fdict = { "file": status.get("file", ""), "status": self.status[status["status"]], "title": status.get("tag_title", ""), "stream": status.get("stream", ""), "album": status.get("tag_album", ""), "artist": status.get("tag_artist", ""), "tracknumber": status.get("tag_tracknumber", 0), "song_length": TimeWrapper(status.get("duration", 0)), "song_elapsed": TimeWrapper(status.get("position", 0)), "bitrate": int(status.get("bitrate", 0)), } if fdict["stream"]: fdict["artist"], fdict["title"] = _extract_artist_title(fdict["stream"]) elif not fdict["title"]: _, filename = os.path.split(fdict["file"]) filebase, _ = os.path.splitext(filename) fdict["artist"], fdict["title"] = _extract_artist_title(filebase) fdict["title"] = fdict["title"].strip() fdict["artist"] = fdict["artist"].strip() self.output = {"full_text": formatp(self.format, **fdict), "color": self.color}
def run(self): self.output = {} response = self._query_cmus() if response: fdict = { 'file': response.get('file', ''), 'status': self.status[response['status']], 'title': response.get('tag_title', ''), 'stream': response.get('stream', ''), 'album': response.get('tag_album', ''), 'artist': response.get('tag_artist', ''), 'tracknumber': response.get('tag_tracknumber', 0), 'song_length': TimeWrapper(response.get('duration', 0)), 'song_elapsed': TimeWrapper(response.get('position', 0)), 'bitrate': int(response.get('bitrate', 0)), } if fdict['stream']: fdict['artist'], fdict['title'] = _extract_artist_title(fdict['stream']) elif not fdict['title']: filename = os.path.basename(fdict['file']) filebase, _ = os.path.splitext(filename) fdict['artist'], fdict['title'] = _extract_artist_title(filebase) self.output['full_text'] = formatp(self.format, **fdict) self.output['color'] = self.color else: self.output['full_text'] = self.format_not_running self.output['color'] = self.color_not_running
def run(self): with socket.create_connection((self.host, self.port)) as s: # Skip "OK MPD ..." s.recv(8192) fdict = {} status = self._mpd_command(s, "status") currentsong = self._mpd_command(s, "currentsong") fdict = { "pos": int(status.get("song", 0)) + 1, "len": int(status["playlistlength"]), "status": self.status[status["state"]], "volume": int(status["volume"]), "title": currentsong.get("Title", ""), "album": currentsong.get("Album", ""), "artist": currentsong.get("Artist", ""), "song_length": TimeWrapper(currentsong.get("Time", 0)), "song_elapsed": TimeWrapper(float(status.get("elapsed", 0))), "bitrate": int(status.get("bitrate", 0)), } self.output = { "full_text": formatp(self.format, **fdict).strip(), }
def run(self): response = self._query_moc() if response: fdict = { 'album': response.get('Album', ''), 'artist': response.get('Artist', ''), 'file': response.get('File', ''), 'song_elapsed': TimeWrapper(response.get('CurrentSec', 0)), 'song_length': TimeWrapper(response.get('TotalSec', 0)), 'status': self.status[response['State'].lower()], 'title': response.get('SongTitle', ''), 'tracknumber': re.match(r'(\d*).*', response.get('Title', '')).group(1) or 0, } self.data = fdict self.output = { 'full_text': formatp(self.format, **self.data), 'color': self.color, } else: if hasattr(self, "data"): del self.data self.output = { 'full_text': self.format_not_running, 'color': self.color_not_running, }
def set_output(self, events): events = sorted( [e for e in events if e["action"] != "resolve" and not e["silenced"]], key=lambda x: x["last_ok"], reverse=True ) last_event_output = "" if not events: status = "OK" color = self.color_ok else: error = None try: error = next(e for e in events if e["check"]["status"] == SensuStatus.critical) except StopIteration: last_event = events[0] else: last_event = error status = "{} event(s)".format(len(events)) color = self.color_error if error else self.color_warn last_event_output = self.get_event_output(last_event) self.output = { "full_text": formatp(self.format, status=status, last_event=last_event_output), "color": color, }
def run(self): with open(self.file, "r") as f: seconds = int(float(f.read().split()[0])) raw_seconds = seconds days = seconds // (60 * 60 * 24) hours = seconds // (60 * 60) minutes = seconds // 60 if "{days}" in self.format: hours = (seconds % (60 * 60 * 24)) // (60 * 60) minutes = (seconds % (60 * 60 * 24)) // 60 seconds = (seconds % (60 * 60 * 24)) if "{hours}" in self.format: minutes = (seconds % (60 * 60)) // 60 seconds = (seconds % (60 * 60)) if "{mins}" in self.format: seconds = seconds % 60 fdict = { "days": days, "hours": hours, "mins": minutes, "secs": seconds, "uptime": "{}:{}".format(hours, minutes), } self.data = fdict if self.alert: if raw_seconds > self.seconds_alert: self.color = self.color_alert self.output = { "full_text": formatp(self.format, **fdict), "color": self.color }
def set_output(self, events): events = sorted([ e for e in events if e["action"] != "resolve" and not e["silenced"] ], key=lambda x: x["last_ok"], reverse=True) last_event_output = "" if not events: status = "OK" color = self.color_ok else: error = None try: error = next(e for e in events if e["check"]["status"] == SensuStatus.critical) except StopIteration: last_event = events[0] else: last_event = error status = "{} event(s)".format(len(events)) color = self.color_error if error else self.color_warn last_event_output = self.get_event_output(last_event) self.output = { "full_text": formatp(self.format, status=status, last_event=last_event_output), "color": color, }
def run(self): command = ["curl", "api.ipify.org"] try: p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL) ip = p.communicate(timeout=self.timeout)[0].decode().strip() except Exception: return self.disable() gi = GeoIP.GeoIP(GeoIP.GEOIP_STANDARD) country_code = gi.country_code_by_addr(ip) country_name = gi.country_name_by_addr(ip) if not ip or not country_code: return self.disable() fdict = { "country_name": country_name, "country_code": country_code, "ip": ip } self.output = { "full_text": formatp(self.format, **fdict).strip(), "color": self.color }
def run(self): status = self._query_cmus() if not status: self.output = {"full_text": 'Not running', "color": self.color} return fdict = { 'file': status.get('file', ''), 'status': self.status[status["status"]], 'title': status.get('tag_title', ''), 'stream': status.get('stream', ''), 'album': status.get('tag_album', ''), 'artist': status.get('tag_artist', ''), 'tracknumber': status.get('tag_tracknumber', 0), 'song_length': TimeWrapper(status.get('duration', 0)), 'song_elapsed': TimeWrapper(status.get('position', 0)), 'bitrate': int(status.get("bitrate", 0)), } if fdict['stream']: fdict['artist'], fdict['title'] = _extract_artist_title( fdict['stream']) elif not fdict['title']: _, filename = os.path.split(fdict['file']) filebase, _ = os.path.splitext(filename) fdict['artist'], fdict['title'] = _extract_artist_title(filebase) fdict['title'] = fdict['title'].strip() fdict['artist'] = fdict['artist'].strip() self.output = { "full_text": formatp(self.format, **fdict), "color": self.color }
def run(self): """Main statement, executes all code every interval""" # tries to create player object and get data from player try: self.player = Playerctl.Player() response = self.get_info(self.player) # creates a dictionary of the spotify data captured fdict = { 'status': self.status[response['status'].lower()], 'title': response["title"], 'album': response.get('album', ''), 'artist': response.get('artist', ''), 'length': response.get('length', 0), } self.data = fdict self.output = {"full_text": formatp(self.format, **fdict), "color": self.color} # outputs the not running string if spotify is closed except: self.output = {"full_text": self.format_not_running, "color": self.color_not_running} if hasattr(self, "data"): del self.data
def run(self): try: player = self.get_player() properties = dbus.Interface(player, "org.freedesktop.DBus.Properties") def get_prop(name, default=None): try: return properties.Get("org.mpris.MediaPlayer2.Player", name) except dbus.exceptions.DBusException: return default currentsong = get_prop("Metadata") fdict = { "status": self.status[self.statusmap[get_prop("PlaybackStatus")]], "len": 0, # TODO: Use optional(!) TrackList interface for this to gain 100 % mpd<->now_playing compat "pos": 0, "volume": int(get_prop("Volume", 0) * 100), "title": currentsong.get("xesam:title", ""), "album": currentsong.get("xesam:album", ""), "artist": ", ".join(currentsong.get("xesam:artist", "")), "song_length": TimeWrapper((currentsong.get("mpris:length") or 0) / 1000 ** 2), "song_elapsed": TimeWrapper((get_prop("Position") or 0) / 1000 ** 2), "filename": "", } if not fdict["title"]: fdict["filename"] = '.'.join( basename((currentsong.get("xesam:url") or "")).split('.')[:-1]) self.data = fdict self.output = { "full_text": formatp(self.format, **fdict).strip(), "color": self.color, } except NoPlayerException: if self.hide_no_player: self.output = None else: self.output = { "full_text": self.format_no_player, "color": self.color_no_player, } if hasattr(self, "data"): del self.data return except dbus.exceptions.DBusException as e: if self.hide_no_player: self.output = None else: self.output = { "full_text": "DBus error: " + e.get_dbus_message(), "color": "#ff0000", } if hasattr(self, "data"): del self.data return
def run(self): format_values = dict(kbs="", network_graph="", bytes_sent="", bytes_recv="", packets_sent="", packets_recv="", rx_tot_Mbytes="", tx_tot_Mbytes="", interface="", v4="", v4mask="", v4cidr="", v6="", v6mask="", v6cidr="", mac="", essid="", freq="", quality="", quality_bar="") if self.network_traffic: network_usage = self.network_traffic.get_usage(self.interface) format_values.update(network_usage) if self.graph_type == 'input': limit = self.recv_limit kbs = network_usage['bytes_recv'] * self.divisor / 1024 elif self.graph_type == 'output': limit = self.sent_limit kbs = network_usage['bytes_sent'] * self.divisor / 1024 else: raise Exception("graph_type must be either 'input' or 'output'!") format_values['network_graph'] = self.get_network_graph(kbs, limit) format_values['kbs'] = "{0:.1f}".format(round(kbs, 2)) if self.separate_color and self.pango_enabled: color = self.color_up color_template = "<span color=\"{}\">{}</span>" per_recv = network_usage["bytes_recv"] * self.divisor / (self.recv_limit * 1024) per_sent = network_usage["bytes_sent"] * self.divisor / (self.sent_limit * 1024) c_recv = self.get_gradient(int(per_recv * 100), self.colors, 100) c_sent = self.get_gradient(int(per_sent * 100), self.colors, 100) format_values["bytes_recv"] = color_template.format(c_recv, network_usage["bytes_recv"]) format_values["bytes_sent"] = color_template.format(c_sent, network_usage["bytes_sent"]) if self.graph_type == 'output': c_kbs = c_sent else: c_kbs = c_recv format_values['network_graph'] = color_template.format(c_kbs, format_values["network_graph"]) format_values['kbs'] = color_template.format(c_kbs, format_values["kbs"]) else: percent = int(kbs * 100 / limit) color = self.get_gradient(percent, self.colors, 100) else: color = None if sysfs_interface_up(self.interface, self.unknown_up): if not color: color = self.color_up format_str = self.format_up else: color = self.color_down format_str = self.format_down if self.next_if_down: self.cycle_interface() network_info = self.network_info.get_info(self.interface) format_values.update(network_info) format_values['interface'] = self.interface self.data = format_values self.output = { "full_text": formatp(format_str, **format_values).strip(), 'color': color, }
def run(self): status = self._mpd_command(self.s, "status") currentsong = self._mpd_command(self.s, "currentsong") fdict = { "pos": int(status.get("song", 0)) + 1, "len": int(status["playlistlength"]), "status": self.status[status["state"]], "volume": int(status["volume"]), "title": currentsong.get("Title", ""), "album": currentsong.get("Album", ""), "artist": currentsong.get("Artist", ""), "song_length": TimeWrapper(currentsong.get("Time", 0)), "song_elapsed": TimeWrapper(float(status.get("elapsed", 0))), "bitrate": int(status.get("bitrate", 0)), } for key in self.truncate_fields: if len(fdict[key]) > self.text_len: fdict[key] = fdict[key][:self.text_len - 1] + "…" if not fdict["title"] and "filename" in fdict: fdict["filename"] = '.'.join( basename(currentsong["file"]).split('.')[:-1]) else: fdict["filename"] = "" self.output = { "full_text": formatp(self.format, **fdict).strip(), "color": self.color, }
def run(self): """Main statement, executes all code every interval""" # tries to create player object and get data from player try: self.player = Playerctl.Player(player_name="spotify") response = self.get_info(self.player) # creates a dictionary of the spotify data captured fdict = { 'status': self.status[response['status'].lower()], 'title': response["title"], 'album': response.get('album', ''), 'artist': response.get('artist', ''), 'length': response.get('length', 0), } self.data = fdict self.output = {"full_text": formatp(self.format, **fdict), "color": self.color} # outputs the not running string if spotify is closed except: self.output = {"full_text": self.format_not_running, "color": self.color_not_running} if hasattr(self, "data"): del self.data
def run(self): try: self.devices = get_bluetooth_device_list(self.show_disconnected) if len(self.devices) < 1: if hasattr(self, "data"): del self.data self.output = None return self.dev_index = self.dev_index % len(self.devices) self.num_devices = len(self.devices) fdict = { "name": self.devices[self.dev_index]['name'], "dev_addr": self.devices[self.dev_index]['dev_addr'] } self.data = fdict color = self.color if self.devices[self.dev_index]['connected']: color = self.connected_color self.output = { "full_text": formatp(self.format, **fdict).strip(), "color": color, } return except dbus.exceptions.DBusException as e: self.output = { "full_text": "DBus error: " + e.get_dbus_message(), "color": "#ff0000", } if hasattr(self, "data"): del self.data return
def run(self): try: status = self._mpd_command(self.s, "status") currentsong = self._mpd_command(self.s, "currentsong") fdict = { "pos": int(status.get("song", 0)) + 1, "len": int(status["playlistlength"]), "status": self.status[status["state"]], "volume": int(status["volume"]), "title": currentsong.get("Title", ""), "album": currentsong.get("Album", ""), "artist": currentsong.get("Artist", ""), "song_length": TimeWrapper(currentsong.get("Time", 0)), "song_elapsed": TimeWrapper(float(status.get("elapsed", 0))), "bitrate": int(status.get("bitrate", 0)), } if not fdict["title"]: fdict["filename"] = '.'.join( basename(currentsong["file"]).split('.')[:-1]) else: fdict["filename"] = "" self.output = { "full_text": formatp(self.format, **fdict).strip(), "color": self.color, } except Exception as e: self.output = { "full_text": "error connecting MPD", "color": self.color }
def run(self): urgent = False color = "#ffffff" battery = Battery.create(self.path) fdict = { "battery_ident": self.battery_ident, "percentage": battery.percentage(), "percentage_design": battery.percentage(design=True), "consumption": battery.consumption(), "remaining": TimeWrapper(0, "%E%h:%M"), } status = battery.status() if status in ["Charging", "Discharging"]: remaining = battery.remaining() fdict["remaining"] = TimeWrapper(remaining * 60, "%E%h:%M") if status == "Discharging": fdict["status"] = "DIS" if battery.percentage() <= self.alert_percentage: urgent = True color = "#ff0000" else: fdict["status"] = "CHR" else: fdict["status"] = "FULL" if self.alert and fdict["status"] == "DIS" and fdict[ "percentage"] <= self.alert_percentage: DesktopNotification( title=formatp(self.alert_format_title, **fdict), body=formatp(self.alert_format_body, **fdict), icon="battery-caution", urgency=2, timeout=60, ).display() fdict["status"] = self.status[fdict["status"]] self.output = { "full_text": formatp(self.format, **fdict).strip(), "instance": self.battery_ident, "urgent": urgent, "color": color }
def report(self): DesktopNotification( title=formatp(self.format_summary, **self.data).strip(), body="\n".join(self.notif_body.values()), icon=self.notification_icon, urgency=1, timeout=0, ).display()
def run(self): if self.current_event and self.current_event.time_remaining > timedelta(seconds=0): self.output = { "full_text": formatp(self.format, **self.current_event.formatters()), "color": self.get_color() if self.dynamic_color else None, "urgent": self.is_urgent() } else: self.output = {}
def run(self): data = self.backend.weather_data() data['icon'], condition_color = self.get_color_data(data['condition']) color = condition_color if self.colorize else self.color self.output = { 'full_text': formatp(self.format, **data).strip(), 'color': color, }
def run(self): fdict = { "status": self.status[self.current_phase()], "illum": self.illum(), } self.output = { "full_text": formatp(self.format, **fdict), "color": self.color[self.current_phase()], }
def refresh_display(self): self.logger.debug('Weather data: %s', self.backend.data) self.backend.data['icon'], condition_color = \ self.get_color_data(self.backend.data['condition']) color = condition_color if self.colorize else self.color self.output = { 'full_text': formatp(self.format, **self.backend.data).strip(), 'color': color, }
def run(self): """Main statement, executes all code every interval""" self.player = pctl.Player(player_name=self.player_name) fdict = self.get_formatted_info(self.player) if fdict.get("status", ""): self.output = {"full_text": formatp(self.format, **fdict), "color": self.color} else: self.output = {"full_text": self.format_not_running, "color": self.color_not_running}
def run(self): fdict = { "temperature": self.temperature, } output = formatp(self.format, **fdict) color = self.color self.output = { "full_text": output, "color": color, }
def refresh_display(self): previous_color = self.output.get('color') try: color = self.colors.get( self.current_status, self.unknown_color) except TypeError: # Shouldn't get here, but this would happen if this function is # called before we check the current status for the first time. color = previous_color self.output = {'full_text': formatp(self.format, **self.data).strip(), 'color': color}
def run(self): if self.current_event and self.current_event.time_remaining > timedelta( seconds=0): self.output = { "full_text": formatp(self.format, **self.current_event.formatters()), "color": self.get_color() if self.dynamic_color else None, "urgent": self.is_urgent() } else: self.output = {}
def alert_if_low_battery(self, fdict): if self.use_design_percentage: percentage = fdict['percentage_design'] else: percentage = fdict['percentage'] if self.alert and fdict[ "status"] == "DIS" and percentage <= self.alert_percentage: title, body = formatp(self.alert_format_title, **fdict), formatp(self.alert_format_body, **fdict) if self.notification is None: self.notification = DesktopNotification( title=title, body=body, icon="battery-caution", urgency=2, timeout=self.alert_timeout, ) self.notification.display() else: self.notification.update(title=title, body=body)
def update_output(self): fdict = { "vpn_name" : self.vpn_name, } self.output = { "full_text" : i3pystatus.formatp(self.format, **fdict), } if not self.enabled: self.output["color"] = self.color_disabled self.send_output()
def run(self): with open(self.file,'r') as f: seconds = float(f.read().split()[0]) fdict = { "uptime" : TimeWrapper(seconds, "%h:%m"), } if self.alert: if seconds > self.seconds_alert: self.color = self.color_alert self.output = { "full_text": formatp(self.format, **fdict), "color": self.color }
def check_updates(self): self.output = { "full_text": formatp(self.format_working, **self.data).strip(), "color": self.color_working, } updates_count = 0 for backend in self.backends: updates = backend.updates updates_count += updates self.data[backend.__class__.__name__] = updates if updates_count == 0: self.output = {} if not self.format_no_updates else { "full_text": self.format_no_updates, "color": self.color_no_updates, } return self.data["count"] = updates_count self.output = { "full_text": formatp(self.format, **self.data).strip(), "color": self.color, }
def run(self): """Main statement, executes all code every interval""" self.player = pctl.Player(player_name=self.player_name) fdict = self.get_formatted_info(self.player) if fdict.get("status", ""): self.output = { "full_text": formatp(self.format, **fdict), "color": self.color } else: self.output = { "full_text": self.format_not_running, "color": self.color_not_running }
def run(self): ip = self.get_external_ip() if not ip: return self.disable() gi = GeoIP.GeoIP(GeoIP.GEOIP_STANDARD) country_code = gi.country_code_by_addr(ip) country_name = gi.country_name_by_addr(ip) if not country_code: return self.disable() # fail here in the case of a bad IP fdict = {"country_name": country_name, "country_code": country_code, "ip": ip} self.output = {"full_text": formatp(self.format, **fdict).strip(), "color": self.color}
def run(self): try: player = self.get_player() except dbus.exceptions.DBusException: self.output = { "full_text": "now_playing: d-bus error", "color": "#ff0000", } return properties = dbus.Interface(player, "org.freedesktop.DBus.Properties") get_prop = functools.partial(properties.Get, "org.mpris.MediaPlayer2.Player") currentsong = get_prop("Metadata") fdict = { "status": self.status[self.statusmap[get_prop("PlaybackStatus")]], "len": 0, # TODO: Use optional(!) TrackList interface for this to gain 100 % mpd<->now_playing compat "pos": 0, "volume": int(get_prop("Volume") * 100), "title": currentsong.get("xesam:title", ""), "album": currentsong.get("xesam:album", ""), "artist": ", ".join(currentsong.get("xesam:artist", "")), "song_length": TimeWrapper((currentsong.get("mpris:length") or 0) / 1000**2), "song_elapsed": TimeWrapper((get_prop("Position") or 0) / 1000**2), "filename": "", } if not fdict["title"]: fdict["filename"] = '.'.join( basename((currentsong.get("xesam:url") or "")).split('.')[:-1]) self.output = { "full_text": formatp(self.format, **fdict).strip(), "color": self.color, }
def run(self): if self.error: fdict = {"error": self.error} color = self.error_color else: fdict = { "inhibit": self.format_inhibit[int(self.inhibit)], "period": self.period, "temperature": self.temperature, "latitude": self.latitude, "longitude": self.longitude, } color = self.color self.output = { "full_text": formatp(self.format, **fdict), "color": color, }
def run(self): updates_count = 0 for backend in self.backends: updates_count += backend.updates if updates_count == 0: self.output = {} if not self.format_no_updates else { "full_text": self.format_no_updates, "color": self.color_no_updates, } return fdict = { "count": updates_count, } self.output = { "full_text": formatp(self.format, **fdict).strip(), "color": self.color, }
def run(self): if self._controller.is_alive(): self.update_values() fdict = { "inhibit": self.format_inhibit[int(self.inhibit)], "period": self.period, "temperature": self.temperature, "latitude": self.latitude, "longitude": self.longitude, } output = formatp(self.format, **fdict) color = self.color else: output = "redshift exited unexpectedly" color = self.error_color self.output = { "full_text": output, "color": color, }
def run(self): try: status = self._mpd_command(self.s, "status") currentsong = self._mpd_command(self.s, "currentsong") fdict = { "pos": int(status.get("song", 0)) + 1, "len": int(status["playlistlength"]), "status": self.status[status["state"]], "volume": int(status["volume"]), "title": currentsong.get("Title", ""), "album": currentsong.get("Album", ""), "artist": currentsong.get("Artist", ""), "song_length": TimeWrapper(currentsong.get("Time", 0)), "song_elapsed": TimeWrapper(float(status.get("elapsed", 0))), "bitrate": int(status.get("bitrate", 0)), } self.output = { "full_text": formatp(self.format, **fdict).strip(), } except Exception as e: self.output = {"full_text": "error connecting MPD"}
def run(self): ip = self.get_external_ip() if not ip: return self.disable() gi = GeoIP.GeoIP(GeoIP.GEOIP_STANDARD) country_code = gi.country_code_by_addr(ip) country_name = gi.country_name_by_addr(ip) if not country_code: return self.disable() # fail here in the case of a bad IP fdict = { "country_name": country_name, "country_code": country_code, "ip": ip } self.output = { "full_text": formatp(self.format, **fdict).strip(), "color": self.color }
def refresh_display(self): if self.current_scroll_index is None: output = self.current_backend.format_no_games color = self.color_no_games else: game = copy.copy(self.current_game) fstr = str(getattr( self.current_backend, 'format_%s' % game['status'] )) for team in ('home', 'away'): abbrev_key = '%s_abbrev' % team # Set favorite icon, if applicable game['%s_favorite' % team] = self.favorite_icon \ if game[abbrev_key] in self.current_backend.favorite_teams \ else '' if self.colorize_teams: # Wrap in Pango markup color = self.current_backend.team_colors.get( game.get(abbrev_key) ) if color is not None: for item in ('abbrev', 'city', 'name', 'name_short'): key = '%s_%s' % (team, item) if key in game: val = '<span color="%s">%s</span>' % (color, game[key]) game[key] = val game['scroll'] = self.scroll_arrow \ if len(self.current_backend.games) > 1 \ else '' output = formatp(fstr, **game).strip() self.output = {'full_text': output, 'color': self.color}