1
- import arrow
2
1
import re
2
+ from zoneinfo import ZoneInfo
3
+
4
+ import arrow
3
5
import requests
4
6
from lxml import html
5
7
6
8
from winds_mobi_provider import Q_ , Pressure , Provider , ProviderException , StationNames , StationStatus , ureg
7
9
8
- class MyProvider (Provider ):
10
+
11
+ class PmcJoder (Provider ):
9
12
provider_code = "pmcjoder"
10
13
provider_name = "pmcjoder.ch"
11
14
provider_url = "https://www.pmcjoder.ch/webcam/neuhaus/wetterstation/wx.htm"
12
15
16
+ timezone = ZoneInfo ("Europe/Zurich" )
17
+
13
18
wind_directions = {
14
19
"N" : 0 ,
15
20
"NNO" : 1 * (360 / 16 ),
@@ -35,17 +40,15 @@ def extract_timestamp(self, data_str):
35
40
if match :
36
41
time_str = match .group (1 )
37
42
date_str = match .group (2 )
38
-
43
+
39
44
# Combine date and time strings
40
45
datetime_str = f"{ date_str } { time_str } "
41
-
46
+
42
47
# Parse the combined string using arrow
43
- datetime_obj = arrow .get (datetime_str , "D/M/YY H:mm" )
44
-
48
+ datetime_obj = arrow .get (datetime_str , "D/M/YY H:mm" ). replace ( tzinfo = self . timezone )
49
+
45
50
# Convert to Unix timestamp
46
- int_timestamp = datetime_obj .int_timestamp
47
- print (int_timestamp )
48
- return int_timestamp
51
+ return datetime_obj .int_timestamp
49
52
else :
50
53
raise ValueError ("Date and time not found in the provided string" )
51
54
@@ -55,18 +58,18 @@ def process_data(self):
55
58
url = "https://www.pmcjoder.ch/webcam/neuhaus/wetterstation/details.htm"
56
59
57
60
page = requests .get (url , timeout = (self .connect_timeout , self .read_timeout ))
58
-
61
+
59
62
tree = html .fromstring (page .content )
60
63
61
- date_blob = tree .xpath (' //table//tr[3]//td[1]//font//text()' )[0 ]
64
+ date_blob = tree .xpath (" //table//tr[3]//td[1]//font//text()" )[0 ]
62
65
63
66
values = tree .xpath ("//table//tr[position() >= 5 and position() <= 27]//td[2]//text()" )
64
67
values = [value .strip () for value in values ]
65
68
66
69
data = [
67
70
{
68
71
"id" : "segelclub-neuhaus-interlaken" ,
69
- "shortName" : "neuhuus " ,
72
+ "shortName" : "Neuhuus " ,
70
73
"name" : "Segelclub Neuhaus-Interlaken" ,
71
74
"latitude" : 46.736866 ,
72
75
"longitude" : 7.654292 ,
@@ -122,9 +125,9 @@ def process_data(self):
122
125
self .log .info ("...Done !" )
123
126
124
127
125
- def my_provider ():
126
- MyProvider ().process_data ()
128
+ def pmcjoder ():
129
+ PmcJoder ().process_data ()
127
130
128
131
129
132
if __name__ == "__main__" :
130
- my_provider ()
133
+ pmcjoder ()
0 commit comments