Skip to content

Commit

Permalink
pmcjoder provider improvements:
Browse files Browse the repository at this point in the history
- fixed timezone
- ran black formatter, isort and flake8 linter to make cicd happy (see README.md)
  • Loading branch information
ysavary committed Jun 28, 2024
1 parent 6d35f9f commit 65d7cdb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
* @ysavary
/providers/windspots.py @Skyrider31
/providers/gxaircom.py @gereic
/providers/pmcjoder.py @MichalBryxi
33 changes: 18 additions & 15 deletions providers/pmcjoder.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import arrow
import re
from zoneinfo import ZoneInfo

import arrow
import requests
from lxml import html

from winds_mobi_provider import Q_, Pressure, Provider, ProviderException, StationNames, StationStatus, ureg

class MyProvider(Provider):

class PmcJoder(Provider):
provider_code = "pmcjoder"
provider_name = "pmcjoder.ch"
provider_url = "https://www.pmcjoder.ch/webcam/neuhaus/wetterstation/wx.htm"

timezone = ZoneInfo("Europe/Zurich")

wind_directions = {
"N": 0,
"NNO": 1 * (360 / 16),
Expand All @@ -35,17 +40,15 @@ def extract_timestamp(self, data_str):
if match:
time_str = match.group(1)
date_str = match.group(2)

# Combine date and time strings
datetime_str = f"{date_str} {time_str}"

# Parse the combined string using arrow
datetime_obj = arrow.get(datetime_str, "D/M/YY H:mm")
datetime_obj = arrow.get(datetime_str, "D/M/YY H:mm").replace(tzinfo=self.timezone)

# Convert to Unix timestamp
int_timestamp = datetime_obj.int_timestamp
print(int_timestamp)
return int_timestamp
return datetime_obj.int_timestamp
else:
raise ValueError("Date and time not found in the provided string")

Expand All @@ -55,18 +58,18 @@ def process_data(self):
url = "https://www.pmcjoder.ch/webcam/neuhaus/wetterstation/details.htm"

page = requests.get(url, timeout=(self.connect_timeout, self.read_timeout))

tree = html.fromstring(page.content)

date_blob = tree.xpath('//table//tr[3]//td[1]//font//text()')[0]
date_blob = tree.xpath("//table//tr[3]//td[1]//font//text()")[0]

values = tree.xpath("//table//tr[position() >= 5 and position() <= 27]//td[2]//text()")
values = [value.strip() for value in values]

data = [
{
"id": "segelclub-neuhaus-interlaken",
"shortName": "neuhuus",
"shortName": "Neuhuus",
"name": "Segelclub Neuhaus-Interlaken",
"latitude": 46.736866,
"longitude": 7.654292,
Expand Down Expand Up @@ -122,9 +125,9 @@ def process_data(self):
self.log.info("...Done !")


def my_provider():
MyProvider().process_data()
def pmcjoder():
PmcJoder().process_data()


if __name__ == "__main__":
my_provider()
pmcjoder()
1 change: 1 addition & 0 deletions run_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def run_scheduler():
("providers.meteoswiss:meteoswiss", 5),
("providers.pdcs:pdcs", 5),
("providers.pioupiou:pioupiou", 5),
("providers.pmcjoder:pmcjoder", 5),
("providers.romma:romma", 5),
("providers.slf:slf", 5),
("providers.thunerwetter:thunerwetter", 5),
Expand Down

0 comments on commit 65d7cdb

Please sign in to comment.