Compare commits
3 Commits
3eea3854dc
...
888e1593f9
Author | SHA1 | Date | |
---|---|---|---|
|
888e1593f9 | ||
|
923839c77f | ||
|
161b32bacf |
@ -2,23 +2,26 @@
|
|||||||
"""
|
"""
|
||||||
extracteur de données iSpindel JSON entreposées par Little Bock en HTML
|
extracteur de données iSpindel JSON entreposées par Little Bock en HTML
|
||||||
"""
|
"""
|
||||||
import json
|
import json, pathlib
|
||||||
try:
|
try:
|
||||||
import lxml.html as LX
|
import lxml.html as LX
|
||||||
except ModuleNotFoundError:
|
except ModuleNotFoundError:
|
||||||
import sys
|
import sys
|
||||||
sys.exit("Le module 'lxml' est nécessaire.\n\thttp://pypi.org/lxml")
|
sys.exit("Le module 'lxml' est nécessaire.\n\thttp://pypi.org/lxml")
|
||||||
import pathlib
|
|
||||||
|
|
||||||
def jsproc(data):
|
def jsproc(data):
|
||||||
"""nettoie des données récursivement"""
|
"""supprime les données inutiles d'une série"""
|
||||||
unwanted = ["color","opacity","yAxis","dashStyle"]
|
unwanted = ("color","opacity","yAxis","dashStyle", "tooltip",)
|
||||||
|
if data.get("data"):
|
||||||
for u in unwanted:
|
for u in unwanted:
|
||||||
if u in data.keys():
|
if u in data.keys():
|
||||||
|
if u == "tooltip":
|
||||||
|
tt = data.get(u)
|
||||||
|
suffix = tt.get("valueSuffix")
|
||||||
|
if suffix: data.update({
|
||||||
|
"name": " ".join([data["name"], suffix])
|
||||||
|
})
|
||||||
del(data[u])
|
del(data[u])
|
||||||
for k,v in data.items():
|
|
||||||
if isinstance(v,dict):
|
|
||||||
jsproc(v)
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def hproc(path_in):
|
def hproc(path_in):
|
||||||
@ -29,11 +32,13 @@ def hproc(path_in):
|
|||||||
if x: data1 = x[0].get('data-chart-options')
|
if x: data1 = x[0].get('data-chart-options')
|
||||||
if data1:
|
if data1:
|
||||||
for i in json.loads(data1).pop('series'):
|
for i in json.loads(data1).pop('series'):
|
||||||
data2.append(jsproc(i))
|
data = jsproc(i)
|
||||||
|
if data: data2.append(data)
|
||||||
if len(data2) > 0:
|
if len(data2) > 0:
|
||||||
path_out = path_in.with_suffix('.json')
|
path_out = path_in.with_suffix('.json')
|
||||||
with open(path_out,'w') as f:
|
with open(path_out,'w') as f:
|
||||||
f.write(json.dumps(data2, indent=2, sort_keys=False))
|
f.write(json.dumps(data2,
|
||||||
|
sort_keys=False, ensure_ascii=False, indent=2))
|
||||||
print(f"INFO: {path_in.name} >> {path_out.name}")
|
print(f"INFO: {path_in.name} >> {path_out.name}")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
Loading…
Reference in New Issue
Block a user