Last active
September 13, 2016 05:34
-
-
Save shomah4a/2ffd3a417239149d11b84feed5f4e2a0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#-*- coding:utf-8 -*- | |
from __future__ import print_function | |
import sys | |
import datetime | |
def get_format(): | |
if len(sys.argv) > 1: | |
return sys.argv[1] | |
return '%Y-%m-%dT%H:%M:%S' | |
def print_help(): | |
if '-h' in sys.argv[1:] or '--help' in sys.argv[1:]: | |
print('''Usage | |
{0} [format]'''.format(sys.argv[0])) | |
sys.exit(0) | |
def main(): | |
print_help() | |
fmt = get_format() | |
for line in sys.stdin: | |
t = datetime.datetime.now().strftime(fmt) | |
print('{0}\t{1}'.format(t, line), end='') | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment