Skip to content

Commit

Permalink
Merge pull request #737 from mkmer/BlinkSync-cleanup
Browse files Browse the repository at this point in the history
save auth key
  • Loading branch information
fronzbot authored Aug 16, 2023
2 parents 50b395d + 1779a73 commit 9fa0b2e
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions blinksync/blinksync.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
import aiohttp
import sys
from sortedcontainers import SortedSet
from forms import LoginDialog, VideosForm, DELAY,CLOSE, DELETE, DOWNLOAD, REFRESH
from forms import LoginDialog, VideosForm, DELAY, CLOSE, DELETE, DOWNLOAD, REFRESH
from blinkpy.blinkpy import Blink, BlinkSyncModule
from blinkpy.auth import Auth


async def main():
"""Main loop for blink test."""
session = aiohttp.ClientSession()
Expand All @@ -20,8 +21,8 @@ async def main():
path = dlg.GetPath()
else:
sys.exit(0)
with open(f"{path}/blink.json", "rt",encoding='ascii') as j:

with open(f"{path}/blink.json", "rt", encoding="ascii") as j:
blink.auth = Auth(json.loads(j.read()), session=session)

except (StopIteration, FileNotFoundError):
Expand All @@ -33,6 +34,9 @@ async def main():
userpass,
session=session,
)
await blink.save(f"{path}/blink.json")
else:
sys.exit(0)
with wx.BusyInfo("Blink is Working....") as working:
cursor = wx.BusyCursor()
if await blink.start():
Expand All @@ -44,7 +48,9 @@ async def main():
print(f"Sync :{blink.networks}")
if len(blink.networks) == 0:
exit()
my_sync: BlinkSyncModule = blink.sync[blink.networks[list(blink.networks)[0]]['name']]
my_sync: BlinkSyncModule = blink.sync[
blink.networks[list(blink.networks)[0]]["name"]
]
cursor = None
working = None

Expand All @@ -55,7 +61,7 @@ async def main():
print(name)
print(camera.attributes)

my_sync._local_storage['manifest'] = SortedSet()
my_sync._local_storage["manifest"] = SortedSet()
await my_sync.refresh()
if my_sync.local_storage and my_sync.local_storage_manifest_ready:
print("Manifest is ready")
Expand All @@ -80,7 +86,7 @@ async def main():
continue
# Download and delete all videos from sync module
for item in reversed(manifest):
if item.id in frame.ItemList:
if item.id in frame.ItemList:
if button == DOWNLOAD:
await item.prepare_download(blink)
await item.download_video(
Expand All @@ -94,12 +100,10 @@ async def main():
working = None
frame = None
await session.close()


# Run the program
if __name__ == "__main__":
logging.basicConfig(level=logging.DEBUG)
loop = asyncio.get_event_loop()
loop.run_until_complete(main())


0 comments on commit 9fa0b2e

Please sign in to comment.