Skip to content

Commit 27331c2

Browse files
committed
add function to email problem cameras with bespoke message
1 parent eda54dd commit 27331c2

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

archive/ukmon_pylib/reports/reportBadCameras.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,46 @@
1414

1515
mailfrom = 'ukmonhelper2@ukmeteors.co.uk'
1616

17+
18+
def sendBespokeMessage(targlist, messagefile, subj):
19+
20+
messagecontent = open(messagefile, 'r').read()
21+
targets = open(targlist, 'r').readlines()
22+
camowners = loadLocationDetails()
23+
camowners['location'] = [ x.lower() + '_' + y.lower() for x,y in zip(camowners.site,camowners.direction)]
24+
camowners = camowners[camowners.active==1]
25+
camowners.drop(columns=['oldcode', 'site', 'camtype', 'active', 'humanName','direction','created'], inplace=True)
26+
#camowners = camowners.groupby('eMail', as_index=False).agg(lambda x: ','.join(x.tolist()))
27+
owners = []
28+
camids = []
29+
gmnids = []
30+
for target in targets:
31+
locationid = target.strip()
32+
if locationid[:1] == '#':
33+
continue
34+
thisrow = camowners[camowners.location.str.contains(locationid)]
35+
if len(thisrow) > 0:
36+
thisowner = thisrow.values[0][0]
37+
if thisowner in owners:
38+
idx = owners.index(thisowner)
39+
gmnids[idx] = f'{gmnids[idx]},{thisrow.values[0][1]}'
40+
camids[idx] = f'{camids[idx]},{thisrow.values[0][2]}'
41+
continue
42+
else:
43+
owners.append(thisowner)
44+
gmnids.append(thisrow.values[0][1])
45+
camids.append(thisrow.values[0][2])
46+
df = pd.DataFrame({'owner':owners, 'camids':camids, 'gmnids':gmnids})
47+
print(df)
48+
for _,rw in df.iterrows():
49+
mailrecip = rw.owner
50+
statid = rw.gmnids
51+
locationid = rw.camids
52+
print(f'emailing {mailrecip} concerning {statid} {locationid} subject {subj}')
53+
sendAnEmail(mailrecip, messagecontent.format(statid, locationid), subj, mailfrom)
54+
return
55+
56+
1757
if __name__ == '__main__':
1858
if len(sys.argv) < 2:
1959
print('usage: python reportBadCameras.py daysback')

0 commit comments

Comments
 (0)