add python scripts to extract parameters to JSON and compare the JSON
This commit is contained in:
parent
bd47bc4928
commit
f8e60f94ce
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -26,6 +26,7 @@ moc_*
|
|||
*.rej
|
||||
*.so
|
||||
*.so.*
|
||||
*.json
|
||||
*_pch.h.cpp
|
||||
*_resource.rc
|
||||
*.qm
|
||||
|
|
37
firmwares/compareJSON.py
Normal file
37
firmwares/compareJSON.py
Normal file
|
@ -0,0 +1,37 @@
|
|||
import json
|
||||
|
||||
# Load the two JSON files
|
||||
with open("x2745_DPP-PHA_2023091800_parameters.json") as f1:
|
||||
old_params = json.load(f1)
|
||||
|
||||
with open("x2745_DPP-PHA_2025012205_parameters.json") as f2:
|
||||
new_params = json.load(f2)
|
||||
|
||||
# Index by parameter name for easy lookup
|
||||
old_dict = {param["name"]: param for param in old_params}
|
||||
new_dict = {param["name"]: param for param in new_params}
|
||||
|
||||
# 1. Find new parameter names
|
||||
new_names = set(new_dict.keys()) - set(old_dict.keys())
|
||||
print("🆕 New parameters in new version:")
|
||||
for name in sorted(new_names):
|
||||
print(f" - {name}")
|
||||
|
||||
# 2. Compare allowed values for common parameters
|
||||
print("\n🔍 Parameters with changed allowed values:")
|
||||
for name in sorted(set(old_dict.keys()) & set(new_dict.keys())):
|
||||
old_vals = {v["value"]: v["description"] for v in old_dict[name].get("allowed_values", [])}
|
||||
new_vals = {v["value"]: v["description"] for v in new_dict[name].get("allowed_values", [])}
|
||||
|
||||
if old_vals != new_vals:
|
||||
print(f" - {name}")
|
||||
removed = set(old_vals) - set(new_vals)
|
||||
added = set(new_vals) - set(old_vals)
|
||||
changed = {k for k in old_vals if k in new_vals and old_vals[k] != new_vals[k]}
|
||||
|
||||
if added:
|
||||
print(f" ➕ Added: {sorted(added)}")
|
||||
if removed:
|
||||
print(f" ➖ Removed: {sorted(removed)}")
|
||||
if changed:
|
||||
print(f" 🔄 Modified descriptions: {sorted(changed)}")
|
1
firmwares/firmware_backup_webpage.txt
Normal file
1
firmwares/firmware_backup_webpage.txt
Normal file
|
@ -0,0 +1 @@
|
|||
https://fsunuc.physics.fsu.edu/wiki/index.php/FSU_SOLARIS_DAQ#Firmware
|
76
firmwares/web2JSON.py
Normal file
76
firmwares/web2JSON.py
Normal file
|
@ -0,0 +1,76 @@
|
|||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
url = "http://192.168.0.102/documentation/a00103.html"
|
||||
response = requests.get(url)
|
||||
soup = BeautifulSoup(response.content, 'html.parser')
|
||||
|
||||
print(url)
|
||||
|
||||
# print(soup)
|
||||
|
||||
# Get the entire div
|
||||
project_div = soup.find('div', id='projectname')
|
||||
print("Full Text:", project_div.get_text(strip=True))
|
||||
|
||||
# Get just the main project name (excluding the span)
|
||||
project_name = project_div.contents[0].strip()
|
||||
print("Name:", project_name)
|
||||
|
||||
# Get the project number from the span
|
||||
project_number = project_div.find('span', id='projectnumber').get_text(strip=True)
|
||||
print("Number:", project_number)
|
||||
|
||||
safe_name = project_name.replace(" ", "_")
|
||||
filename = f"{safe_name}_{project_number}_parameters.json"
|
||||
|
||||
import json
|
||||
|
||||
data = []
|
||||
|
||||
# Iterate through all <h2> blocks which denote parameters
|
||||
for h2 in soup.find_all("h2"):
|
||||
param = {}
|
||||
name = h2.get_text(strip=True)
|
||||
param['name'] = name
|
||||
|
||||
# Description is usually the next <p>
|
||||
desc_tag = h2.find_next_sibling('p')
|
||||
if desc_tag:
|
||||
param['description'] = desc_tag.get_text(strip=True)
|
||||
|
||||
# Get the next two blockquotes: one for options, one for allowed values
|
||||
blockquotes = desc_tag.find_all_next('blockquote', class_='doxtable', limit=2)
|
||||
|
||||
# Parse Options
|
||||
if len(blockquotes) > 0:
|
||||
options = {}
|
||||
for li in blockquotes[0].find_all('li'):
|
||||
text = li.get_text(strip=True)
|
||||
if ':' in text:
|
||||
key, val = text.split(':', 1)
|
||||
options[key.strip()] = val.strip()
|
||||
param['options'] = options
|
||||
|
||||
# Parse Allowed Values
|
||||
if len(blockquotes) > 1:
|
||||
allowed_values = []
|
||||
for li in blockquotes[1].find_all('li'):
|
||||
b_tag = li.find('b')
|
||||
em_tag = li.find('em')
|
||||
if b_tag and em_tag:
|
||||
allowed_values.append({
|
||||
'value': b_tag.get_text(strip=True),
|
||||
'description': em_tag.get_text(strip=True)
|
||||
})
|
||||
param['allowed_values'] = allowed_values
|
||||
|
||||
data.append(param)
|
||||
|
||||
|
||||
# print(parameters)
|
||||
|
||||
|
||||
# Output as JSON
|
||||
with open(filename, 'w') as f:
|
||||
json.dump(data, f, indent=2)
|
Loading…
Reference in New Issue
Block a user