Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update windspots.py #30

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions providers/windspots.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,30 @@ def process_data(self):
try:
self.log.info("Processing WindsSpots data...")
result = requests.get(
"https://api.windspots.com/windmobile/stationinfo",
"https://api.windspots.org/mobile/stationinfo",
timeout=(self.connect_timeout, self.read_timeout),
verify=False,
)

for windspots_station in result.json()["stationInfo"]:
station_id = None
try:
windspots_id = windspots_station["winId"][10:]
windspots_id = windspots_station["stationName"][10:]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing the 1st 10 chars is returning an invalid id

station = self.save_station(
windspots_id,
windspots_station["shortName"],
windspots_station["name"],
windspots_station["wgs84Latitude"],
windspots_station["wgs84Longitude"],
StationStatus(windspots_station["maintenanceStatus"]),
windspots_station["displayName"],
windspots_station["latitude"],
windspots_station["longitude"],
StationStatus(windspots_station["status"]),
altitude=windspots_station["altitude"],
)
station_id = station["_id"]

try:
# Asking 2 days of data
result = requests.get(
f"https://api.windspots.com/windmobile/stationdatas/windspots:{windspots_id}",
f"https://api.windspots.org/mobile/stationdata?station={windspots_id}",
timeout=(self.connect_timeout, self.read_timeout),
verify=False,
)
Expand All @@ -51,13 +51,13 @@ def process_data(self):
raise ProviderException("Action=Data return invalid json response")

try:
key = arrow.get(windspots_measure["@lastUpdate"], "YYYY-M-DTHH:mm:ssZ").int_timestamp
key = arrow.get(windspots_measure["lastUpdate"], "YYYY-M-DTHH:mm:ssZ").int_timestamp
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lastUpdate is not existing any more with this new API

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lastUpdate is not existing any more with this new API

except arrow.parser.ParserError:
raise ProviderException(
f"Unable to parse measure date: '{windspots_measure['@lastUpdate']}"
f"Unable to parse measure date: '{windspots_measure['lastUpdate']}"
)

wind_direction_last = windspots_measure["windDirectionChart"]["serie"]["points"][0]
wind_direction_last = windspots_measure["windChart"]["serie"]["points"][0]
wind_direction_key = int(wind_direction_last["date"]) // 1000
if arrow.get(key).minute != arrow.get(wind_direction_key).minute:
key_time = arrow.get(key).to("local").format("YY-MM-DD HH:mm:ssZZ")
Expand All @@ -74,10 +74,10 @@ def process_data(self):
station,
key,
wind_direction_last["value"],
windspots_measure.get("windAverage"),
windspots_measure.get("windMax"),
temperature=windspots_measure.get("airTemperature"),
humidity=windspots_measure.get("airHumidity"),
windspots_measure.get("windChartAverage"),
windspots_measure.get("windChartMax"),
temperature=windspots_measure.get("temperature"),
humidity=windspots_measure.get("humidity"),
)
self.insert_new_measures(measures_collection, station, [measure])
except ProviderException as e:
Expand Down