blinkpy
blinkpy copied to clipboard
Videos do not delete from sync module local storage
I recently posted about a script to delete old videos from the local storage on the sync module and I updated my blinkpy to the latest development version. The script appeared to be working (i.e., no errors were generated) but the local storage continued to fill up. Looking in the blink app, I confirmed that old videos (currently defined in my script as older than 5 days) are still showing up, demonstrating that they have not been deleted.
Below is my code and the output.
#!/usr/bin/env python3.9
import asyncio
from datetime import datetime, timedelta
from sortedcontainers import SortedSet
from blinkpy.helpers.util import json_load
from blinkpy.blinkpy import Blink, BlinkSyncModule
from blinkpy.auth import Auth
from aiohttp import ClientSession
async def start(session: ClientSession):
"""Startup blink app."""
blink = Blink(session=session)
blink.auth = Auth(await json_load("/home/pi/utils/blink.auth"), session=session)
await blink.start()
return blink
async def main():
session = ClientSession()
try:
blink = await start(session)
await blink.refresh()
my_sync: BlinkSyncModule = blink.sync["Laguna"]
await my_sync.refresh()
if my_sync.local_storage and my_sync.local_storage_manifest_ready:
manifest = my_sync._local_storage["manifest"]
# print(f"Manifest {manifest}")
for item in reversed(manifest):
current_date = datetime.now(item.created_at.tzinfo)
time_difference = current_date - item.created_at
if time_difference > timedelta(days=5):
try:
await item.delete_video(blink)
await asyncio.sleep(2)
print(f"Success deleting video {item.id}")
except Exception as e:
print(f"Error deleting video {item.id}: {e}")
else:
print("Manifest not ready")
finally:
await session.close()
asyncio.run(main())
Success deleting video 1165876146
Success deleting video 2357212475
Success deleting video 3389086544
Success deleting video 4061158032
Success deleting video 4198518603
Success deleting video 3066931222
Success deleting video 2397370008
Note that output is truncated for brevity.