Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
# coding=utf-8
# requirements.txt
# click
import click
import datetime
@click.group()
def cli():
pass
@click.command()
@click.option('--date', default='now', help='The date format "yyyy-mm-dd"')
def get_weekday(date):
if date == 'now':
date = datetime.datetime.utcnow()
else:
date = datetime.datetime.strptime(date, '%Y-%m-%d')
click.echo(date.strftime('%A'))
@click.command()
@click.option('--date1', help='The date format "yyyy-mm-dd"')
@click.option('--date2', help='The date format "yyyy-mm-dd"')
def delta_day(date1, date2):
date1 = datetime.datetime.strptime(date1, '%Y-%m-%d')
date2 = datetime.datetime.strptime(date2, '%Y-%m-%d')
delta = date1 - date2 if date1 > date2 else date2 - date1
click.echo(delta.days)
cli.add_command(get_weekday)
cli.add_command(delta_day)
if __name__ == '__main__':
cli()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment