File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -48,13 +48,17 @@ def parse_weather_data(body):
4848 body = re .sub (r"^([0-9]{3})/([0-9]{3})" , "c\\ 1s\\ 2" , body )
4949 body = body .replace ('s' , 'S' , 1 )
5050
51- data = re . findall ( r"([cSgtrpPlLs#]\d{3}|t-\d{2}|h\d{2}|b\d{5}|s\.\d{2}|s\d\.\d)" , body )
52- data = map ( lambda x : ( key_map [ x [ 0 ]] , val_map [ x [ 0 ]]( x [ 1 :])), data )
51+ # match as many parameters from the start, rest is comment
52+ data = re . match ( r"^([cSgtrpPlLs#][0-9\-\. ]{3}|h[0-9\. ]{2}|b[0-9\. ]{5})+" , body )
5353
54- parsed .update (dict (data ))
55-
56- # strip weather data
57- body = re .sub (r"([cSgtrpPlLs#][0-9\-\. ]{3}|h[0-9\. ]{2}|b[0-9\. ]{5})" , '' , body )
54+ if data :
55+ data = data .group ()
56+ # split out data from comment
57+ body = body [len (data ):]
58+ # parse all weather parameters
59+ data = re .findall (r"([cSgtrpPlLs#]\d{3}|t-\d{2}|h\d{2}|b\d{5}|s\.\d{2}|s\d\.\d)" , data )
60+ data = map (lambda x : (key_map [x [0 ]] , val_map [x [0 ]](x [1 :])), data )
61+ parsed .update (dict (data ))
5862
5963 return (body , parsed )
6064
Original file line number Diff line number Diff line change @@ -204,11 +204,11 @@ def test_rain_raw(self):
204204 def test_positionless_packet (self ):
205205
206206 expected = {
207- 'comment' : 'wRSW ' ,
207+ 'comment' : '.ABS1.2CDF ' ,
208208 'format' : 'wx' ,
209209 'from' : 'A' ,
210210 'path' : [],
211- 'raw' : 'A>B:_10090556c220s004g005t077r010p020P030h50b09900s5.5wRSW ' ,
211+ 'raw' : 'A>B:_10090556c220s004g005t077r010p020P030h50b09900s5.5.ABS1.2CDF ' ,
212212 'to' : 'B' ,
213213 'via' : '' ,
214214 'wx_raw_timestamp' : '10090556' ,
@@ -226,11 +226,11 @@ def test_positionless_packet(self):
226226 }
227227 }
228228
229- packet = "A>B:_10090556c220s004g005t077r010p020P030h50b09900s5.5wRSW "
229+ packet = "A>B:_10090556c220s004g005t077r010p020P030h50b09900s5.5.ABS1.2CDF "
230230
231231 self .assertEqual (expected , parse (packet ))
232232
233- packet2 = "A>B:_10090556c220s112g t r h b wRSW "
233+ packet2 = "A>B:_10090556c220s112g t r h b .ABS1.2CDF "
234234 expected ['raw' ] = packet2
235235 expected ['weather' ] = {
236236 "wind_direction" : 220 ,
@@ -239,7 +239,7 @@ def test_positionless_packet(self):
239239
240240 self .assertEqual (expected , parse (packet2 ))
241241
242- packet3 = "A>B:_10090556c220s112g...t...r...p...P...b.....wRSW "
242+ packet3 = "A>B:_10090556c220s112g...t...r...p...P...b......ABS1.2CDF "
243243 expected ['raw' ] = packet3
244244 expected ['weather' ] = {
245245 "wind_direction" : 220 ,
You can’t perform that action at this time.
0 commit comments