import requests from capparselib.parsers import CAPParser from xml.etree import ElementTree from shapely.geometry import Point, Polygon # Create Point objects p1 = Point(-71.32,-41.15) # Create a Polygon #coords = [(24.950899, 60.169158), (24.953492, 60.169158), (24.953510, 60.170104), (24.950958, 60.169990)] #poly = Polygon(coords) response = requests.get('https://ssl.smn.gob.ar/CAP/AR.php') response.encoding = 'UTF-8' # create element tree object root = ElementTree.fromstring(response.text) # get root element #root = tree.getroot() # create empty list for news items newsitems = [] # iterate news items for item in root.findall('./channel/item'): # empty news dictionary news = {} for child in item: # special checking for namespace object content:media #if child.tag == 'link' or child.tag == 'description': #or child.tag == 'title' or child.tag == 'description': #print(child.tag) #print(child.text) if child.tag == 'link': linktext = requests.get(child.text) alert_list = CAPParser(linktext.text).as_dict() for alert in alert_list: for info in alert['cap_info']: if 'cap_area' in info: for area in info['cap_area']: for polygon_str in area['polygons']: polygon_str_tokens = str(polygon_str).split(' ') points = list() for token in polygon_str_tokens: coords_str = token.split(',') if coords_str[0] != '': x_coord = float(coords_str[1]) y_coord = float(coords_str[0]) points.append(Point(x_coord, y_coord)) poly = Polygon(points) #print(poly) if p1.within(poly): print(child.text) print(info['cap_headline']) print(alert['cap_sent']) print(info['cap_expires']) print(info['cap_description']) #print(alert_list)