aboutsummaryrefslogtreecommitdiffstats
path: root/.i3/py3status/80-datetime.py
diff options
context:
space:
mode:
authorWeitian LI <liweitianux@gmail.com>2014-06-13 21:12:21 +0800
committerWeitian LI <liweitianux@gmail.com>2014-06-13 21:12:21 +0800
commit78f7be4e4b6501b15b5fefc9f7824bbadf0daf2a (patch)
treeb761e28709e4a6f45458c323b8870150827ef831 /.i3/py3status/80-datetime.py
parente1ce158f65c472b7c8d14c04fce94c85bc881a6c (diff)
downloaddotfiles-78f7be4e4b6501b15b5fefc9f7824bbadf0daf2a.tar.bz2
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)
Diffstat (limited to '.i3/py3status/80-datetime.py')
-rw-r--r--.i3/py3status/80-datetime.py76
1 files changed, 76 insertions, 0 deletions
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 <liweitianux@gmail.com>
+# 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)
+