From 78f7be4e4b6501b15b5fefc9f7824bbadf0daf2a Mon Sep 17 00:00:00 2001 From: Weitian LI Date: Fri, 13 Jun 2014 21:12:21 +0800 Subject: Added various dotfiles. * Xresources * profile, xprofile, xinitrc * bash (aliases, logout, profile, rc, completion) * gitconfig * gtkrc and gtk-bookmarks * i3 configs (with py3status configs) * i3status.conf * lftp/rc * tmux.conf * xbindkeysrc * mpdconf * ncmpcpp (config and keys) * sbclrc * vifm (vifmrc, colors) * urxvt (perl extensions) * conkyrc (and conky/cronograph configs) --- .i3/py3status/80-datetime.py | 76 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 .i3/py3status/80-datetime.py (limited to '.i3/py3status/80-datetime.py') diff --git a/.i3/py3status/80-datetime.py b/.i3/py3status/80-datetime.py new file mode 100644 index 0000000..5d578a0 --- /dev/null +++ b/.i3/py3status/80-datetime.py @@ -0,0 +1,76 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# +# Weitian LI +# 2014/05/15 + +""" +datetime module for py3status +""" + +## Get output of shell command: +## python 3.x: +## >>> subprocess.getoutput(cmd) +## >>> subprocess.getstatusoutput(cmd) +## python 2.7.x: +## >>> subprocess.Popen(cmd, shell=True, stderr=subprocess.PIPE) + +import re +import subprocess +import time + + +# regext to match date and time from output of 'date' +datetime_p = re.compile(r'(^\d+/\d+)\s*(\d+:\d+)') + + +class Py3status: + """ + Datetime module to show current date and time. + """ + + def mydate(self, i3status_output_json, i3status_config): + """ + Display current date. + """ + POSITION = 0 + response = { + 'full_text': '', + 'name': 'mydate', + 'instance': 'first', + } + prompt = '' # Icons: uF073 (calendar) + # update datetime + self._get_datetime() + response['full_text'] = '{0} {1}'.format(prompt, self.date) + # cache status for 5 seconds + response['cached_until'] = time.time() + 5 + return (POSITION, response) + + def mytime(self, i3status_output_json, i3status_config): + """ + Display current time. + """ + POSITION = 1 + response = { + 'full_text': '', + 'name': 'mytime', + 'instance': 'first', + } + prompt = '' # Icons: uF017 (clock) + # update datetime + self._get_datetime() + response['full_text'] = '{0} {1}'.format(prompt, self.time) + # cache status for 5 seconds + response['cached_until'] = time.time() + 5 + return (POSITION, response) + + def _get_datetime(self): + """ + Get current date and time + """ + cmd = 'date "+%m/%d %H:%M"' + datetime = subprocess.getoutput(cmd) + dt_m = datetime_p.match(datetime) + self.date, self.time = dt_m.group(1, 2) + -- cgit v1.2.2