otime/web/ps_ttime.py

67 lines
2.0 KiB
Python

import otime
import asyncio
from js import document, FileReader
from pyodide import create_proxy
import xml.etree.ElementTree as ET
global event
event = otime.Event(0, 'PlaceHolder')
async def process_conf(f_event):
global event
file_list = f_event.target.files.to_py()
for f in file_list:
data = await f.text()
document.getElementById('tt-cnf-cnt').innerHTML = data
event.import_ttime_cnf(data)
for c in event.o_classes:
print(c.name, c.course.name)
async def process_db(f_event):
global event
file_list = f_event.target.files.to_py()
for f in file_list:
data = await f.text()
document.getElementById('tt-db-cnt').innerHTML = data
event.import_ttime_db(data)
async def process_mtr(f_event):
global event
file_list = f_event.target.files.to_py()
for f in file_list:
data = await f.text()
document.getElementById('mtr-cnt').innerHTML = data
event.import_mtr_file(data)
async def create_xml(f_event):
global event
event.match_all()
xml_res = ET.tostring(event.get_xml_res().getroot(), encoding='unicode', method='xml', xml_declaration=True)
#xml_res = dir(event.get_xml_res())
document.getElementById('xml-cnt').innerHTML = xml_res.replace('&', '&amp').replace('<', '&lt').replace('>', '&gt')
def main():
global event
# Create a Python proxy for the callback function
# process_file() is your function to process events from FileReader
cnf_f_event = create_proxy(process_conf)
ec = document.getElementById("tt-cnf")
ec.addEventListener("change", cnf_f_event, False)
db_f_event = create_proxy(process_db)
ed = document.getElementById("tt-db")
ed.addEventListener("change", db_f_event, False)
mtr_f_event = create_proxy(process_mtr)
em = document.getElementById("mtr")
em.addEventListener("change", mtr_f_event, False)
xml_btn_call = create_proxy(create_xml)
eb = document.getElementById("xml-btn")
eb.addEventListener("click", xml_btn_call, False)