get_epncore_parameters.py
2.3 KB
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
#!/usr/bin/python3
import urllib.request
from html.parser import HTMLParser
from bs4 import BeautifulSoup
from re import sub
"""
This script parse the Parameters table on the EpnTAPv2 VO-Paris Confluence page
(voparis-confluence.obspm.fr) and print them in several ways (by setting EXPORT_TYPE):
- CSV: A simple CSV table whicj have the same content as the Confluence table;
example: `"incidence_min";"";"incidence_min";"Double";"deg";"Min incidence angle (solar zenithal angle)";"pos.posAng;stat.min";"";"N"`
- init: A Java code for parameters initalisation, in camelCase
example: `public double incidenceMin;`
- enum: A Java code for emuration, as `THE_PARAMETER(name, class, isOptional, mustBeFilled, unit, UCD, desciption)`
example: `INCIDENCE_MIN("incidence_min", class.Double, false, false, "deg", "pos.posAng;stat.min", "Min incidence angle (solar zenithal angle)"),`
"""
EXPORT_TYPE = 'enum' # 'CSV', or 'init', or 'enum'.
URL = 'https://voparis-confluence.obspm.fr/display/VES/EPN-TAP+V2.0+parameters'
tmp_file, headers = urllib.request.urlretrieve(URL)
html = open(tmp_file)
soup = BeautifulSoup(html.read(), 'html.parser')
# EPN-TAP table is the first one.
table = soup.find_all('table', 'confluenceTable')[0].find('tbody').find_all('tr')
optional = False
for tr in table:
row=[]
for td in tr.find_all('td'):
txt = td.string if td.string and td.string != None else ''
row.append(sub(r'[^\x00-\x7F]', r' ', txt).strip())
if row and row[0] == 'Optional parameters':
optional = True
if not row or row[0] == "" or (row[1]=="" and row[2]=="" and row[3]==""):
continue
row.append('Y' if optional else 'N')
if EXPORT_TYPE == 'CSV':
print('"' + '";"'.join(row) + '"')
elif EXPORT_TYPE == 'init':
var_type = row[3].replace('Text', 'String').replace('Double', 'double').replace('Integer', 'int')
var_name = row[0][0].lower() + row[0].replace('_', ' ').title().replace(' ', '')[1:] # camelCase
print('public %s %s;' % (var_type, var_name))
elif EXPORT_TYPE == 'enum':
var_type = row[3].replace('Text', 'String')
print('%s("%s", class.%s, %s, %s, "%s", "%s", "%s"),'
% (row[0].upper(), row[0], var_type, 'true' if optional else 'false', \
'true' if row[1]=='Y' else 'false', row[4], row[6], row[5]))