Commit 168ebf31d6f0100b03f078799902010ffcff5199
1 parent
65f577b1
Exists in
master
Add a Python script to get the epn-tap-v2 parameters
Showing
1 changed file
with
51 additions
and
0 deletions
Show diff stats
@@ -0,0 +1,51 @@ | @@ -0,0 +1,51 @@ | ||
1 | +#!/usr/bin/python3 | ||
2 | + | ||
3 | +import urllib.request | ||
4 | +from html.parser import HTMLParser | ||
5 | +from bs4 import BeautifulSoup | ||
6 | +from re import sub | ||
7 | +""" | ||
8 | +This script parse the Parameters table on the EpnTAPv2 VO-Paris Confluence page | ||
9 | +(voparis-confluence.obspm.fr) and print them in several ways (by setting EXPORT_TYPE): | ||
10 | +- CSV: A simple CSV table whicj have the same content as the Confluence table; | ||
11 | + example: `"incidence_min";"";"incidence_min";"Double";"deg";"Min incidence angle (solar zenithal angle)";"pos.posAng;stat.min";"";"N"` | ||
12 | +- init: A Java code for parameters initalisation, in camelCase | ||
13 | + example: `public double incidenceMin;` | ||
14 | +- enum: A Java code for emuration, as `THE_PARAMETER(name, class, isOptional, mustBeFilled, unit, UCD, desciption)` | ||
15 | + example: `INCIDENCE_MIN("incidence_min", class.Double, false, false, "deg", "pos.posAng;stat.min", "Min incidence angle (solar zenithal angle)"),` | ||
16 | +""" | ||
17 | + | ||
18 | +EXPORT_TYPE = 'enum' # 'CSV', or 'init', or 'enum'. | ||
19 | +URL = 'https://voparis-confluence.obspm.fr/display/VES/EPN-TAP+V2.0+parameters' | ||
20 | + | ||
21 | +tmp_file, headers = urllib.request.urlretrieve(URL) | ||
22 | +html = open(tmp_file) | ||
23 | +soup = BeautifulSoup(html.read(), 'html.parser') | ||
24 | + | ||
25 | +# EPN-TAP table is the first one. | ||
26 | +table = soup.find_all('table', 'confluenceTable')[0].find('tbody').find_all('tr') | ||
27 | + | ||
28 | +optional = False | ||
29 | + | ||
30 | +for tr in table: | ||
31 | + row=[] | ||
32 | + for td in tr.find_all('td'): | ||
33 | + txt = td.string if td.string and td.string != None else '' | ||
34 | + row.append(sub(r'[^\x00-\x7F]', r' ', txt).strip()) | ||
35 | + if row and row[0] == 'Optional parameters': | ||
36 | + optional = True | ||
37 | + if not row or row[0] == "" or (row[1]=="" and row[2]=="" and row[3]==""): | ||
38 | + continue | ||
39 | + row.append('Y' if optional else 'N') | ||
40 | + | ||
41 | + if EXPORT_TYPE == 'CSV': | ||
42 | + print('"' + '";"'.join(row) + '"') | ||
43 | + elif EXPORT_TYPE == 'init': | ||
44 | + var_type = row[3].replace('Text', 'String').replace('Double', 'double').replace('Integer', 'int') | ||
45 | + var_name = row[0][0].lower() + row[0].replace('_', ' ').title().replace(' ', '')[1:] # camelCase | ||
46 | + print('public %s %s;' % (var_type, var_name)) | ||
47 | + elif EXPORT_TYPE == 'enum': | ||
48 | + var_type = row[3].replace('Text', 'String') | ||
49 | + print('%s("%s", class.%s, %s, %s, "%s", "%s", "%s"),' | ||
50 | + % (row[0].upper(), row[0], var_type, 'true' if optional else 'false', \ | ||
51 | + 'true' if row[1]=='Y' else 'false', row[4], row[6], row[5])) |