Compare commits
3 Commits
009b60b8db
...
3eea3854dc
Author | SHA1 | Date | |
---|---|---|---|
|
3eea3854dc | ||
|
496e95f191 | ||
|
09209b3b3e |
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
|||||||
local/
|
local/
|
||||||
*.tar.gz
|
*.tar.gz
|
||||||
|
*.json
|
||||||
|
|
||||||
|
@ -5,33 +5,44 @@ extracteur de données iSpindel JSON entreposées par Little Bock en HTML
|
|||||||
import json
|
import json
|
||||||
try:
|
try:
|
||||||
import lxml.html as LX
|
import lxml.html as LX
|
||||||
except ModuleNotFoundError as e:
|
except ModuleNotFoundError:
|
||||||
import sys
|
import sys
|
||||||
print("Le module 'lxml' est nécessaire.\n http://pypi.org/lxml")
|
sys.exit("Le module 'lxml' est nécessaire.\n\thttp://pypi.org/lxml")
|
||||||
sys.exit()
|
|
||||||
import pathlib
|
import pathlib
|
||||||
|
|
||||||
def proc(path):
|
def jsproc(data):
|
||||||
s, js = None, None
|
"""nettoie des données récursivement"""
|
||||||
h = LX.parse(path.name)
|
unwanted = ["color","opacity","yAxis","dashStyle"]
|
||||||
|
for u in unwanted:
|
||||||
|
if u in data.keys():
|
||||||
|
del(data[u])
|
||||||
|
for k,v in data.items():
|
||||||
|
if isinstance(v,dict):
|
||||||
|
jsproc(v)
|
||||||
|
return data
|
||||||
|
|
||||||
|
def hproc(path_in):
|
||||||
|
"""traite un document HTML"""
|
||||||
|
data1, data2 = None, []
|
||||||
|
h = LX.parse(str(path_in))
|
||||||
x = h.xpath("//*[@id='fermentation_log_chart']")
|
x = h.xpath("//*[@id='fermentation_log_chart']")
|
||||||
if x: s = x[0].get('data-chart-options')
|
if x: data1 = x[0].get('data-chart-options')
|
||||||
if s:
|
if data1:
|
||||||
js = json.dumps(
|
for i in json.loads(data1).pop('series'):
|
||||||
json.loads(s).pop('series'), indent=4, sort_keys=True) or None
|
data2.append(jsproc(i))
|
||||||
if js:
|
if len(data2) > 0:
|
||||||
p = path.with_suffix('.json')
|
path_out = path_in.with_suffix('.json')
|
||||||
with open(p,'w') as f:
|
with open(path_out,'w') as f:
|
||||||
f.write(js)
|
f.write(json.dumps(data2, indent=2, sort_keys=False))
|
||||||
print(f"INFO: extraction des données dans {p.name}.")
|
print(f"INFO: {path_in.name} >> {path_out.name}")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
here = pathlib.Path.cwd()
|
here = pathlib.Path.cwd()
|
||||||
hdocs = tuple(here.glob("*.html"))
|
hdocs = tuple(here.rglob("*.html"))
|
||||||
if len(hdocs) == 0:
|
if len(hdocs) == 0:
|
||||||
print("Aucun fichier HTML ('.html') trouvé.")
|
print("Aucun fichier HTML ('.html') trouvé.")
|
||||||
for i in hdocs:
|
for i in hdocs:
|
||||||
if i.exists() and i.stat().st_size > 0:
|
if i.exists() and i.stat().st_size > 0:
|
||||||
proc(i)
|
hproc(i)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user