-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwmoid.py
54 lines (43 loc) · 1.52 KB
/
wmoid.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"""
#############################################################################################
# Name: wmoid.py
#
# Author: Michel Grenier
#
# Date: 2009-06-19
#
# Description: parse the wmo_id.conf file
# this file is used to force the station name into the ingested filename
#
#############################################################################################
"""
import os, os.path, sys
import PXPaths
class wmoid:
def __init__(self, logger ):
self.logger = logger
self.wmo_ids = []
PXPaths.normalPaths()
self.path = PXPaths.ETC + 'wmo_id.conf'
def parse(self):
if not os.path.isfile(self.path) : return self.wmo_ids
try :
file = open(self.path,'r')
lines = file.readlines()
file.close()
for line in lines:
if len(line) <= 0 : continue
if line[0] == '#' : continue
if line[0] == '\n' : continue
words = line.split()
if len(words) == 0 : continue
self.wmo_ids.extend(words)
except:
(type, value, tb) = sys.exc_info()
self.logger.error("Type: %s, Value: %s" % (type, value))
self.logger.error("Problem with parsing the wmo_id.conf")
return []
#self.logger.info("wmo_id.conf gives %s" % self.wmo_ids)
return self.wmo_ids
if __name__ == '__main__':
print wmoid(None).parse()