Skip to content

Commit 6fae18b

Browse files
committed
datemagic
1 parent 99b3c1a commit 6fae18b

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

ipython_magic/datemagic.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
__version__ == '1.0.0'
2+
13
"""
24
IPython magic function for printing basic information, such as the current date, time,
35
Python, and IPython version.
@@ -23,6 +25,7 @@
2325
import platform
2426
from time import strftime
2527
from platform import python_version
28+
from pkg_resources import get_distribution
2629

2730
import IPython
2831
from IPython.core.magic import Magics, magics_class, line_magic
@@ -37,10 +40,13 @@ class DateMagic(Magics):
3740
"""
3841
@magic_arguments()
3942
@argument('-d', '--date', action='store_true', help='prints date (default)')
43+
@argument('-dd', '--dateday', action='store_true', help='prints date with abbrv. day and month names')
4044
@argument('-t', '--time', action='store_true', help='print current time')
4145
@argument('-s', '--datetime', action='store_true', help='print current time')
42-
@argument('-p', '--python', action='store_true', help='prints Python version')
46+
@argument('-z', '--timezone', action='store_true', help='prints time zone')
47+
@argument('-y', '--python', action='store_true', help='prints Python version')
4348
@argument('-i', '--ipython', action='store_true', help='prints IPython version')
49+
@argument('-p', '--packages', action=str, help='prints versions of Python modules and packages')
4450
@line_magic
4551
def date(self, line):
4652
"""
@@ -52,10 +58,16 @@ def date(self, line):
5258
out = ''
5359
if args.date:
5460
out += strftime('%d/%m/%Y')
61+
elif arts.dateday:
62+
out += strftime('%a %b %M %Y')
5563
if args.time:
5664
if out:
5765
out += ' '
5866
out += strftime('%H:%M:%S')
67+
if args.timezone:
68+
if out:
69+
out += ' '
70+
out += strftime('%Z')
5971
if args.python:
6072
if out:
6173
out += '\n'
@@ -64,6 +76,10 @@ def date(self, line):
6476
if out:
6577
out += '\n'
6678
out += 'IPython %s' %IPython.__version__
79+
if args.packages:
80+
packages = args.packages.split(',')
81+
for p in packages:
82+
out += '\n%s' %get_distribution(p).version
6783
if not out:
6884
out += strftime('%d/%m/%Y')
6985
print(out)

0 commit comments

Comments
 (0)