import os
import sys
from commands import getoutput

fn = sys.argv[1]
f = open(fn+'.txt')
lines = f.readlines()
f.close()
fon = fn+'.txt'
fo = open(fon, 'w')
for l in lines:
    print 'l='+l
    spl = l.split()
    if spl[0] == 'htmlstart':
        fo.write(l)
        continue
    if spl[0] == 'txt':
        fo.write(l)
        continue
    if len(spl) < 3:
        continue
    jpgfn = spl[1]
    yy = jpgfn[0:2]
    try:
        if int(yy) > 30:
            yyyy = '19'+yy
        else:
            yyyy = '20'+yy
    except:
        yyyy = '9999'
    caption = ''
    for i in range(6,len(spl)):
        caption = caption + spl[i]+' '
    caption = caption.strip()
    ol = 'jpg '+yyyy+' '+jpgfn+' '+caption
    fo.write(ol+'\n')
fo.close()


