Skip to content

Commit

Permalink
Add date_added column to torrent
Browse files Browse the repository at this point in the history
  • Loading branch information
archangelic committed Oct 19, 2016
1 parent c27a1fc commit 7f82f7a
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions cistern/cistern.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3

import datetime
import os

import click
Expand All @@ -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'))

Expand Down Expand Up @@ -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
Expand All @@ -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'))


Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 7f82f7a

Please sign in to comment.