Skip to content

Commit 5b7c268

Browse files
committed
Upgrade FFVL provider with the new API. Waiting for encoding fix on their side...
1 parent b2106ac commit 5b7c268

File tree

4 files changed

+42
-77
lines changed

4 files changed

+42
-77
lines changed

.env.localhost.template

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,15 @@
1-
# COMMONS
1+
# Commons
22
MONGODB_URL=mongodb://localhost:8011/winds
33
REDIS_URL=redis://localhost:8012/0
4-
ADMIN_DB_URL=postgres://postgres:postgres@localhost:8016/winds
5-
64
GOOGLE_API_KEY=
75

8-
# PROVIDERS
9-
10-
# Windline
11-
WINDLINE_SQL_URL=
12-
13-
# METAR
14-
CHECKWX_API_KEY=
15-
16-
# Romma
17-
ROMMA_KEY=
18-
19-
# iWeathar
20-
IWEATHAR_KEY=
21-
22-
# BornToFly
6+
# Providers
7+
ADMIN_DB_URL=postgres://postgres:postgres@localhost:8016/winds
238
BORN_TO_FLY_VENDOR_ID=
249
BORN_TO_FLY_DEVICE_ID=
25-
26-
# Windy
10+
CHECKWX_API_KEY=
11+
FFVL_API_KEY=
12+
IWEATHAR_KEY=
13+
ROMMA_KEY=
14+
WINDLINE_SQL_URL=
2715
WINDY_API_KEY=

.env.template

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,15 @@
1-
# COMMONS
1+
# Commons
22
MONGODB_URL=mongodb://mongodb:27017/winds
33
REDIS_URL=redis://redis:6379/0
4-
ADMIN_DB_URL=postgres://postgres:postgres@postgres:5432/winds
5-
64
GOOGLE_API_KEY=
75

8-
# PROVIDERS
9-
10-
# Windline
11-
WINDLINE_SQL_URL=
12-
13-
# METAR
14-
CHECKWX_API_KEY=
15-
16-
# Romma
17-
ROMMA_KEY=
18-
19-
# iWeathar
20-
IWEATHAR_KEY=
21-
22-
# BornToFly
6+
# Providers
7+
ADMIN_DB_URL=postgres://postgres:postgres@postgres:5432/winds
238
BORN_TO_FLY_VENDOR_ID=
249
BORN_TO_FLY_DEVICE_ID=
25-
26-
# Windy
10+
CHECKWX_API_KEY=
11+
FFVL_API_KEY=
12+
IWEATHAR_KEY=
13+
ROMMA_KEY=
14+
WINDLINE_SQL_URL=
2715
WINDY_API_KEY=

providers/ffvl.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,34 @@
1-
import logging
1+
import json
22

33
import arrow
44
import requests
55
from dateutil import tz
6-
from tenacity import after_log, retry, stop_after_delay, wait_random_exponential
76

7+
from settings import FFVL_API_KEY
88
from winds_mobi_provider import Pressure, Provider, ProviderException, StationStatus
99

1010

1111
class Ffvl(Provider):
1212
provider_code = "ffvl"
1313
provider_name = "ffvl.fr"
14-
provider_url = "http://www.balisemeteo.com"
14+
provider_url = "https://www.balisemeteo.com"
15+
16+
def __init__(self, ffvl_api_key):
17+
super().__init__()
18+
self.ffvl_api_key = ffvl_api_key
1519

1620
def process_data(self):
1721
stations = {}
1822
try:
1923
self.log.info("Processing FFVL data...")
2024

2125
result = requests.get(
22-
"http://data.ffvl.fr/json/balises.json", timeout=(self.connect_timeout, self.read_timeout)
26+
f"https://data.ffvl.fr/api/?base=balises&r=list&mode=json&key={self.ffvl_api_key}",
27+
timeout=(self.connect_timeout, self.read_timeout),
2328
)
24-
ffvl_stations = result.json()
29+
# TODO: remove the BOM encoding when the FFVL will fix the forbidden json encoding on their side
30+
# https://www.rfc-editor.org/rfc/rfc7159#section-8.1
31+
ffvl_stations = json.loads(result.content.decode("utf-8-sig"))
2532

