|
14 | 14 |
|
15 | 15 | mailfrom = 'ukmonhelper2@ukmeteors.co.uk' |
16 | 16 |
|
| 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 | + |
17 | 57 | if __name__ == '__main__': |
18 | 58 | if len(sys.argv) < 2: |
19 | 59 | print('usage: python reportBadCameras.py daysback') |
|
0 commit comments