-
Notifications
You must be signed in to change notification settings - Fork 0
/
montcoai.py
74 lines (56 loc) · 1.76 KB
/
montcoai.py
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
#!/usr/bin/env python3
import re
import urllib.request
from twilio.rest import Client
from itertools import product
from bs4 import BeautifulSoup as bs
account_sid = ''
auth_token = ''
client = Client(account_sid, auth_token)
file = open('/home/montcocad/lib/last_alert.txt', 'r+')
url = "https://webapp02.montcopa.org/eoc/cadinfo/livecadrss.asp"
with urllib.request.urlopen(url) as response:
xml = response.read()
x = file.read().splitlines()
soup = bs(xml, 'lxml')
newalert = []
known_alert = []
description = soup.find_all(['description'])
title = soup.find_all(['title'])
count = 0
# Grab the township we want to alerts
for eachd in description:
#print(eachd)
if 'WHITEMARSH' in eachd.string:
t1 = re.sub('<.*?>', '', str(title[count])).strip()
d1 = eachd.string.strip()
newalert.append(t1 + ": " + d1)
elif 'CONSHOHOCKEN' in eachd.string:
t1 = re.sub('<.*?>', '', str(title[count])).strip()
d1 = eachd.string.strip()
newalert.append(t1 + ": " + d1)
elif 'PLYMOUTH' in eachd.string:
t1 = re.sub('<.*?>', '', str(title[count])).strip()
d1 = eachd.string.strip()
newalert.append(t1 + ": " + d1)
count = count + 1
for eacha in x:
if 'WHITEMARSH' in eacha:
known_alert.append(eacha)
elif 'CONSHOHOCKEN' in eacha:
known_alert.append(eacha)
elif 'PLYMOUTH' in eacha:
known_alert.append(eacha)
for x, y in product(newalert, known_alert):
if x == y:
newalert.remove(x)
newalert_count = len(newalert)
if newalert_count > 0:
for c in newalert:
newalert_count -= 1
file.write(newalert[newalert_count] + '\n')
client.messages.create(
to = '',
from_ = '',
body = newalert[newalert_count]
)