-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheClockDataGetter.py
More file actions
398 lines (330 loc) · 17.1 KB
/
eClockDataGetter.py
File metadata and controls
398 lines (330 loc) · 17.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
#!/usr/bin/python3
# rpi_dashboard
# =================
# Data Getter - 15 Minute runner
import sys
if sys.version_info[0] < 3:
raise Exception("Python 3 or a more recent version is required.")
import os
import shutil
import glob
import json
import time
import datetime as dt
# MAKE SURE WE is in the correct directory
os.chdir('/home/pi/dashdisplay')
def fnGetLastUpdated(datafile, refreshdefault):
""" Determine Last Updated from Json file
:param datafile: Datafile to check
:param refreshdefault: Default refresh interval
"""
data_timediff = int(refreshdefault)*61
try:
if os.path.isfile(datafile+'.json'):
with open(datafile+'.json', encoding='utf-8') as fp:
json_obj = json.load(fp)
data_timediff = int(time.time()) - int(json_obj['dt'])
except Exception as ex:
print("fnGetLastUpdated("+datafile+") WARN: No Source Current)", ex)
data_timediff = int(refreshdefault)*61
return data_timediff/60
def fnGetWeather():
""" Get Weather Information """
from infosource.app_weather import app_weather
# Open Config
with open('conf/weather.json', encoding='utf-8') as fp:
json_config = json.load(fp)
if int(json_config['refresh']) == 0:
# Clear all Downloaded Data and Icon Files
for filePath in glob.glob(app_weather.datapath + 'current_*.json'):
try:
os.remove(filePath)
except:
print("fnGetWeather(Error while deleting file)", filePath)
for filePath in glob.glob(app_weather.datapath + 'forecast_*.json'):
try:
os.remove(filePath)
except:
print("fnGetWeather(Error while deleting file)", filePath)
for filePath in glob.glob(app_weather.datapath + 'icon_*.png'):
try:
os.remove(filePath)
except:
print("fnGetWeather(Error while deleting file)", filePath)
else:
weatheraction = app_weather(config=json_config)
# Loop round all locations and get data
for weatherlocation in json_config["locations"]:
data_timediff = fnGetLastUpdated(app_weather.datapath + 'current_' + str(weatherlocation['townid']), json_config['refresh'])
if data_timediff >= int(json_config['refresh']):
# Get Weather, check for name and get icon image
# - Current
json_obj = weatheraction.getcurrent(weatherlocation['townid'])
weatheraction.savedata('current_' + str(weatherlocation['townid']), json_obj)
# - Current Icon
iconpath = weatheraction.downloadicon(json_obj['weather'][0]['icon'])
# - Forecast
json_obj = weatheraction.getforecast(weatherlocation['townid'])
weatheraction.savedata('forecast_' + str(weatherlocation['townid']), json_obj)
# - Get Active Weather Icons
for i in range(0, 20):
iconpath = weatheraction.downloadicon(json_obj['list'][i]['weather'][0]['icon'])
else:
print("fnGetWeather("+str(weatherlocation['townid'])+") Info: Not needed")
def fnGetTide():
""" Get Tide Information """
from infosource.app_tide import app_tide
# Open Config
with open('conf/tide.json', encoding='utf-8') as fp:
json_config = json.load(fp)
if int(json_config['refresh']) == 0:
# Clear all Downloaded Data and Icon Files
for filePath in glob.glob(app_tide.datapath + '*.json'):
try:
os.remove(filePath)
except:
print("fnGetTide(Error while deleting file)", filePath)
else:
# Loop round all locations and get data
tideaction = app_tide(config=json_config)
for tidelocation in json_config["locations"]:
data_timediff = fnGetLastUpdated(app_tide.datapath + str(tidelocation['portid']), json_config['refresh'])
if data_timediff >= int(json_config['refresh']):
# Get Forecast
json_obj = tideaction.getforecast(tidelocation['portid'])
json_obj['dt'] = int(time.time())
# Save Info
tideaction.savedata(tidelocation['portid'], json_obj)
else:
print("fnGetTide("+tidelocation['portid']+") Info: Not needed")
def fnGetDlna():
""" Get DLNA Information """
# No longer Used
from infosource.app_dlna import app_dlna
_data_file = 'data/dlna_stats.json'
_data_fileold = 'data/dlna_stats.old.json'
# Open Config
with open('conf/dlna.json', encoding='utf-8') as fp:
json_config = json.load(fp)
# Load Existing
try:
with open(_data_file, encoding='utf-8') as fp:
json_data = json.load(fp)
data_timediff = int(time.time()) - int(json_data['updated'])
except:
json_data = {"audio": 0, "video": 0, "updated": 0}
data_timediff = int(json_config['refresh'])*61
if not 'audio' in json_data:
json_data['audio'] = 0
if not 'video' in json_data:
json_data['video'] = 0
if not 'photo' in json_data:
json_data['photo'] = 0
if int(json_config['refresh']) == 0 or int(json_config['type']) == 0:
# Turn off update (delete data)
if os.path.isfile(_data_file):
os.remove(_data_file)
if os.path.isfile(_data_fileold):
os.remove(_data_fileold)
elif data_timediff >= (int(json_config['refresh'])*60):
# Get Data
dataresponse = app_dlna(config=json_config).process()
if int(json_data['audio']) != int(dataresponse['audio']) or int(json_data['video']) != int(dataresponse['video']) or int(json_data['photo']) != int(dataresponse['photo']):
if os.path.isfile(_data_file):
shutil.copyfile(_data_file, _data_fileold)
with open(_data_file, 'w', encoding='utf-8') as outs:
json.dump(dataresponse, outs)
else:
print("fnGetDlna(): No Change")
else:
print("fnGetDlna(): Not needed")
def fnGetO365Calendar():
""" Get Office365 Calendar information """
# VERY OLD NOT IN USE
from infosource.app_calendar import app_calendar
# Open Config
with open('conf/o365.json', encoding='utf-8') as fp:
json_config = json.load(fp)
data_timediff = fnGetLastUpdated('data/o365_calendar.json', json_config['schedule']['refresh'])
if data_timediff >= int(json_config['schedule']['refresh']):
# Get Data
o365action = app_calendar(config=json_config)
with open('data/o365_calendar.json', 'w', encoding='utf-8') as outs:
json.dump(o365action.process('schedule'), outs)
else:
print("fnGetO365Calendar(): Not needed")
def fnGet0365CalendarHP():
"""
Get Office365 Calendar information
NB: Uses PHP!!
"""
print("fnGet0365CalendarHP():")
os.system('php -f alternate/eClockDataGetterTC.php')
def fnGetO365InfoPane():
""" Get Office365 Info Pane Calendar information """
from infosource.app_calendar import app_calendar
# Open Config
with open('conf/o365.json', encoding='utf-8') as fp:
json_config = json.load(fp)
with open('conf/site.json', encoding='utf-8') as fp:
json_siteconfig = json.load(fp)
# Loop round all site locations and get data
o365action = app_calendar(config=json_config)
for json_site in json_siteconfig["locations"]:
time.sleep(1)
if json_site is None:
json_site = {}
if not 'calendar' in json_site:
json_site['calendar'] = {}
if json_site['calendar'] is None:
json_site['calendar'] = {}
json_site['calendar']['refresh'] = 0
if not 'refresh' in json_site['calendar']:
json_site['calendar']['refresh'] = 0
if not 'manual' in json_site['calendar']:
json_site['calendar']['manual'] = False
data_timediff = fnGetLastUpdated(app_calendar.datapath+'infopane_'+str(json_site["id"]), json_site['calendar']['refresh'])
if data_timediff >= int(json_site['calendar']['refresh']):
# Get Data
json_catsourcedata = {'MasterList':[]}
if json_site['calendar']['manual']:
# Manual process (from PHP lookup data)
try:
# Manual Merge of Category List
json_catsourcedata = o365action.loaddata('infopane_'+str(json_site["id"])+'_cat')
o365action.set_categorylist(categorylist=json_catsourcedata['MasterList'])
# Manual Process ingest
json_sourcedata = o365action.loaddata('infopane_'+str(json_site["id"])+'s')
json_output = o365action.processmanual(siteconfig=json_site['calendar'], sourcedata=json_sourcedata['value'])
o365action.savedata('infopane_'+str(json_site["id"]), json_output)
except Exception as ex:
print('Calendar Source file issue. '+str(json_site["id"]), ex)
else:
# Automatic process
json_output = o365action.process(siteconfig=json_site['calendar'])
o365action.savedata('infopane_'+str(json_site["id"]), json_output)
def fnGetO365Menu():
'''Get Office365 Info Pane Dinner Menu information'''
from infosource.app_menu import app_menu
# Open Config
with open('conf/site.json', encoding='utf-8') as fp:
json_siteconfig = json.load(fp)
# Loop round all site locations and get data
o365actionmenu = app_menu()
for json_site in json_siteconfig["locations"]:
time.sleep(1)
if json_site is None:
json_site = {}
if not 'menu' in json_site:
json_site['menu'] = {}
if json_site['menu'] is None:
json_site['menu'] = {}
json_site['menu']['refresh'] = 0
if not 'refresh' in json_site['menu']:
json_site['menu']['refresh'] = 0
if not 'allowedit' in json_site['menu']:
json_site['menu']['allowedit'] = False
data_timediff = fnGetLastUpdated(app_menu.datapath+'menu_'+str(json_site["id"]), json_site['menu']['refresh'])
if data_timediff >= int(json_site['menu']['refresh']):
# Get Data
json_menu = o365actionmenu.Process(sitemenuconfig=json_site['menu'])
o365actionmenu.SaveData('menu_'+json_site["id"], json_menu)
# Get Options Data
json_menuoptions = o365actionmenu.GetEditOptions(sitemenuconfig=json_site['menu'])
o365actionmenu.SaveData('options_'+json_site["id"], json_menuoptions)
o365actionmenu.GetRecipeOptions(siteid=json_site["id"], menudata=json_menuoptions['option'])
else:
print("fnGetO365Menu("+str(json_site['id'])+") Info: Not needed")
def fnGetO365Task():
"""Get Office365 Info Pane Tasks information"""
from infosource.app_tasks import app_tasks
# Open Config
with open('conf/o365.json', encoding='utf-8') as fp:
json_config = json.load(fp)
with open('conf/site.json', encoding='utf-8') as fp:
json_siteconfig = json.load(fp)
# Loop round all site locations and get data
o365action = app_tasks(config=json_config)
for json_site in json_siteconfig["locations"]:
time.sleep(1)
if json_site is None:
json_site = {}
if not 'tasks' in json_site:
json_site['tasks'] = {}
if json_site['tasks'] is None:
json_site['tasks'] = {}
json_site['tasks']['refresh'] = 0
if not 'refresh' in json_site['tasks']:
json_site['tasks']['refresh'] = 0
if not 'manual' in json_site['tasks']:
json_site['tasks']['manual'] = False
data_timediff = fnGetLastUpdated('data/o365_tasks_'+str(json_site["id"]), json_site['tasks']['refresh'])
if data_timediff >= int(json_site['tasks']['refresh']):
# Get Data
if json_site['tasks']['manual']:
try:
with open('data/o365_tasks_'+json_site["id"]+'s.json', encoding='utf-8') as fp:
json_sourcedata = json.load(fp)
json_output = o365action.processmanual(siteconfig=json_site['tasks'], sourcedata=json_sourcedata['value'])
with open('data/o365_tasks_'+json_site["id"]+'.json', 'w', encoding='utf-8') as outs:
json.dump(json_output, outs)
except Exception as ex:
print('Tasks Source file issue. '+json_site["id"], ex)
else:
json_output = o365action.process(siteconfig=json_site['tasks'])
with open('data/o365_tasks_'+json_site["id"]+'.json', 'w') as outs:
json.dump(json_output, outs)
else:
print("fnGetO365Task("+str(json_site['id'])+") Info: Not needed")
def fnGetO365Photo():
""" Get Office365 Photo Collage """
from infosource.app_photo import app_photo
# Open Config
with open('conf/o365.json', encoding='utf-8') as fp:
json_config = json.load(fp)
with open('conf/site.json', encoding='utf-8') as fp:
json_siteconfig = json.load(fp)
o365action = app_photo(config=json_config)
for json_site in json_siteconfig["locations"]:
time.sleep(1)
if json_site is None:
json_site = {}
if not 'photo' in json_site:
json_site['photo'] = {}
if json_site['photo'] is None:
json_site['photo'] = {}
json_site['photo']['refresh'] = 0
if not 'refresh' in json_site['photo']:
json_site['photo']['refresh'] = 0
data_timediff = fnGetLastUpdated('data/photo/photo_'+str(json_site["id"]), json_site['photo']['refresh'])
if data_timediff >= int(json_site['photo']['refresh']):
# Get Data
o365datajson = o365action.process(siteconfig=json_site['photo'], locationid=json_site["id"])
o365datajson['imagecollage'] = []
o365datajson['imagecollagevirt'] = []
if o365datajson['imagecount'] == 12:
o365action.makeCollage(siteconfig=json_site['photo'], locationid=json_site["id"], title=o365datajson['folder0name'], inputs={'photo_'+json_site["id"]+'_0.jpg','photo_'+json_site["id"]+'_1.jpg','photo_'+json_site["id"]+'_2.jpg'}, outputfile='image_'+json_site["id"]+'_0.png')
o365action.makeCollage(siteconfig=json_site['photo'], locationid=json_site["id"], title=o365datajson['folder1name'], inputs={'photo_'+json_site["id"]+'_3.jpg','photo_'+json_site["id"]+'_4.jpg','photo_'+json_site["id"]+'_5.jpg'}, outputfile='image_'+json_site["id"]+'_1.png')
o365action.makeCollage(siteconfig=json_site['photo'], locationid=json_site["id"], title=o365datajson['folder2name'], inputs={'photo_'+json_site["id"]+'_6.jpg','photo_'+json_site["id"]+'_7.jpg','photo_'+json_site["id"]+'_8.jpg'}, outputfile='image_'+json_site["id"]+'_2.png')
o365action.makeCollage(siteconfig=json_site['photo'], locationid=json_site["id"], title=o365datajson['folder3name'], inputs={'photo_'+json_site["id"]+'_9.jpg','photo_'+json_site["id"]+'_10.jpg','photo_'+json_site["id"]+'_11.jpg'}, outputfile='image_'+json_site["id"]+'_3.png')
o365datajson['imagecollage'] = ['image_'+json_site["id"]+'_0.png', 'image_'+json_site["id"]+'_1.png', 'image_'+json_site["id"]+'_2.png', 'image_'+json_site["id"]+'_3.png']
if 'v' in json_site['photo']:
o365action.makeCollageVirt(siteconfig=json_site['photo'], locationid=json_site["id"], title=o365datajson['folder0name'], inputs={'photo_'+json_site["id"]+'_0.jpg','photo_'+json_site["id"]+'_1.jpg','photo_'+json_site["id"]+'_2.jpg'}, outputfile='image_'+json_site["id"]+'_v0.png')
o365action.makeCollageVirt(siteconfig=json_site['photo'], locationid=json_site["id"], title=o365datajson['folder1name'], inputs={'photo_'+json_site["id"]+'_3.jpg','photo_'+json_site["id"]+'_4.jpg','photo_'+json_site["id"]+'_5.jpg'}, outputfile='image_'+json_site["id"]+'_v1.png')
o365action.makeCollageVirt(siteconfig=json_site['photo'], locationid=json_site["id"], title=o365datajson['folder2name'], inputs={'photo_'+json_site["id"]+'_6.jpg','photo_'+json_site["id"]+'_7.jpg','photo_'+json_site["id"]+'_8.jpg'}, outputfile='image_'+json_site["id"]+'_v2.png')
o365action.makeCollageVirt(siteconfig=json_site['photo'], locationid=json_site["id"], title=o365datajson['folder3name'], inputs={'photo_'+json_site["id"]+'_9.jpg','photo_'+json_site["id"]+'_10.jpg','photo_'+json_site["id"]+'_11.jpg'}, outputfile='image_'+json_site["id"]+'_v3.png')
o365datajson['imagecollagevirt'] = ['image_'+json_site["id"]+'_v0.png', 'image_'+json_site["id"]+'_v1.png', 'image_'+json_site["id"]+'_v2.png', 'image_'+json_site["id"]+'_v3.png']
o365action.savedata('photo_'+str(json_site["id"]), o365datajson)
else:
print("fnGetO365Photo("+str(json_site['id'])+") Info: Not needed")
#######################################
# Main program
fnGetWeather()
fnGetTide()
# fnGetDlna()
# fnGetO365Calendar()
fnGet0365CalendarHP()
fnGetO365InfoPane()
fnGetO365Menu()
# fnGetO365Task()
fnGetO365Photo()