Changeset 3194
- Timestamp:
- Jun 21, 2006, 3:42:57 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/demos/test_flood_database.py
r3191 r3194 10 10 11 11 base_url = 'http://www.ga.gov.au:8500/oracle/flood/' 12 12 servlet_base_url = 'http://www.ga.gov.au:8500/' 13 13 14 14 def test_site(): 15 """Test flood database16 """15 """Test flood database 16 """ 17 17 18 top_url = 'flood_input_hide.jsp'18 top_url = 'flood_input_hide.jsp' 19 19 20 url = base_url+top_url21 live = False22 print 'Trying to connect to %s' %url23 T = get_page(url)20 url = base_url+top_url 21 live = False 22 print 'Testing %s. ' %url, 23 T = get_page(url) 24 24 25 for line in T:26 #print line.strip()27 if line.startswith('<title>Geoscience Australia: Online Flood Search'):28 live = True29 break25 for line in T: 26 #print line.strip() 27 if line.startswith('<title>Geoscience Australia: Online Flood Search'): 28 live = True 29 break 30 30 31 if live is True: 32 print 'OK: Page %s is live' %url 33 else: 34 msg = 'Page %s is not live' %url 35 raise msg 31 if live is True: 32 print 'OK: Page is live' 33 else: 34 msg = 'Page %s is not live' %url 35 raise msg 36 37 print 36 38 37 39 38 40 def test_database(filename): 39 """Read list of studies from html and try them one by one40 """41 """Read list of studies from html and try them one by one 42 """ 41 43 42 print 'Reading %s' %filename43 fid = open(filename)44 print 'Reading %s' %filename 45 fid = open(filename) 44 46 45 for line in fid.readlines(): 46 print line.strip() 47 for link in get_individual_studies(fid.readlines()): 48 url = base_url+htmlmap(link) 49 50 live = False 51 print 'Testing %s...' %link[:72], 52 T = get_page(url) 53 54 live = False 55 for line in T: 56 if line.startswith('<tr><th>Dataset Name</th>') or\ 57 line.startswith('<h2>Study title only available.</h2>'): 58 live = True 59 break 60 61 if live is True: 62 print 'OK: Link is live' 63 else: 64 msg = 'FAIL: Link is not live: %s' %url 65 raise msg 47 66 48 67 68 # Secon tier links 69 for link in get_second_tier_links(T): 70 url = servlet_base_url+htmlmap(link) 71 72 live = False 73 print 'Testing %s...' %link[:80], 74 T = get_page(url) 75 76 live = False 77 for line in T: 78 #print line.strip() 79 if line.startswith('<tr><td><h3>Participants in '): 80 live = True 81 break 82 83 if live is True: 84 print 'OK: Detail link is live' 85 else: 86 for line in T: 87 print line.strip() 88 msg = 'FAIL: Detail link is not live' 89 print msg 90 91 92 93 def get_second_tier_links(lines): 94 """Scan html lines for flood details and yield 95 """ 96 for line in lines: 97 98 index = line.find('<a href="/servlet/FloodDetailServlet?sno') 99 if index >= 0: 100 start_index = line.find('servlet', index) 101 end_index = line.find('">', start_index) 102 yield line[start_index:end_index] 103 104 105 106 def get_individual_studies(lines): 107 """Scan html lines for individual flood studies and yield links 108 """ 49 109 110 for line in lines: 111 index = line.find('<a href="flood_infolist.jsp?sno') 112 if index >= 0: 113 start_index = line.find('flood_infolist', index) 114 end_index = line.find('">', start_index) 115 116 yield line[start_index:end_index] 117 118 50 119 def get_page(URL): 51 """General routine for getting and caching URL pages52 """120 """General routine for getting and caching URL pages 121 """ 53 122 54 from caching import cache55 56 def _GetPage(URL):57 123 import urllib 58 59 #params = urllib.urlencode({'rivers': 'avoca'})60 #F = urllib.urlopen(URL, params)61 124 62 125 F = urllib.urlopen(URL) … … 64 127 return(T) 65 128 66 #T = cache(_GetPage,URL,verbose=0)67 T = _GetPage(URL)68 return(T)69 129 70 130 71 131 def htmlmap(s): 72 import types73 from string import replace, strip132 import types 133 from string import replace, strip 74 134 75 s = replace(s,'<b>','') 76 s = replace(s,'</b>','') 77 s = replace(s,'<sup>','') 78 s = replace(s,'</sup>','') 79 s = replace(s,'<SUP>','') 80 s = replace(s,'</SUP>','') 81 s = replace(s,'<SUB>','') 82 s = replace(s,'</SUB>','') 83 s = replace(s,'‡','?') 84 return(strip(s)) 135 s = replace(s,' ','%20') 136 return(strip(s)) 85 137 86 138 … … 88 140 89 141 test_site() 90 #test_database('')142 test_database('flood_studies_all.html') 91 143 92 144
Note: See TracChangeset
for help on using the changeset viewer.