import re,glob,json,sys,os
os.chdir(sys.argv[1])
d={}
for f in sorted(glob.glob('tsa_*.html')):
h=open(f,encoding='utf-8',errors='ignore').read()
rows=re.findall(r'
]*>(.*?)
',h,re.S)
n=0
for r in rows:
c=[re.sub(r'<[^>]+>','',x).strip() for x in re.findall(r']*>(.*?)',r,re.S)]
if len(c)>=2 and re.match(r'\d+/\d+/\d{4}',c[0]):
m,dd,y=c[0].split('/'); k=f'{y}-{int(m):02d}-{int(dd):02d}'
v=int(c[1].replace(',','')); d[k]=v; n+=1
print(f,n)
json.dump(dict(sorted(d.items())),open('tsa.json','w'),indent=0)
ks=sorted(d); print(ks[0],ks[-1],len(ks))