forked from jab/galerts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
galerts.py
686 lines (606 loc) · 25.1 KB
/
galerts.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
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
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
# Copyright (c) 2011 Josh Bronson
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without
# restriction, including without limitation the rights to use,
# copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following
# conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
import re
from urllib import parse, request
import lxml.html
from getpass import getpass
# {{{ these values must match those used in the Google Alerts web interface:
#: The maximum length of an alert query
QUERY_MAXLEN = 2048
#: Use this value to indicate delivery via email
DELIVER_EMAIL = 'Email'
#: Use this value to indicate delivery via feed
DELIVER_FEED = 'feed'
DELIVER_DEFAULT_VAL = '6'
#: maps available delivery types to the values Google uses for them
DELIVER_TYPES = {
DELIVER_EMAIL: '0',
DELIVER_FEED: DELIVER_DEFAULT_VAL,
}
#: Use this value for :attr:`Alert.freq` to indicate delivery in real time
FREQ_AS_IT_HAPPENS = 'As-it-happens'
#: Use this value for :attr:`Alert.freq` to indicate delivery once a day
FREQ_ONCE_A_DAY = 'Once a day'
#: Use this value for :attr:`Alert.freq` to indicate delivery once a week
FREQ_ONCE_A_WEEK = 'Once a week'
#: maps available alert frequencies to the values Google uses for them
ALERT_FREQS = {
FREQ_AS_IT_HAPPENS: '0',
FREQ_ONCE_A_DAY: '1',
FREQ_ONCE_A_WEEK: '6',
}
#: Use this value for an alert volume of only the best results
VOL_ONLY_BEST = 'Only the best results'
#: Use this value for an alert volume of all results
VOL_ALL = 'All results'
#: maps available alert volumes to the values Google uses for them
ALERT_VOLS = {
VOL_ONLY_BEST: '0',
VOL_ALL: '1',
}
#: Use this value for :attr:`Alert.type` to indicate all results
TYPE_EVERYTHING = 'Everything'
#: Use this value for :attr:`Alert.type` to indicate news results
TYPE_NEWS = 'News'
#: Use this value for :attr:`Alert.type` to indicate blog results
TYPE_BLOGS = 'Blogs'
#: Use this value for :attr:`Alert.type` to indicate realtime results
TYPE_REALTIME = 'Realtime'
#: Use this value for :attr:`Alert.type` to indicate video results
TYPE_VIDEO = 'Video'
#: Use this value for :attr:`Alert.type` to indicate discussion results
TYPE_DISCUSSIONS = 'Discussions'
#: maps available alert types to the values Google uses for them
ALERT_TYPES = {
TYPE_EVERYTHING: '7',
TYPE_NEWS: '1',
TYPE_BLOGS: '4',
TYPE_REALTIME: '20',
TYPE_VIDEO: '9',
TYPE_DISCUSSIONS: '8',
}
# }}}
class SignInError(Exception):
"""
Raised when Google sign in fails.
"""
class UnexpectedResponseError(Exception):
"""
Raised when Google's response to a request is unrecognized.
"""
def __init__(self, status, headers, body):
Exception.__init__(self)
self.resp_status = status
self.resp_headers = headers
self.resp_body = body
def safe_urlencode(params):
result = []
for k, v in params.iteritems():
if not isinstance(k, str):
k = k.encode('utf-8')
if not isinstance(v, str):
v = v.encode('utf-8')
result.append((k, v))
return parse.urlencode(result)
class Alert(object):
"""
Models a Google Alert.
You should not create :class:`Alert` objects explicitly; the
:class:`GAlertsManager` will create them for you. You can then access
alert objects via :attr:`GAlertsManager.alerts` to e.g. update their
attributes and pass them back to the manager for saving. To create a new
alert, use :attr:`GAlertsManager.create`, and when you next access
:attr:`GAlertsManager.alerts` you'll find an :class:`Alert` object there
for the alert you just created.
"""
def __init__(self, email, s, query, type, freq, vol, deliver, feedurl=None):
assert type in ALERT_TYPES
assert freq in ALERT_FREQS
assert vol in ALERT_VOLS
assert deliver in DELIVER_TYPES
self._email = email
self._s = s
self._query = query
self._type = type
self._freq = freq
self._vol = vol
self._deliver = deliver
self._feedurl = feedurl
def _query_get(self):
return self._query
def _query_set(self, value):
if len(value) > QUERY_MAXLEN:
raise ValueError('Illegal value for Alert.query (must be at most '
'%d characters): %r' % (QUERY_MAXLEN, value))
if not isinstance(value, str):
try:
value = str(value, 'utf-8')
except UnicodeDecodeError:
raise ValueError('Illegal value for Alert.query ' \
'(str(value, \'utf-8\') failed): %r' % value)
self._query = value
query = property(_query_get, _query_set, doc="""\
The search terms this alert will match.
:raises ValueError: if value is not ``str`` or ``str(value)``
fails, or if its length exceeds :attr:`QUERY_MAXLEN`
""")
def _deliver_get(self):
return self._deliver
def _deliver_set(self, value):
if value not in DELIVER_TYPES:
raise ValueError('Illegal value for Alert.deliver: %r' % value)
self._deliver = value
deliver = property(_deliver_get, _deliver_set, doc="""\
The delivery method for this alert.
:raises ValueError: if value is not in :attr:`DELIVER_TYPES`
""")
def _freq_get(self):
return self._freq
def _freq_set(self, value):
if value not in ALERT_FREQS:
raise ValueError('Illegal value for Alert.freq: %r' % value)
self._freq = value
freq = property(_freq_get, _freq_set, doc="""\
The frequency with which results are delivered for this alert.
:raises ValueError: if value is not in :attr:`ALERT_FREQS`
""")
def _vol_get(self):
return self._vol
def _vol_set(self, value):
if value not in ALERT_VOLS:
raise ValueError('Illegal value for Alert.vol: %r' % value)
self._vol = value
vol = property(_vol_get, _vol_set, doc="""\
The volume of results delivered for this alert.
:raises ValueError: if value is not in :attr:`ALERT_VOLS`
""")
def _type_get(self):
return self._type
def _type_set(self, value):
if value not in ALERT_TYPES:
raise ValueError('Illegal value for Alert.type: %r' % value)
self._type = value
type = property(_type_get, _type_set, doc="""\
The type of the results this alert delivers.
:raises ValueError: if value is not in :attr:`ALERT_TYPES`
""")
@property
def email(self):
"""
Returns the email address of the manager that created this alert.
"""
# XXX support Google accounts with multiple email addresses?
return self._email
@property
def feedurl(self):
"""
For feed alerts, returns the url of the feed results are delivered to.
For email alerts, returns ``None``.
**Note:** If you change an :class:`Alert` object from a feed alert to
an email alert (or vice versa) via :attr:`Alert.deliver`, the value of
:attr:`Alert.feedurl` is not updated. You must pass the alert to
:attr:`GAlertsManager.update` to save the changes and then get a
fresh :class:`Alert` object from :attr:`GAlertsManager.alerts` to get
the up-to-date feed url.
"""
return self._feedurl
def __hash__(self):
return hash((self._s, self.query, self.type, self.freq, self.deliver,
self._feedurl))
def __eq__(self, other):
return all(getattr(self, attr) == getattr(other, attr) for attr in
('_s', 'query', 'type', 'freq', 'deliver', '_feedurl'))
def __repr__(self):
return '<%s for "%s" at %s>' % (self.__class__.__name__,
self.query.encode('utf-8'), hex(id(self)))
def __str__(self):
return '<%s query="%s" type="%s" freq="%s" deliver="%s">' % (
self.__class__.__name__,
self.query.encode('utf-8'), self.type, self.freq, self.deliver)
class GAlertsManager(object):
"""
Manages creation, modification, and deletion of Google Alerts for the
Google account associated with *email*.
Resorts to html scraping because no public API has been released.
Note: multiple email addresses can be associated with a single Google
account, and if a user with multiple email addresses associated with her
Google account signs into the web interface, it will allow her to set the
delivery of email alerts to any of her associated email addresses. However,
for now, :class:`GAlertsManager` always uses the email address it's
instantiated with when creating new email alerts or changing feed alerts
to email alerts.
"""
def __init__(self, email, password):
"""
:param email: sign in using this email address. If there is no @
symbol in the value, "@gmail.com" will be appended.
:param password: plaintext password, used only to get a session
cookie. Sent over a secure connection and then discarded.
:raises SignInError: if Google responds with "403 Forbidden" to
our request to sign in
:raises UnexpectedResponseError: if the status code of Google's
response is unrecognized (neither 403 nor 200)
:raises socket.error: e.g. if there is no network connection
"""
if '@' not in email:
email += '@gmail.com'
self.email = email
self.opener = request.build_opener(request.HTTPCookieProcessor())
request.install_opener(self.opener)
self._signin(password)
def _signin(self, password):
"""
Obtains a cookie from Google for an authenticated session.
"""
login_page_url = 'https://accounts.google.com/ServiceLogin'
authenticate_url = 'https://accounts.google.com/ServiceLoginAuth'
# Load login page
login_page_contents = self.opener.open(login_page_url).read()
# Find GALX value
galx_match_obj = re.search(
r'name="GALX" type="hidden"\n*\t*\s*value="(.*)"',
login_page_contents,
re.IGNORECASE,
)
galx_value = galx_match_obj.group(1) \
if galx_match_obj.group(1) is not None else ''
params = parse.urlencode({
'Email': self.email,
'Passwd': password,
'service': 'alerts',
'continue': 'http://www.google.com/alerts/manage?hl=en&gl=us',
'GALX': galx_value,
})
response = self.opener.open(authenticate_url, params)
resp_code = response.getcode()
final_url = response.geturl()
body = response.read()
if resp_code == 403 or final_url == authenticate_url:
raise SignInError(
'Got 403 Forbidden; bad email/password combination?'
)
if resp_code != 200:
raise UnexpectedResponseError(
resp_code,
response.info().headers,
body,
)
def _scrape_sig(self, path='/alerts'):
"""
Google signs forms with a value in a hidden input named "x" to
prevent xss attacks, so we need to scrape this out and submit it along
with any forms we POST.
"""
url = 'http://www.google.com%s' % path
response = self.opener.open(url)
resp_code = response.getcode()
body = response.read()
if resp_code != 200:
raise UnexpectedResponseError(
resp_code,
response.info().headers,
body,
)
return lxml.html.fromstring(body).xpath('//input[@name="x"]')[0].value
def _scrape_sig_es_hps(self, alert):
"""
Each alert is associated with two values in hidden inputs named "es"
and "hps" which must be scraped and passed along when modifying it
along with the "x" hidden input value to prevent xss attacks.
"""
url = 'http://www.google.com/alerts/edit?hl=en&gl=us&s=%s' % alert._s
response = self.opener.open(url)
resp_code = response.getcode()
body = response.read()
if resp_code != 200:
raise UnexpectedResponseError(
resp_code,
response.info().headers,
body,
)
root = lxml.html.fromstring(body)
sig = root.xpath('//input[@name="x"]')[0].value
es = root.xpath('//input[@name="es"]')[0].value
# hps = soup.findChild('input', attrs={'name': 'hps'})['value']
return tuple(str(i) for i in (sig, es))
@property
def alerts(self):
alerts_url = 'http://www.google.com/alerts/manage?hl=en&gl=us'
response = self.opener.open(alerts_url)
resp_code = response.getcode()
body = response.read()
if resp_code != 200:
raise UnexpectedResponseError(resp_code, [], body)
root = lxml.html.fromstring(body)
trs = root.xpath('//tr[@class="ACTIVE"]')
for tr in trs:
xs = tr.xpath('td[1]/input')[0].attrib['value']
query = tr.xpath('td[2]/a')[0].text
lang = tr.xpath('td[3]')[0].text # 'English'
vol = tr.xpath('td[4]')[0].text # 'Only the best results'
freq = tr.xpath('td[5]')[0].text # 'As-it-happens'
tddeliver = tr.xpath('td[6]')[0]
a_lst = tddeliver.xpath('a')
feed_url, email = None, None
if len(a_lst) > 0: # feed
feed_url = a_lst[0].attrib['href']
deliver = DELIVER_EMAIL # normalize
else: # email
email = tddeliver.text
deliver = DELIVER_FEED
# print s, query, lang, vol, freq
type = TYPE_EVERYTHING
yield Alert(email or self.email, xs, query, type, freq, vol, deliver, feedurl=feed_url)
def create(self, query, type, feed=True, freq=FREQ_ONCE_A_DAY,
vol=VOL_ONLY_BEST):
"""
Creates a new alert.
:param query: the search terms the alert will match
:param type: a value in :attr:`ALERT_TYPES`
:param feed: whether to deliver results via feed or email
:param freq: a value in :attr:`ALERT_FREQS` indicating how often results
should be delivered; used only for email alerts (feed alerts are
updated in real time). Defaults to :attr:`FREQ_ONCE_A_DAY`.
:param vol: a value in :attr:`ALERT_VOLS` indicating volume of results
to be delivered. Defaults to :attr:`VOL_ONLY_BEST`.
"""
url = 'http://www.google.com/alerts/create?hl=en&gl=us'
params = safe_urlencode({
'q': query,
'e': DELIVER_FEED if feed else self.email,
'f': ALERT_FREQS[FREQ_AS_IT_HAPPENS if feed else freq],
't': ALERT_TYPES[type],
'l': ALERT_VOLS[vol],
'x': self._scrape_sig(),
})
response = self.opener.open(url, params)
resp_code = response.getcode()
if resp_code != 200:
raise UnexpectedResponseError(resp_code,
response.info().headers,
response.read(),
)
def update(self, alert):
"""
Updates an existing alert which has been modified.
"""
url = 'http://www.google.com/alerts/save?hl=en&gl=us'
sig, es = self._scrape_sig_es_hps(alert)
params = {
'd': DELIVER_TYPES.get(alert.deliver, DELIVER_DEFAULT_VAL),
'e': self.email,
'es': es,
'q': alert.query,
'se': 'Save',
'x': sig,
't': ALERT_TYPES[alert.type],
'l': ALERT_VOLS[alert.vol],
}
if alert.deliver == DELIVER_EMAIL:
params['f'] = ALERT_FREQS[alert.freq]
params = safe_urlencode(params)
response = self.opener.open(url, params)
resp_code = response.getcode()
if resp_code != 200:
raise UnexpectedResponseError(
resp_code,
response.info().headers,
response.read(),
)
def delete(self, alert):
"""
Deletes an existing alert.
"""
url = 'http://www.google.com/alerts/save?hl=en&gl=us'
params = parse.urlencode({
'da': 'Delete',
'e': self.email,
's': alert._s,
'x': self._scrape_sig(path='/alerts/manage?hl=en&gl=us'),
})
response = self.opener.open(url, params)
resp_code = response.getcode()
if resp_code != 200:
raise UnexpectedResponseError(
resp_code,
response.info().headers,
response.read(),
)
def main():
import socket
import sys
TERMINAL_ENCODING = sys.stdin.encoding
print('Google Alerts Manager\n')
try:
while True:
email = input('email: ')
password = getpass('password: ')
try:
gam = GAlertsManager(email, password)
break
except SignInError:
print('\nSign in failed, try again or hit Ctrl-C to quit\n')
except socket.error:
print('\nCould not connect to Google. Check your network '
'connection and try again, or hit Ctrl-C to quit\n')
def print_alerts(alerts):
print(' # Query Type How often Volume Deliver to')
print(' = ===== ==== ========= ====== ==========')
for i, alert in enumerate(alerts):
query = alert.query
if len(query) > 20:
query = query[:17] + bytes('...')
type = alert.type
freq = alert.freq
vol = alert.vol
deliver = alert.deliver
if deliver == DELIVER_FEED:
deliver = alert.feedurl
num = '%d' % i
print(num.rjust(2), ' ', query.ljust(20), type.ljust(14), freq.ljust(15), vol.ljust(25), deliver)
def prompt_type(default=None):
while True:
print(' Alert type:')
print('\n'.join(' %s. %s' % (v, k) for (k, v) in sorted(
ALERT_TYPES.items(), key=lambda i: int(i[1]))))
if default is not None:
prompt = ' Choice (<Enter> for "%s"): ' % default
else:
prompt = ' Choice: '
type = input(prompt)
for k, v in ALERT_TYPES.items():
if v == type:
return k
if default is not None:
return default
print(' Invalid type, try again\n')
def prompt_vol(default=None):
while True:
print(' Alert volume:')
print('\n'.join(' %s. %s' % (v, k) for (k, v) in sorted(
ALERT_VOLS.items(), key=lambda i: int(i[1]))))
if default is not None:
prompt = ' Choice (<Enter> for "%s"): ' % default
else:
prompt = ' Choice: '
vol = input(prompt)
for k, v in ALERT_VOLS.items():
if v == vol:
return k
if default is not None:
return default
print(' Invalid volume, try again\n')
def prompt_alert(alerts):
while True:
try:
choice = int(input('\n Choice: '))
return alerts[choice]
except (ValueError, IndexError):
print(' Bad input: enter a number from 0 to %d' % (len(alerts) - 1))
def prompt_query(default=None):
if not isinstance(default, str):
default = default.encode('utf-8')
while True:
if default is not None:
prompt = ' Query (<Enter> for "%s"): ' % default
else:
prompt = ' Query: '
query = input(prompt)
query = query.decode(TERMINAL_ENCODING)
if len(query) > QUERY_MAXLEN:
print(' Query must be at most %d characters, try again\n' \
% QUERY_MAXLEN)
continue
if query:
return query
if default is not None:
return default
print(' Query must be at least 1 character, try again\n')
def prompt_deliver(current=None):
if current is None:
if input(' Deliver to [F]eed or [e]mail? (F/e): ') != 'e':
return DELIVER_FEED
return DELIVER_EMAIL
if current == DELIVER_EMAIL:
if input(' Switch to feed delivery (y/N)? ') == 'y':
return DELIVER_FEED
return DELIVER_EMAIL
if input(' Switch to email delivery (y/N)? ') == 'y':
return DELIVER_EMAIL
return DELIVER_FEED
def prompt_freq(default=None):
while True:
print(' Alert frequency:')
print('\n'.join(' %s. %s' % (v, k) for (k, v) in sorted(
ALERT_FREQS.items(), key=lambda i: int(i[1]))))
if default is not None:
prompt = ' Choice (<Enter> for "%s"): ' % default
else:
prompt = ' Choice: '
freq = input(prompt)
for k, v in ALERT_FREQS.items():
if v == freq:
return k
if default is not None:
return default
print(' Invalid frequency, try again\n')
ACTIONS = ('List Alerts', 'Create Alert', 'Edit Alert', 'Delete Alert', 'Quit')
while True:
print('\nActions:')
print('\n'.join(' %d. %s' % (i, v) for (i, v) in enumerate(ACTIONS)))
action = input(' Choice: ')
try:
action = int(action)
action = ACTIONS[action]
except (ValueError, IndexError):
print('Bad input: enter a number from 0 to %d\n' % (len(ACTIONS) - 1))
continue
print('\n%s' % action)
if action == 'Quit':
break
alerts = list(gam.alerts)
if action == 'List Alerts':
print_alerts(alerts)
elif action == 'Create Alert':
query = prompt_query()
type = prompt_type()
feed = prompt_deliver() == DELIVER_FEED
freq = ALERT_FREQS[FREQ_AS_IT_HAPPENS] if feed else prompt_freq()
vol = prompt_vol()
try:
gam.create(query, type, feed=feed, freq=freq, vol=vol)
print('\nAlert created.')
except UnexpectedResponseError:
print('\nCould not create alert.')
import pdb; pdb.set_trace()
elif action == 'Edit Alert':
print_alerts(alerts)
alert = prompt_alert(alerts)
alert.query = prompt_query(default=alert.query)
alert.type = prompt_type(default=alert.type)
alert.deliver = prompt_deliver(current=alert.deliver)
alert.freq = FREQ_AS_IT_HAPPENS if alert.deliver != DELIVER_EMAIL \
else prompt_freq(default=alert.freq)
alert.vol = prompt_vol(default=alert.vol)
try:
gam.update(alert)
print('\nAlert modified.')
except UnexpectedResponseError:
print('\nCould not modify alert.')
import pdb; pdb.set_trace()
elif action == 'Delete Alert':
print_alerts(alerts)
alert = prompt_alert(alerts)
try:
gam.delete(alert)
print ('\nAlert deleted.')
except UnexpectedResponseError:
print('\nCould not delete alert.')
import pdb; pdb.set_trace()
else:
print('code took unexpected branch... typo?')
except (EOFError, KeyboardInterrupt):
print('EOF Error')
return
if __name__ == '__main__':
main()