Skip to content

Commit

Permalink
cleanup logic/display in export & library methods
Browse files Browse the repository at this point in the history
  • Loading branch information
jessedp committed Aug 7, 2019
1 parent f09e3e6 commit 5334a83
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 30 deletions.
10 changes: 5 additions & 5 deletions export.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ def copy(id_list, args):
# TODO: put a X of Y somewhere near here
_copy(id, args)
print()
print("FINSIHED")
print("FINISHED")


def _copy(id, args):
def _copy(obj_id, args):
# TODO: Whoops, now used this twice (search.py too)
path = built_ins['db']['recordings']
rec_db = TinyDB(path)
Expand All @@ -49,16 +49,16 @@ def _copy(id, args):
# - look at recording/show data to see what it *should* be?
# - overwrite previous portions
obj = rec_db.get(
(shows_qry.object_id == int(id))
(shows_qry.object_id == int(obj_id))
&
(shows_qry.video_details.state == 'finished')
)
if obj is None:
print(
f'ERROR: Unable to load record with object_id == "{id}", '
f'ERROR: Unable to find recording with object_id == "{obj_id}", '
f'skipping...')
return
# print(f'working on: {id}')

rec = Recording(obj['data'])

watch = rec.watch()
Expand Down
63 changes: 38 additions & 25 deletions library.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,11 @@ def delete(id_list, args):
if total == 0:
print(f"Nothing to delete, exiting...")
return
elif total == 1:
print(f"Deleting {total} recording")
else:
print(f"Deleting {total} recordings")
print("-" * 50)

# Load all the recs
path = built_ins['db']['recordings']
Expand All @@ -344,39 +349,47 @@ def delete(id_list, args):
recs = []
total = 0
for obj_id in id_list:
obj = rec_db.get(shows_qry.object_id == int(obj_id))
if obj['data']['video_details']['state'] == 'recording':
total = max((total-1), 0)
else:
total += 1
recs.append(
{
'doc_id': obj.doc_id,
'obj_id': obj_id,
'rec': Recording(obj['data'])
})
obj = rec_db.get(
(shows_qry.object_id == int(obj_id))
&
(shows_qry.video_details.state != 'recording')
)
if not obj:
print(f'ERROR: Unable to find recording with '
f'object_id == "{obj_id}", skipping...')
continue

total += 1
recs.append(
{
'doc_id': obj.doc_id,
'obj_id': obj_id,
'rec': Recording(obj['data'])
})

# TODO: don't "total" like this
if total <= 0:
print("No recordings found.")
return
print(f"No recordings found; {len(id_list)} requested.")
elif total == 1:
print(f"Deleting {total} recording...")
else:
print(f"Deleting {total} recordings...")

for rec in recs:
rec = rec['rec']
print(f" - {rec.get_actual_dur()} | {rec.get_description()} ")

print("-" * 50)
if not args.yes:
print()
print('\tAdd the "--yes" flag to actually delete things...')
print()
else:
if total > 0:
for rec in recs:
_delete(rec, rec_db)
print("FINSIHED")
rec = rec['rec']
print(f" - {rec.get_actual_dur()} | {rec.get_description()} ")

print("-" * 50)
if not args.yes:
print()
print('\tAdd the "--yes" flag to actually delete things...')
print()
else:
for rec in recs:
_delete(rec, rec_db)

print("\nFINISHED")


def _delete(rec, rec_db):
Expand Down

0 comments on commit 5334a83

Please sign in to comment.