Skip to content

Commit

Permalink
load data from map data service rather than from file
Browse files Browse the repository at this point in the history
  • Loading branch information
kruegercharles committed Mar 28, 2024
1 parent b9926ce commit 8fc7e45
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
22 changes: 12 additions & 10 deletions backend/construction/management/commands/import_constructions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import json

import requests
from construction.models import Construction
from django.conf import settings
from django.contrib.gis.geos import Point
from django.core.management.base import BaseCommand

Expand Down Expand Up @@ -62,14 +60,18 @@ def handle(self, *args, **options):

print("Importing construction data from priobike-map-data...")

# Import GeoJSON file from data folder.
with open(
str(settings.BASE_DIR)
+ "/sample-construction-sites-v2.geojson" # TODO: use real data
) as f:
data = json.load(f)
BASE_URL = "priobike.vkw.tu-dresden.de/production"
API = "https://" + BASE_URL + "/map-data/construction_sites_v2.geojson"

try:
response = requests.get(API)
response.raise_for_status()
data = response.json()
except Exception as e:
print("Failed to fetch construction data: " + str(e))
return

print(f"Found {len(data['features'])} construction sites.")
print(f"Loaded {len(data['features'])} construction sites.")

try:
Construction.objects.all().delete()
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ gunicorn = "^21.2.0"
scipy = "^1.12.0"
numpy = "^1.26.4"
shapely = "^2.0.3"
requests = "^2.31.0"

[tool.poetry.dev-dependencies]

Expand Down
File renamed without changes.

0 comments on commit 8fc7e45

Please sign in to comment.