diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 1f9c3b6..d11adfc 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -25,10 +25,13 @@ jobs:
git config --global user.name "Weather Exporter"
- name: Install dependencies
run: |
- pip install . flake8 pyre-check
+ pip3 install -e ".[tests]"
- name: flake8 linting
run: |
flake8
- name: pyre type checking
run: |
- pyre
+ pyre --noninteractive check
+ - name: execute tests
+ run: |
+ pytest
diff --git a/prometheus_fzj_weather_exporter/fzj_weather.py b/prometheus_fzj_weather_exporter/fzj_weather.py
index c820c7d..39d1a30 100755
--- a/prometheus_fzj_weather_exporter/fzj_weather.py
+++ b/prometheus_fzj_weather_exporter/fzj_weather.py
@@ -7,7 +7,7 @@
import requests
import re
-from bs4 import BeautifulSoup
+from bs4 import BeautifulSoup # pyre-ignore[21]
def get_weather_data(url: str,
diff --git a/pyproject.toml b/pyproject.toml
new file mode 100644
index 0000000..4cf2197
--- /dev/null
+++ b/pyproject.toml
@@ -0,0 +1,38 @@
+[build-system]
+requires = ["setuptools", "setuptools-scm"]
+build-backend = "setuptools.build_meta"
+
+[project]
+name = "prometheus-fzj-weather-exporter"
+authors = [
+ {name = "Oskar Druska"},
+]
+description = "A Prometheus exporter for Weather Data from the FZJ."
+version = "1.3.0"
+readme = "README.md"
+requires-python = ">=3.11"
+keywords = ["prometheus", "exporter", "weather", "FZJ"]
+license = {text = "ISC"}
+classifiers = [
+ "Programming Language :: Python :: 3",
+]
+dependencies = [
+ 'BeautifulSoup4',
+ 'prometheus_client',
+ 'requests',
+]
+
+[project.urls]
+"Bug Reports" ="https://github.com/psyinfra/prometheus-fzj-weather-exporter/issues/"
+"Source" = "https://github.com/psyinfra/prometheus-fzj-weather-exporter/"
+
+[project.optional-dependencies]
+tests = [
+ 'flake8',
+ 'pyre-check',
+ 'pytest',
+ 'pytest-vcr',
+]
+
+[project.scripts]
+prometheus_fzj_weather_exporter = "prometheus_fzj_weather_exporter.main:main"
diff --git a/setup.py b/setup.py
deleted file mode 100644
index 2f9fcd6..0000000
--- a/setup.py
+++ /dev/null
@@ -1,25 +0,0 @@
-#!/usr/bin/env python3
-''' setup file for installation of fzj_weather prometheus exporter '''
-from setuptools import setup, find_packages
-
-setup(
- name='prometheus_fzj_weather_exporter',
- version='1.3.0',
- description='prometheus exporter for weather data from FZJ',
- author='Oskar Druska',
- author_email='o.druska@fz-juelich.de',
- packages=find_packages(),
- license='ISC',
- install_requires=[
- 'requests',
- 'BeautifulSoup4',
- 'prometheus_client'
- ],
- python_requires=">=3.11",
- entry_points={
- 'console_scripts': [
- 'prometheus_fzj_weather_exporter=prometheus_fzj_weather_exporter.main:main'
- ],
- },
-
-)
diff --git a/tests/cassettes/test_scrape_weather_website.yaml b/tests/cassettes/test_scrape_weather_website.yaml
new file mode 100644
index 0000000..025329c
--- /dev/null
+++ b/tests/cassettes/test_scrape_weather_website.yaml
@@ -0,0 +1,1593 @@
+interactions:
+- request:
+ body: null
+ headers:
+ Accept:
+ - '*/*'
+ Accept-Encoding:
+ - gzip, deflate
+ Connection:
+ - keep-alive
+ User-Agent:
+ - python-requests/2.31.0
+ method: GET
+ uri: https://www.fz-juelich.de/de/gs/ueber-uns/meteo/aktuelle-wetterdaten/wetterdaten
+ response:
+ body:
+ string: "\n
Wetterdaten von J\xFClichWetterdaten von J\xFClich
\n\n
\n Aktuelle Messwerte vom 16.04.2024 12:00 Uhr MEZ
+ \n
\n\n
\n
+ \ \n \n Luftdruck (92 m
+ ü.N.H.N.) \n | \n \n 991.7 hPa\n
+ \ | \n
\n \n \n
+ \ Lufttemperatur \n | \n \n 10.2 °C\n
+ \ | \n
\n \n \n
+ \ relative Feuchte \n | \n \n 82 %\n
+ \ | \n
\n \n \n
+ \ Windstärke \n | \n \n 8.0 m/s\n
+ \ | \n
\n \n \n
+ \ Windrichtung \n | \n \n 265 Grad\n
+ \ | \n
\n
\n\n
\n
\n\n
Wetterentwicklung während
+ der vergangenen 24 Stunden
\n\n
\n \n \n Messgröße \n | \n \n Die X-Achsen geben die Zeit (Stunden) in MEZ an.\n
+ \ | \n
\n \n \n Luftdruck [hPa] \n | \n \n \n | \n
+ \
\n \n \n
+ \ Temperatur [° C] \n | \n \n \n | \n
+ \
\n \n \n
+ \ rel. Feuchte [%] \n | \n \n
+ \ \n | \n
+ \
\n \n \n
+ \ Windgeschwin- digkeit [m/s] \n | \n \n \n | \n
+ \
\n \n \n
+ \ max. Wind- spitze [m/s] \n | \n \n
+ \
+ \n | \n
\n \n \n Windrichtung [Grad] \n | \n \n \n | \n
+ \
\n \n \n
+ \ Niederschlags- summe [mm] \n | \n \n
+ \ \n | \n
+ \
\n \n \n
+ \ Sonnenschein- dauer [%] \n | \n \n
+ \ \n | \n
\n
+ \
\n\n
\n
\n\n
Klimawerte
\n\n
+ \
\n
+ \ \n \n
+ \ Tiefste Temperatur \n (gestern 7:00 - heute 7:00 MEZ)
+ \n | \n \n 3.1 °C\n
+ \ | \n
\n \n \n Höchste Temperatur
+ \n (gestern 0:00 - heute 0:00 MEZ) \n
+ \ | \n \n 13.7 °C\n
+ \ | \n
\n \n \n Windstärkemaximum \n (gestern 0:00 - heute 0:00 MEZ)
+ \n | \n \n 22.5 m/s\n
+ \ | \n
\n \n \n 24-std. Niederschlagssumme
+ \n (gestern 0:00 - heute 0:00 MEZ) \n
+ \ | \n \n 8.4 mm\n
+ \ | \n
\n \n \n Sonnenscheindauer (gestern) \n | \n
+ \ \n 4.6 h\n | \n
+ \
\n
\n\n
\n
\n\n
Astronomische Daten
+ für Jülich vom 16.04.2024
\n\n
\n \n
+ \ \n Sonnenaufgang \n | \n
+ \ \n 5:37 MEZ\n | \n
+ \
\n \n \n
+ \ Sonnenuntergang \n | \n \n
+ \ 19:33 MEZ\n | \n
\n \n \n max. Sonnenhöhe
+ heute \n | \n \n 49.2
+ Grad\n | \n
\n
\n\n
\n
Letzte
+ \xC4nderung:\_07.02.2024
\n
+ \ "
+ headers:
+ cache-control:
+ - private
+ content-encoding:
+ - gzip
+ content-type:
+ - text/html; charset=utf-8
+ date:
+ - Tue, 16 Apr 2024 11:10:43 GMT
+ etag:
+ - W/"27741-wJoW5zn+rQVBHUWa5yfWC+DvfZU"
+ permissions-policy:
+ - camera=(), display-capture=(), geolocation=(), microphone=()
+ referrer-policy:
+ - strict-origin-when-cross-origin
+ set-cookie:
+ - SERVERID=2; path=/
+ strict-transport-security:
+ - max-age=63072000
+ transfer-encoding:
+ - chunked
+ vary:
+ - Accept-Encoding
+ x-frame-options:
+ - SAMEORIGIN
+ status:
+ code: 200
+ message: OK
+version: 1
diff --git a/tests/test_prometheus_fzj_weather_exporter.py b/tests/test_prometheus_fzj_weather_exporter.py
new file mode 100644
index 0000000..90563dc
--- /dev/null
+++ b/tests/test_prometheus_fzj_weather_exporter.py
@@ -0,0 +1,24 @@
+import pytest
+
+from prometheus_fzj_weather_exporter.fzj_weather_crawler import fzj_weather_crawler
+
+# variables to crawl weather data
+LISTEN_ADDRESS = "127.0.0.1:9184"
+WEATHER_URL = "https://www.fz-juelich.de/de/gs/ueber-uns/meteo/aktuelle-wetterdaten/wetterdaten"
+
+
+@pytest.mark.vcr()
+def test_scrape_weather_website() -> None:
+ """Crawl the fzj weather website and verify that data of the expected
+ data type was received."""
+
+ # get weather data
+ weather_data = fzj_weather_crawler(WEATHER_URL,
+ insecure=False)
+
+ # verify contents
+ assert isinstance(weather_data.temperature, float)
+ assert isinstance(weather_data.air_pressure, float)
+ assert isinstance(weather_data.humidity, int)
+ assert isinstance(weather_data.wind_power, float)
+ assert isinstance(weather_data.wind_direction, int)