Repaired function update_wrmapcache.
authorphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Sun, 29 Jan 2017 22:19:06 +0000 (22:19 +0000)
committerphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Sun, 29 Jan 2017 22:19:06 +0000 (22:19 +0000)
git-svn-id: http://www.winterrodeln.org/svn/wrpylib/trunk@2632 7aebc617-e5e2-0310-91dc-80fb5f6d2477

wrpylib/wrmwcache.py

index 1540dc8fe58181311832d0c3793608de3401df7d..9aedf98d6b7129a07543f368bd313061685d6672 100644 (file)
@@ -172,11 +172,16 @@ def update_wrmapcache(connection):
     
     # Refill wrmappointcache and wrmappathcache tables
     for sledrun_page in sledrun_pages:
-        try: 
-            start, content, endtag, end = mwmarkup.find_tag(sledrun_page.old_text, 'wrmap')
-            if content is None:
-                continue
-            geojson = wrmwmarkup.parse_wrmap(sledrun_page.old_text[start:end])
+        try:
+            import mwparserfromhell
+            wikicode = mwparserfromhell.parse(sledrun_page.old_text)
+            wrmap_list = wikicode.filter_tags(recursive=False, matches=lambda tag: tag.tag == 'wrmap')
+            if len(wrmap_list) == 0:
+                continue  # not wrmap in page
+            if len(wrmap_list) > 1:
+                raise UpdateCacheError('{} <wrmap ...> entries found in article "{}"'.format(len(wrmap_list), sledrun_page.page_title))
+            wrmap = wrmap_list[0]
+            geojson = wrmwmarkup.parse_wrmap(str(wrmap))
 
             for feature in geojson['features']:
                 properties = feature['properties']