summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rwxr-xr-xsrc/vgstash/__init__.py10
-rwxr-xr-xsrc/vgstash_cli.py72
2 files changed, 59 insertions, 23 deletions
diff --git a/src/vgstash/__init__.py b/src/vgstash/__init__.py
index dcf6c5b..5184fac 100755
--- a/src/vgstash/__init__.py
+++ b/src/vgstash/__init__.py
@@ -250,7 +250,15 @@ class DB(object):
stmt = "SELECT * FROM games WHERE title=? AND system=?"
res = self.conn.execute(stmt, (title, system)).fetchone()
if bool(res):
- return Game(res['title'], res['system'], res['ownership'], res['progress'], res['notes'])
+ return Game(
+ title = res['title'],
+ system = res['system'],
+ ownership = res['ownership'],
+ progress = res['progress'],
+ notes = res['notes'],
+ p_date = res['p_date'],
+ b_date = res['b_date'],
+ c_date = res['c_date'])
else:
raise KeyError
diff --git a/src/vgstash_cli.py b/src/vgstash_cli.py
index 046443d..ca53576 100755
--- a/src/vgstash_cli.py
+++ b/src/vgstash_cli.py
@@ -126,6 +126,9 @@ def add(title, system, ownership, progress, notes, p_date, b_date, c_date):
def list_games(filter, raw):
db = get_db()
row_data = db.list_games(filter)
+ if len(row_data) == 0:
+ click.echo("No games matching this filter in your collection.")
+ return
if raw:
for r in row_data:
@@ -160,24 +163,36 @@ def list_games(filter, raw):
for r in row_cache:
for i in range(len(columns)):
+ # possible values for r[i]:
+ # title -> str
+ # system -> str
+ # ownership -> int
+ # progress -> int
+ # *_date -> int
# process fields that need massaging for display
- if r[i]:
- if columns[i] == ("p_date"):
- r[i] = vgstash.unix_to_iso(r[i])
- if columns[i] == ("b_date"):
- r[i] = vgstash.unix_to_iso(r[i])
- if columns[i] == ("c_date"):
- r[i] = vgstash.unix_to_iso(r[i])
- if columns[i] == "notes" and len(r[i]) > 0:
- r[i] = "*"
- if columns[i] == "progress":
- r[i] = vgstash.vtok(r[i], vgstash.PROGRESS)[0].capitalize()
- if columns[i] == "ownership":
- r[i] = vgstash.vtok(r[i], vgstash.OWNERSHIP)[0].capitalize()
if r[i] == None:
r[i] = ""
- if isinstance(r[i], int):
- r[i] = str(r[i])
+ else:
+ if columns[i] == "progress":
+ if r[i] == 0:
+ r[i] = ''
+ else:
+ r[i] = vgstash.vtok(r[i], vgstash.PROGRESS)[0].capitalize()
+ if columns[i] == "ownership":
+ if r[i] == 0:
+ r[i] = ''
+ else:
+ r[i] = vgstash.vtok(r[i], vgstash.OWNERSHIP)[0].capitalize()
+ if columns[i] == ("p_date") and r[i] != "":
+ r[i] = vgstash.unix_to_iso(int(r[i]))
+ if columns[i] == ("b_date") and r[i] != "":
+ r[i] = vgstash.unix_to_iso(int(r[i]))
+ if columns[i] == ("c_date") and r[i] != "":
+ r[i] = vgstash.unix_to_iso(int(r[i]))
+ if columns[i] == "notes" and len(r[i]) > 0:
+ r[i] = "*"
+ # if isinstance(r[i], int):
+ # r[i] = str(r[i])
# Store width in relevant list
w = len(str(r[i]))
if w > widths[i]:
@@ -203,7 +218,10 @@ def list_games(filter, raw):
l = []
for i in range(len(columns)):
# TODO: set different fstring based on column name
- l.append(left_fst.format(r[i], w=widths[i]))
+ if columns[i] == 'years' or columns[i] == 'days':
+ l.append(right_fst.format(str(r[i]), w=widths[i]))
+ else:
+ l.append(left_fst.format(r[i], w=widths[i]))
click.echo(" | ".join(l))
@cli.command('delete')
@@ -221,9 +239,16 @@ def delete_game(title, system):
@cli.command('update')
@click.argument('title', required=True)
@click.argument('system', required=True)
-@click.argument('attr', type=click.Choice(['title', 'system', 'ownership', 'progress']), required=True)
+@click.argument('attr', type=click.Choice(['title', 'system', 'ownership', 'progress', 'p_date', 'b_date', 'c_date']), required=True)
@click.argument('val', required=True)
def update_game(title, system, attr, val):
+ """
+ Update a specific game's attribute in the database.
+
+ Use the title and system parameters to target the game to update.
+ Ownership and progress can be their letter or numeric values.
+ p_date, b_date, and c_date MUST be ISO8601 dates, i.e. 2025-07-27
+ """
# TODO: Consider namedtuple as a solution
db = get_db()
try:
@@ -236,11 +261,14 @@ def update_game(title, system, attr, val):
if attr == 'progress':
val = vgstash.vtok(val, vgstash.PROGRESS)
updated_game = vgstash.Game(
- val if attr == 'title' else target_game.title,
- val if attr == 'system' else target_game.system,
- val if attr == 'ownership' else target_game.ownership,
- val if attr == 'progress' else target_game.progress,
- target_game.notes
+ title = val if attr == 'title' else target_game.title,
+ system = val if attr == 'system' else target_game.system,
+ ownership = val if attr == 'ownership' else target_game.ownership,
+ progress = val if attr == 'progress' else target_game.progress,
+ notes = target_game.notes,
+ p_date = vgstash.iso_to_unix(val) if attr == 'p_date' else target_game.p_date,
+ b_date = vgstash.iso_to_unix(val) if attr == 'b_date' else target_game.b_date,
+ c_date = vgstash.iso_to_unix(val) if attr == 'c_date' else target_game.c_date
)
if db.update_game(target_game, updated_game):
click.echo("Updated {} for {}. Its {} is now {}.".format(title, system, attr, val))
h/commit/vgstash?h=next&id=7686f310447e56518d3959c0aa7d62a69c3fb789&follow=1'>add 'playlog' list filterzlg2-2/+9 This filter is used to get an idea of which games you're currently playing through, so you can prioritize games to play when you're bored and detect it when you've beaten a game but haven't marked it as such. 2018-03-13Update helpers a bitzlg1-2/+9 At present, user modification is needed to make these seamless. vgup() may need to be axed in favor of telling the user to make an alias. 2018-03-13Make VGSTASH_DB_LOCATION point to a filezlg2-21/+20 It used to point to a directory, which would then look for .vgstash.db. This behavior was kind of backwards and I don't remember why I did it that way. This change gives users more control over where they put their DB. Be sure to update your environment variable if you have it set! 2016-11-18Remove settings from helpers.shZe Libertine Gamer1-5/+0 Sourcing them in .bash_profile screws up login if they're set. 2016-11-15Correct phrasing in README.Ze Libertine Gamer1-4/+4 2016-11-13DerpZe Libertine Gamer1-0/+1 2016-11-03Improve error handling in shell scriptsZe Libertine Gamer4-3/+23 2016-10-24Correct run_again, add recursionZe Libertine Gamer1-0/+4 Loops and functions -- oh my, what a useful combination. :) 2016-10-21Add quotes to correct behavior for arglistZe Libertine Gamer1-1/+1 2016-10-14updater.sh: add recursion, error handlingZe Libertine Gamer1-43/+101 2016-10-14Correct pipe-handling behaviorZe Libertine Gamer1-1/+9 2016-10-12Clarify a method to move between platformsZe Libertine Gamer1-2/+5 Also correct a typo.