2633
for ffvl_station in ffvl_stations:
2734
ffvl_id = None
@@ -52,20 +59,13 @@ def process_data(self):
5259
self.log.exception(f"Error while processing stations: {e}")
5360

5461
try:
55-
56-
@retry(
57-
wait=wait_random_exponential(multiplier=2, min=2),
58-
stop=stop_after_delay(60),
59-
after=after_log(self.log, logging.WARNING),
62+
result = requests.get(
63+
f"https://data.ffvl.fr/api/?base=balises&r=releves_meteo&key={self.ffvl_api_key}",
64+
timeout=(self.connect_timeout, self.read_timeout),
6065
)
61-
def request_data():
62-
# data.ffvl.fr randomly returns an empty file instead the json doc
63-
result = requests.get(
64-
"http://data.ffvl.fr/json/relevesmeteo.json", timeout=(self.connect_timeout, self.read_timeout)
65-
)
66-
return result.json()
67-
68-
ffvl_measures = request_data()
66+
# TODO: remove the BOM encoding when the FFVL will fix the forbidden json encoding on their side
67+
# https://www.rfc-editor.org/rfc/rfc7159#section-8.1
68+
ffvl_measures = json.loads(result.content.decode("utf-8-sig"))
6969

7070
ffvl_tz = tz.gettz("Europe/Paris")
7171
for ffvl_measure in ffvl_measures:
@@ -107,7 +107,7 @@ def request_data():
107107

108108

109109
def ffvl():
110-
Ffvl().process_data()
110+
Ffvl(FFVL_API_KEY).process_data()
111111

112112

113113
if __name__ == "__main__":

settings.py

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22

3-
# COMMONS
3+
# Commons
44
MONGODB_URL = os.environ.get("MONGODB_URL") or "mongodb://localhost:27017/winds_mobi"
55
REDIS_URL = os.environ.get("REDIS_URL") or "redis://localhost:6379/0"
66
GOOGLE_API_KEY = os.environ.get("GOOGLE_API_KEY")
@@ -9,24 +9,13 @@
99
SENTRY_URL = os.environ.get("SENTRY_URL")
1010
ENVIRONMENT = os.environ.get("ENVIRONMENT") or "development"
1111

12-
# PROVIDERS
12+
# Providers
1313
ADMIN_DB_URL = os.environ.get("ADMIN_DB_URL") or "postgres://postgres:postgres@localhost:5432/winds_mobi"
14-
15-
# Windline
16-
WINDLINE_SQL_URL = os.environ.get("WINDLINE_SQL_URL")
17-
18-
# METAR
19-
CHECKWX_API_KEY = os.environ.get("CHECKWX_API_KEY")
20-
21-
# Romma
22-
ROMMA_KEY = os.environ.get("ROMMA_KEY")
23-
24-
# iWeathar
25-
IWEATHAR_KEY = os.environ.get("IWEATHAR_KEY")
26-
27-
# BornToFly
2814
BORN_TO_FLY_VENDOR_ID = os.environ.get("BORN_TO_FLY_VENDOR_ID")
2915
BORN_TO_FLY_DEVICE_ID = os.environ.get("BORN_TO_FLY_DEVICE_ID")
30-
31-
# Windy
16+
CHECKWX_API_KEY = os.environ.get("CHECKWX_API_KEY") # For METAR provider
17+
FFVL_API_KEY = os.environ.get("FFVL_API_KEY")
18+
IWEATHAR_KEY = os.environ.get("IWEATHAR_KEY")
19+
ROMMA_KEY = os.environ.get("ROMMA_KEY")
20+
WINDLINE_SQL_URL = os.environ.get("WINDLINE_SQL_URL")
3221
WINDY_API_KEY = os.environ.get("WINDY_API_KEY")

0 commit comments

Comments
 (0)