import collections
T='/app/data/tasks/29/'
todo=[l.rstrip('\n').split('\t') for l in open(T+'i29bng24/todo.tsv') if l.strip()]
excl=set()
for f in ['i29bng24/manifest.tsv','i29bng25/manifest.tsv','i29bng25/manifest3.tsv','i29bng25/manifest_all.tsv','i29bng26/manifest.tsv','i29bng27/manifest.tsv']:
    for l in open(T+f):
        p=l.rstrip('\n').split('\t')
        if len(p)>=2: excl.add((p[0],p[1]))
rest=[r for r in todo if (r[0],r[1]) not in excl]
print('todo',len(todo),'excl',len(excl),'rest',len(rest))
by=collections.defaultdict(list)
for r in rest:
    ext=r[1].rsplit('.',1)[-1].lower()
    by[ext].append(r)
exts=sorted(by,key=lambda e:-len(by[e]))
print({e:len(by[e]) for e in exts})
out=[];i=0
while len(out)<800 and any(by[e] for e in exts):
    e=exts[i%len(exts)];i+=1
    if by[e]: out.append(by[e].pop(0))
open(T+'i29bng28/batch6.tsv','w').write(''.join('\t'.join(r)+'\n' for r in out))
print('batch6',len(out))
print('extcount',collections.Counter(r[1].rsplit('.',1)[-1].lower() for r in out))
print('left_total',sum(len(v) for v in by.values()))
