Skip to content

Commit

Permalink
fikset på nedlasting fra wms og api nøkkel skjuling
Browse files Browse the repository at this point in the history
  • Loading branch information
victbakk committed Feb 16, 2024
1 parent befe3f8 commit f7fdbab
Show file tree
Hide file tree
Showing 13 changed files with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions WMS/Orotfoto.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
import os
from dotenv import load_dotenv
import requests
from datetime import datetime
import urllib.parse
from dotenv import load_dotenv

# Finner path til .env filen som ligger i ngisopenapi mappen
current_script_directory = os.path.dirname(os.path.abspath(__file__))
project_root = os.path.abspath(os.path.join(current_script_directory, '..', 'ngisopenapi'))
env_file_path = os.path.join(project_root, '.env')

# Laster inn environment fra .env filen
load_dotenv()
# Laster .env fra riktig path
load_dotenv(env_file_path)

# Laster API nøkkel
api_key = os.getenv("NK_WMS_API_KEY")
# Henter API nøkkelen fra .env
api_key = os.getenv('NK_WMS_API_KEY')

# Definerer WMS url
wms_url = 'https://waapi.webatlas.no/wms-orto/'

# Setter directory for lagring av bilde
images_directory = "ortofoto_images"

# Lager hele pathen i samme mappe
# Lager hele pathen i samme mappe
images_directory_path = os.path.join(os.path.dirname(__file__), images_directory)

# Sjekker om filen eksisterer
Expand All @@ -41,9 +46,13 @@
print("Generated URL:")
print(full_url)

"""
# Headers som legger en browser request
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3"
}

# Oppretter en get request til WMS serveren gjennom url og api nøkkel
response = requests.get(wms_url, params=params)
response = requests.get(full_url, headers=headers) # Ensure the request is made to `full_url`

if response.status_code == 200:
# Genererer et filnavn basert på dato og tid bildet ble hentet på
Expand All @@ -58,4 +67,3 @@
print(f"Bildet ble lagret i {image_path}.")
else:
print(f"Kunne ikke lagre bilde, statuskode: {response.status_code}")
"""
File renamed without changes.
Binary file not shown.
Binary file removed WMS/__pycache__/test_util.cpython-311.pyc
Binary file not shown.
Binary file removed WMS/__pycache__/util.cpython-311.pyc
Binary file not shown.
Binary file added WMS/ortofoto_images/output_20240216104419.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed __pycache__/__init__.cpython-311.pyc
Binary file not shown.
Binary file removed __pycache__/deleteFolder.cpython-311.pyc
Binary file not shown.
Binary file modified __pycache__/main.cpython-311.pyc
Binary file not shown.
Binary file removed __pycache__/main.cpython-39.pyc
Binary file not shown.
Binary file removed __pycache__/test_main.cpython-311-pytest-7.4.4.pyc
Binary file not shown.
Empty file added kartai/kartai/__init__.py
Empty file.
Empty file added ngisopenapi/__init__ .py
Empty file.

0 comments on commit f7fdbab

Please sign in to comment.