Upload files to ''
Added parser and plotter files
This commit is contained in:
parent
97c8e17e3f
commit
9feaf0be3f
45
plotter.py
Normal file
45
plotter.py
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
import requests
|
||||||
|
import geopandas as gpd
|
||||||
|
#import folium
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
from capparselib.parsers import CAPParser
|
||||||
|
|
||||||
|
from xml.etree import ElementTree
|
||||||
|
|
||||||
|
from shapely.geometry import Point, Polygon
|
||||||
|
|
||||||
|
import contextily as ctx
|
||||||
|
|
||||||
|
|
||||||
|
linktext = requests.get('http://forms.smn.gob.ar/feeds/CAP/oladecalor/87765_cap_en.xml')
|
||||||
|
alert_list = CAPParser(linktext.text).as_dict()
|
||||||
|
polyList = list()
|
||||||
|
|
||||||
|
if 'cap_area' in alert_list[0]['cap_info'][0]:
|
||||||
|
for area in alert_list[0]['cap_info'][0]['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))
|
||||||
|
|
||||||
|
polyList.append(Polygon(points))
|
||||||
|
|
||||||
|
crs = {'init': 'epsg:4326'}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
for poly in polyList:
|
||||||
|
geo_poly = gpd.GeoSeries(poly, crs=crs)
|
||||||
|
geo_poly.crs = 'epsg:4326'
|
||||||
|
|
||||||
|
area_gdf = gpd.GeoDataFrame(geometry=geo_poly)
|
||||||
|
ax = area_gdf.plot(alpha=0.5)
|
||||||
|
ctx.add_basemap(ax, zoom=10, crs='EPSG:4326',source=ctx.providers.CartoDB.Positron)
|
||||||
|
#ax.set_axis_off()
|
||||||
|
|
||||||
|
plt.show()
|
74
smn_parser.py
Normal file
74
smn_parser.py
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
|
||||||
|
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)
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user