From 7f82f7ae55e0e1c448f1bfb338615b4609f45883 Mon Sep 17 00:00:00 2001 From: Mallory Hancock Date: Wed, 19 Oct 2016 13:46:26 -0700 Subject: [PATCH] Add date_added column to torrent --- cistern/cistern.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/cistern/cistern.py b/cistern/cistern.py index 3543529..e418fb0 100755 --- a/cistern/cistern.py +++ b/cistern/cistern.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 +import datetime import os import click @@ -9,6 +10,8 @@ from tabulate import tabulate import transmissionrpc +import migrations + cistern_folder = os.getenv('CISTERNHOME', os.path.join(os.environ['HOME'], '.cistern')) db = SqliteDatabase(os.path.join(cistern_folder, 'cistern.db')) @@ -38,6 +41,7 @@ class Torrent(Model): url = CharField(unique=True) feed = ForeignKeyField(Feed, related_name='torrents') downloaded = BooleanField(default=False) + date_added = DateTimeField(default=datetime.datetime.now) class Meta: database = db @@ -56,6 +60,12 @@ def set_downloaded(self): elif os.path.isfile(os.path.join(cistern_folder, 'cistern.db')): db.connect() +# Check if migration is necessary +try: + t = Torrent.select().first() +except OperationalError: + migrations.update() + config = ConfigObj(os.path.join(cistern_folder, 'config')) @@ -210,10 +220,10 @@ def lister(list_type): downloaded = 'Yes' else: downloaded = 'No' - torrent_list.append([torrent.id, torrent.name, torrent.feed.name, downloaded]) + torrent_list.append([torrent.id, torrent.name, torrent.feed.name, downloaded, torrent.date_added]) tab = tabulate( torrent_list, - ['ID', 'Name', 'Feed', 'Downloaded'] + ['ID', 'Name', 'Feed', 'Downloaded', 'Date Added'] ) click.echo(tab) else: