Skip to content

Commit a52fae2

Browse files
committed
Timezone
working dialog
1 parent 1fbe076 commit a52fae2

File tree

2 files changed

+181
-167
lines changed

2 files changed

+181
-167
lines changed

.github/blinksync/blinksync.py

Lines changed: 59 additions & 167 deletions
Original file line numberDiff line numberDiff line change
@@ -1,133 +1,13 @@
11
import json
22
import asyncio
3+
import wx
4+
import logging
35
import aiohttp
46
import sys
5-
import wx
67
from sortedcontainers import SortedSet
8+
from forms import LoginDialog, VideosForm, DELAY,CLOSE, DELETE, DOWNLOAD, REFRESH
79
from blinkpy.blinkpy import Blink, BlinkSyncModule
810
from blinkpy.auth import Auth
9-
import logging
10-
11-
DELETE = 1
12-
CLOSE = 2
13-
DOWNLOAD = 3
14-
REFRESH = 4
15-
DELAY = 5
16-
17-
class VideosForm(wx.Dialog):
18-
"""My delete form."""
19-
def __init__(self,manifest):
20-
wx.Frame.__init__(self, None, wx.ID_ANY, "Select List to Download and Delete",size = (450,550))
21-
22-
# Add a panel so it looks the correct on all platforms
23-
panel = wx.Panel(self, wx.ID_ANY)
24-
#self.Bind(wx.EVT,self._when_closed)
25-
self.index = 0
26-
self.ItemList = []
27-
self.list_ctrl = wx.ListCtrl(panel, size=(-1,400),
28-
style=wx.LC_REPORT
29-
|wx.BORDER_SUNKEN
30-
)
31-
self.list_ctrl.InsertColumn(0, 'Name')
32-
self.list_ctrl.InsertColumn(1, 'Camera')
33-
self.list_ctrl.InsertColumn(2, 'Date', width=225)
34-
self.list_ctrl.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK,self.download_line)
35-
36-
btn = wx.Button(panel, label="Download")
37-
btn.Bind(wx.EVT_BUTTON, self.download_line)
38-
39-
deletebtn = wx.Button(panel, label="Delete")
40-
deletebtn.Bind(wx.EVT_BUTTON, self.delete_line)
41-
42-
closeBtn = wx.Button(panel, label="Close")
43-
closeBtn.Bind(wx.EVT_BUTTON, self._when_closed)
44-
45-
refrestBtn = wx.Button(panel, label="Refresh")
46-
refrestBtn.Bind(wx.EVT_BUTTON, self._refresh)
47-
48-
sizer = wx.BoxSizer(wx.VERTICAL)
49-
sizer.Add(self.list_ctrl, 0, wx.ALL|wx.EXPAND, 20)
50-
sizer_buttons = wx.BoxSizer(wx.HORIZONTAL)
51-
sizer_buttons.Add(btn, 0, wx.ALL|wx.CENTER, 5)
52-
sizer_buttons.Add(deletebtn,0,wx.ALL|wx.CENTER,5)
53-
sizer_buttons.Add(refrestBtn,0,wx.ALL|wx.CENTER,5)
54-
sizer_buttons.Add(closeBtn,0,wx.ALL|wx.CENTER, 5)
55-
sizer.Add(sizer_buttons,0,wx.ALL|wx.CENTER,5)
56-
panel.SetSizer(sizer)
57-
58-
for item in reversed(manifest):
59-
self.list_ctrl.InsertItem(self.index, str(item.id))
60-
self.list_ctrl.SetItem(self.index, 1, item.name)
61-
self.list_ctrl.SetItem(self.index, 2, item.created_at.isoformat())
62-
self.index += 1
63-
#----------------------------------------------------------------------
64-
def download_line(self, event):
65-
"""Add to list and return DOWNLOAD"""
66-
for count in range(self.list_ctrl.ItemCount):
67-
if self.list_ctrl.IsSelected(count):
68-
self.ItemList.append(int(self.list_ctrl.GetItem(count).Text))
69-
self.EndModal(DOWNLOAD)
70-
71-
def delete_line(self, event):
72-
"""Add to list and return DOWNLOAD"""
73-
for count in range(self.list_ctrl.ItemCount):
74-
if self.list_ctrl.IsSelected(count):
75-
self.ItemList.append(int(self.list_ctrl.GetItem(count).Text))
76-
self.EndModal(DELETE)
77-
78-
79-
def _when_closed(self,event):
80-
self.EndModal(CLOSE)
81-
82-
def _refresh(self,event):
83-
self.EndModal(REFRESH)
84-
85-
class LoginDialog(wx.Dialog):
86-
"""
87-
Class to define login dialog
88-
"""
89-
#----------------------------------------------------------------------
90-
def __init__(self):
91-
"""Constructor"""
92-
wx.Dialog.__init__(self, None, title="Login")
93-
94-
# user info
95-
user_sizer = wx.BoxSizer(wx.HORIZONTAL)
96-
97-
user_lbl = wx.StaticText(self, label="Username:")
98-
user_sizer.Add(user_lbl, 0, wx.ALL|wx.CENTER, 5)
99-
self.user = wx.TextCtrl(self)
100-
user_sizer.Add(self.user, 0, wx.ALL, 5)
101-
102-
# pass info
103-
p_sizer = wx.BoxSizer(wx.HORIZONTAL)
104-
105-
p_lbl = wx.StaticText(self, label="Password:")
106-
p_sizer.Add(p_lbl, 0, wx.ALL|wx.CENTER, 5)
107-
self.password = wx.TextCtrl(self, style=wx.TE_PASSWORD|wx.TE_PROCESS_ENTER)
108-
p_sizer.Add(self.password, 0, wx.ALL, 5)
109-
110-
main_sizer = wx.BoxSizer(wx.VERTICAL)
111-
main_sizer.Add(user_sizer, 0, wx.ALL, 5)
112-
main_sizer.Add(p_sizer, 0, wx.ALL, 5)
113-
114-
btn = wx.Button(self, label="Login")
115-
btn.Bind(wx.EVT_BUTTON, self.onLogin)
116-
main_sizer.Add(btn, 0, wx.ALL|wx.CENTER, 5)
117-
118-
self.SetSizer(main_sizer)
119-
120-
#----------------------------------------------------------------------
121-
def onLogin(self, event):
122-
"""
123-
Check credentials and login
124-
"""
125-
self.account = {"username":self.user.Value,"password":self.password.Value}
126-
self.EndModal(wx.ID_OK)
127-
128-
def getUserPassword(self):
129-
return self.account
130-
13111

13212
async def main():
13313
"""Main loop for blink test."""
@@ -141,7 +21,7 @@ async def main():
14121
else:
14222
sys.exit(0)
14323

144-
with open(f"{path}/blink.json", "r") as j:
24+
with open(f"{path}/blink.json", "rt",encoding='ascii') as j:
14525
blink.auth = Auth(json.loads(j.read()), session=session)
14626

14727
except (StopIteration, FileNotFoundError):
@@ -153,53 +33,65 @@ async def main():
15333
userpass,
15434
session=session,
15535
)
36+
with wx.BusyInfo("Blink is Working....") as working:
37+
cursor = wx.BusyCursor()
38+
if await blink.start():
39+
await blink.setup_post_verify()
40+
elif blink.auth.check_key_required():
41+
print("I failed to authenticate")
42+
43+
print(f"Sync status: {blink.network_ids}")
44+
print(f"Sync :{blink.networks}")
45+
if len(blink.networks) == 0:
46+
exit()
47+
my_sync: BlinkSyncModule = blink.sync[blink.networks[list(blink.networks)[0]]['name']]
48+
cursor = None
49+
working = None
15650

157-
if await blink.start():
158-
await blink.setup_post_verify()
159-
elif blink.auth.check_key_required():
160-
print("I failed to authenticate")
161-
162-
print(f"Sync status: {blink.network_ids}")
163-
print(f"Sync :{blink.networks}")
164-
if len(blink.networks) == 0:
165-
exit()
166-
my_sync: BlinkSyncModule = blink.sync[blink.networks[list(blink.networks)[0]]['name']]
16751
while True:
168-
for name, camera in blink.cameras.items():
169-
print(name)
170-
print(camera.attributes)
171-
172-
my_sync._local_storage['manifest'] = SortedSet()
173-
await my_sync.refresh()
174-
if my_sync.local_storage and my_sync.local_storage_manifest_ready:
175-
print("Manifest is ready")
176-
print(f"Manifest {my_sync._local_storage['manifest']}")
177-
else:
178-
print("Manifest not ready")
179-
for name, camera in blink.cameras.items():
180-
print(f"{camera.name} status: {blink.cameras[name].arm}")
181-
new_vid = await my_sync.check_new_videos()
182-
print(f"New videos?: {new_vid}")
183-
184-
manifest = my_sync._local_storage["manifest"]
52+
with wx.BusyInfo("Blink is Working....") as working:
53+
cursor = wx.BusyCursor()
54+
for name, camera in blink.cameras.items():
55+
print(name)
56+
print(camera.attributes)
57+
58+
my_sync._local_storage['manifest'] = SortedSet()
59+
await my_sync.refresh()
60+
if my_sync.local_storage and my_sync.local_storage_manifest_ready:
61+
print("Manifest is ready")
62+
print(f"Manifest {my_sync._local_storage['manifest']}")
63+
else:
64+
print("Manifest not ready")
65+
for name, camera in blink.cameras.items():
66+
print(f"{camera.name} status: {blink.cameras[name].arm}")
67+
new_vid = await my_sync.check_new_videos()
68+
print(f"New videos?: {new_vid}")
69+
70+
manifest = my_sync._local_storage["manifest"]
71+
cursor = None
72+
working = None
18573
frame = VideosForm(manifest)
18674
button = frame.ShowModal()
187-
if button == CLOSE:
188-
break
189-
if button == REFRESH:
190-
continue
191-
# Download and delete all videos from sync module
192-
for item in reversed(manifest):
193-
if item.id in frame.ItemList:
194-
if button == DOWNLOAD:
195-
await item.prepare_download(blink)
196-
await item.download_video(
197-
blink,
198-
f"{path}/{item.name}_{item.created_at.isoformat().replace(':','_')}.mp4",
199-
)
200-
if button == DELETE:
201-
await item.delete_video(blink)
202-
await asyncio.sleep(DELAY)
75+
with wx.BusyInfo("Blink is Working....") as working:
76+
cursor = wx.BusyCursor()
77+
if button == CLOSE:
78+
break
79+
if button == REFRESH:
80+
continue
81+
# Download and delete all videos from sync module
82+
for item in reversed(manifest):
83+
if item.id in frame.ItemList:
84+
if button == DOWNLOAD:
85+
await item.prepare_download(blink)
86+
await item.download_video(
87+
blink,
88+
f"{path}/{item.name}_{item.created_at.astimezone().isoformat().replace(':','_')}.mp4",
89+
)
90+
if button == DELETE:
91+
await item.delete_video(blink)
92+
await asyncio.sleep(DELAY)
93+
cursor = None
94+
working = None
20395
frame = None
20496
await session.close()
20597

