Skip to content

Commit

Permalink
injecting regions
Browse files Browse the repository at this point in the history
  • Loading branch information
Alfiejz committed Jun 22, 2023
1 parent 226e4e7 commit e2e36a5
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions cap_feed/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,13 @@

region_centroids = ["17.458740234362434 -2.677413176352464", "-80.83261851536723 -2.6920536197633442", "117.78896429869648 -3.1783208418475954", "30.64725652750233 45.572165430308736", "21.18749859869599 31.264366696701767"]

def saveRegions():
count = 0
for region_entry in data:
region = Region()
region.id = region_entry["id"]
region.name = region_entry["region_name"]
coordinates = region_entry["bbox"]["coordinates"][0]
for coordinate in coordinates:
region.polygon += str(coordinates[0]) + "," + str(coordinates[1]) + " "
region.centroid = region_centroids[count]
count += 1
region.save()




def index(request):
getAlerts()
saveRegions()
latest_alert_list = Alert.objects.order_by("-sent")[:10]
template = loader.get_template("cap_feed/index.html")
context = {
Expand All @@ -38,6 +28,19 @@ def index(request):
return HttpResponse(template.render(context, request))


def saveRegions():
count = 0
for region_entry in data:
region = Region()
region.id = region_entry["id"]
region.name = region_entry["region_name"]
coordinates = region_entry["bbox"]["coordinates"][0]
for coordinate in coordinates:
region.polygon += str(coordinates[0]) + "," + str(coordinates[1]) + " "
region.centroid = region_centroids[count]
count += 1
region.save()

# sources = [
# ("https://feeds.meteoalarm.org/feeds/meteoalarm-legacy-atom-france", {'atom': 'http://www.w3.org/2005/Atom', 'cap': 'urn:oasis:names:tc:emergency:cap:1.2'}),
# ("https://feeds.meteoalarm.org/feeds/meteoalarm-legacy-atom-croatia", {'atom': 'http://www.w3.org/2005/Atom', 'cap': 'urn:oasis:names:tc:emergency:cap:1.2'}),
Expand Down

0 comments on commit e2e36a5

Please sign in to comment.