Skip to content

Commit

Permalink
Using tabulate to display data in a table
Browse files Browse the repository at this point in the history
  • Loading branch information
btnpushnmunky committed May 18, 2015
1 parent 86c0d21 commit 10560aa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
3 changes: 2 additions & 1 deletion requirements.txt
@@ -1,2 +1,3 @@

tabulate
peewee

21 changes: 9 additions & 12 deletions tmr/main.py
Expand Up @@ -13,7 +13,7 @@

database = SqliteDatabase(os.path.join(user_dir, 'timers.db'))

table_header = "\nId\t| Title\n-------------"
table_header = ("ID", "Title")


class Timer(Model):
Expand Down Expand Up @@ -41,9 +41,8 @@ def start(args):
Timer.create_table(fail_silently=True)
new_timer = Timer.create(title=args.n, started=datetime.now())
new_timer.save()
print("\nStarted: \n{0}".format(table_header))
print("{0}\t| {1}".format(new_timer.id, new_timer.title))
print("\n")
print("Started: ")
print(tabulate([[new_timer.id, new_timer.title]], table_header))


def stop(args):
Expand All @@ -54,22 +53,20 @@ def stop(args):
timer.stopped = datetime.now()
timer.total_time = (timer.stopped - timer.started).total_seconds()
timer.save()
print("\nStopped:\n{0}".format(table_header))
print("{0}\t| {1} \nYou spent {2} seconds on this task.".format(
timer.id, timer.title, timer.total_time))
print("\n")
stopped_header = ["ID", "Title", "Total Time"]
print("Stopped: ")
data = [timer.id, timer.title, timer.total_time]
print(tabulate([data], stopped_header))


def list_timers(args):
"""
List all running timers
"""
timers = Timer.filter(Timer.stopped == None) # noqa
data = [[timer.id, timer.title] for timer in timers]
print("\nRunning timers:")
print("\nId | Title\n-------------")
for timer in timers:
print("{0} | {1}".format(timer.id, timer.title))
print("\n")
print(tabulate(data, table_header))


def export(args):
Expand Down

0 comments on commit 10560aa

Please sign in to comment.