.github/blinksync/forms.py

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
import wx
2+
3+
DELETE = 1
4+
CLOSE = 2
5+
DOWNLOAD = 3
6+
REFRESH = 4
7+
DELAY = 5
8+
9+
class VideosForm(wx.Dialog):
10+
"""My delete form."""
11+
def __init__(self,manifest):
12+
wx.Frame.__init__(self, None, wx.ID_ANY, "Select List to Download and Delete",size = (450,550))
13+
14+
# Add a panel so it looks the correct on all platforms
15+
panel = wx.Panel(self, wx.ID_ANY)
16+
#self.Bind(wx.EVT,self._when_closed)
17+
self.index = 0
18+
self.ItemList = []
19+
self.list_ctrl = wx.ListCtrl(panel, size=(-1,400),
20+
style=wx.LC_REPORT
21+
|wx.BORDER_SUNKEN
22+
)
23+
self.list_ctrl.InsertColumn(0, 'Name')
24+
self.list_ctrl.InsertColumn(1, 'Camera')
25+
self.list_ctrl.InsertColumn(2, 'Date', width=225)
26+
self.list_ctrl.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK,self.download_line)
27+
28+
btn = wx.Button(panel, label="Download")
29+
btn.Bind(wx.EVT_BUTTON, self.download_line)
30+
31+
deletebtn = wx.Button(panel, label="Delete")
32+
deletebtn.Bind(wx.EVT_BUTTON, self.delete_line)
33+
34+
closeBtn = wx.Button(panel, label="Close")
35+
closeBtn.Bind(wx.EVT_BUTTON, self._when_closed)
36+
37+
refrestBtn = wx.Button(panel, label="Refresh")
38+
refrestBtn.Bind(wx.EVT_BUTTON, self._refresh)
39+
40+
sizer = wx.BoxSizer(wx.VERTICAL)
41+
sizer.Add(self.list_ctrl, 0, wx.ALL|wx.EXPAND, 20)
42+
sizer_buttons = wx.BoxSizer(wx.HORIZONTAL)
43+
sizer_buttons.Add(btn, 0, wx.ALL|wx.CENTER, 5)
44+
sizer_buttons.Add(deletebtn,0,wx.ALL|wx.CENTER,5)
45+
sizer_buttons.Add(refrestBtn,0,wx.ALL|wx.CENTER,5)
46+
sizer_buttons.Add(closeBtn,0,wx.ALL|wx.CENTER, 5)
47+
sizer.Add(sizer_buttons,0,wx.ALL|wx.CENTER,5)
48+
panel.SetSizer(sizer)
49+
50+
for item in reversed(manifest):
51+
self.list_ctrl.InsertItem(self.index, str(item.id))
52+
self.list_ctrl.SetItem(self.index, 1, item.name)
53+
self.list_ctrl.SetItem(self.index, 2, item.created_at.astimezone().isoformat())
54+
self.index += 1
55+
#----------------------------------------------------------------------
56+
def download_line(self, event):
57+
"""Add to list and return DOWNLOAD"""
58+
for count in range(self.list_ctrl.ItemCount):
59+
if self.list_ctrl.IsSelected(count):
60+
self.ItemList.append(int(self.list_ctrl.GetItem(count).Text))
61+
self.EndModal(DOWNLOAD)
62+
63+
def delete_line(self, event):
64+
"""Add to list and return DOWNLOAD"""
65+
for count in range(self.list_ctrl.ItemCount):
66+
if self.list_ctrl.IsSelected(count):
67+
self.ItemList.append(int(self.list_ctrl.GetItem(count).Text))
68+
self.EndModal(DELETE)
69+
70+
71+
def _when_closed(self,event):
72+
self.EndModal(CLOSE)
73+
74+
def _refresh(self,event):
75+
self.EndModal(REFRESH)
76+
77+
class LoginDialog(wx.Dialog):
78+
"""
79+
Class to define login dialog
80+
"""
81+
#----------------------------------------------------------------------
82+
def __init__(self):
83+
"""Constructor"""
84+
wx.Dialog.__init__(self, None, title="Login")
85+
86+
# user info
87+
user_sizer = wx.BoxSizer(wx.HORIZONTAL)
88+
89+
user_lbl = wx.StaticText(self, label="Username:")
90+
user_sizer.Add(user_lbl, 0, wx.ALL|wx.CENTER, 5)
91+
self.user = wx.TextCtrl(self)
92+
user_sizer.Add(self.user, 0, wx.ALL, 5)
93+
94+
# pass info
95+
p_sizer = wx.BoxSizer(wx.HORIZONTAL)
96+
97+
p_lbl = wx.StaticText(self, label="Password:")
98+
p_sizer.Add(p_lbl, 0, wx.ALL|wx.CENTER, 5)
99+
self.password = wx.TextCtrl(self, style=wx.TE_PASSWORD|wx.TE_PROCESS_ENTER)
100+
p_sizer.Add(self.password, 0, wx.ALL, 5)
101+
102+
main_sizer = wx.BoxSizer(wx.VERTICAL)
103+
main_sizer.Add(user_sizer, 0, wx.ALL, 5)
104+
main_sizer.Add(p_sizer, 0, wx.ALL, 5)
105+
106+
btn = wx.Button(self, label="Login")
107+
btn.Bind(wx.EVT_BUTTON, self.onLogin)
108+
main_sizer.Add(btn, 0, wx.ALL|wx.CENTER, 5)
109+
110+
self.SetSizer(main_sizer)
111+
112+
#----------------------------------------------------------------------
113+
def onLogin(self, event):
114+
"""
115+
Check credentials and login
116+
"""
117+
self.account = {"username":self.user.Value,"password":self.password.Value}
118+
self.EndModal(wx.ID_OK)
119+
120+
def getUserPassword(self):
121+
return self.account
122+

0 commit comments

Comments
 (0)