Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: sitescripts/subscriptions/bin/updateStatusPage.py

Issue 29350318: Issue 4382 - Use new syntax to catch exceptions in sitescripts (Closed)
Patch Set: Created Aug. 30, 2016, 1:28 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 # This file is part of the Adblock Plus web scripts, 1 # This file is part of the Adblock Plus web scripts,
2 # Copyright (C) 2006-2016 Eyeo GmbH 2 # Copyright (C) 2006-2016 Eyeo GmbH
3 # 3 #
4 # Adblock Plus is free software: you can redistribute it and/or modify 4 # Adblock Plus is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License version 3 as 5 # it under the terms of the GNU General Public License version 3 as
6 # published by the Free Software Foundation. 6 # published by the Free Software Foundation.
7 # 7 #
8 # Adblock Plus is distributed in the hope that it will be useful, 8 # Adblock Plus is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details. 11 # GNU General Public License for more details.
12 # 12 #
13 # You should have received a copy of the GNU General Public License 13 # You should have received a copy of the GNU General Public License
14 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 14 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
15 15
16 import re 16 import re
17 import sys 17 import sys
18 import os 18 import os
19 from urlparse import urlparse 19 from urlparse import urlparse
20 import eventlet 20 import eventlet
21 from eventlet.green import urllib2 21 from eventlet.green import urllib2
22 from sitescripts.utils import get_config, get_template, setupStderr 22 from sitescripts.utils import get_config, get_template, setupStderr
23 import sitescripts.subscriptions.subscriptionParser as subscriptionParser 23 import sitescripts.subscriptions.subscriptionParser as subscriptionParser
24 24
25 25
26 def checkURL(url): 26 def checkURL(url):
27 try: 27 try:
28 result = urllib2.urlopen(url, timeout=60).read(1) 28 result = urllib2.urlopen(url, timeout=60).read(1)
29 return (url, True) 29 return (url, True)
30 except urllib2.HTTPError, e: 30 except urllib2.HTTPError as e:
31 return (url, e.code) 31 return (url, e.code)
32 except: 32 except:
33 return (url, False) 33 return (url, False)
34 34
35 35
36 def checkSite(site): 36 def checkSite(site):
37 try: 37 try:
38 result = urllib2.urlopen('http://downforeveryoneorjustme.com/' + site, t imeout=60).read() 38 result = urllib2.urlopen('http://downforeveryoneorjustme.com/' + site, t imeout=60).read()
39 if re.search(r'\blooks down\b', result): 39 if re.search(r'\blooks down\b', result):
40 return (site, False) 40 return (site, False)
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 }) 90 })
91 return result 91 return result
92 92
93 if __name__ == '__main__': 93 if __name__ == '__main__':
94 setupStderr() 94 setupStderr()
95 95
96 subscriptions = checkSubscriptions() 96 subscriptions = checkSubscriptions()
97 outputFile = get_config().get('subscriptions', 'statusPage') 97 outputFile = get_config().get('subscriptions', 'statusPage')
98 template = get_template(get_config().get('subscriptions', 'statusTemplate')) 98 template = get_template(get_config().get('subscriptions', 'statusTemplate'))
99 template.stream({'subscriptions': subscriptions}).dump(outputFile, encoding= 'utf-8') 99 template.stream({'subscriptions': subscriptions}).dump(outputFile, encoding= 'utf-8')
OLDNEW
« no previous file with comments | « sitescripts/stats/bin/logprocessor.py ('k') | sitescripts/subscriptions/combineSubscriptions.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld