def find_coords(page, ibox=False): lat = False lon = False if not ibox: ibox = parse_infobox(page) if 'latitude' in ibox: lat = ibox['latitude'] elif 'Latitude' in ibox: lat = ibox['Latitude'] if lat: if 'longitude' in ibox: lon = ibox['longitude'] elif 'Longitude' in ibox: lon = ibox['Longitude'] if lat and lon: return (lon, lat) text = ''.join(page) match = re.search( r'\{\{coord\|(\d+)\|(\d+)\|(\d+)\|N\|(\d+)\|(\d+)\|(\d+)\|E', text, re.IGNORECASE) if match: lon1 = match.groups()[0:3] lat1 = match.groups()[3:6] lon = int(lon1[0]) + (int(lon1[1]) / 60.0) + (int(lon1[2]) / 3600.0) lat = int(lat1[0]) + (int(lat1[1]) / 60.0) + (int(lat1[2]) / 3600.0) return (lon, lat)
def inserter(page, cats, title, lon, lat, sha1): if lon and lat: try: new_kwiki, created = models.KircheWikipedia.\ objects.get_or_create(title=title) if created: ibox = parse_infobox(page) new_kwiki.infobox = json.dumps(ibox) new_kwiki.sha1 = sha1 new_kwiki.contents = ''.join(page) if not isinstance(lon, bool): new_kwiki.lon = lon if not isinstance(lat, bool): new_kwiki.lat = lat new_kwiki.save() sys.stdout.write('.') sys.stdout.flush() except: sys.stderr.write('\n!!!!ERROR inserting %s\n' % title) sys.stderr.flush()