DIR : /home/kozerus/public_html/ka/ko.py

/home/kozerus/public_html/ka

# konet.py	20220201_0130 housatonic tesseract
# konet.py	20211003_1430
# encoding=utf8


# ka1.py	20220201_1212 dt2db3 dt2db3v
# ka1.py	20220126_0100 db3s cmds
# ka1.py	20220126_0100 ftsdb3 cmds
# ka1.py	20220125_2000 ftsdb3 sql_create
# ka1.py	20220125_1616 do_tl(a0,a1,a2,a3,a4)
# ka1.py	20220125_1600 f2ftsdb3(db3file,pathfile,tbl,id)
# ka1.py	20220125_1500 f2db3(db3file,pathfile,tbl,id)
# ka1.py	20220125_1500 load_lines_new()
# ka1.py	20190214_1444 go wii
# ka1.py	20190214_0230 go htms2host
# ka1.py	20190213_2300 go png2gif png+gif+size=png_gif-size.gif
# ka1.py	20190212_1500 go gif2gifs imgs/ani/work/ring/ring.gif = gifs(ring0,1,2, 00,01,02, 10,11,12, 20,21,22)
# ka1.py	20190210_2200 go htms2htm .
# ka1.py	20190210_2100 go php2php .
# ka1.py	20190204_1730 go newhtm .
# ka1.py	20190204_1730 go 
# ka1.py	20190115_0300 do_sl find.wl
# ka1.py	20190114_1723 do_tlwl tl.psv
# ka1.py	20190112_1200 do_tlwl tl.psv
# ka1.py	20190112_1100 do_tl tl.psv
# ka1.py	20190111_1123 do_tl(a0,a1,a2,a3)
# ka1.py	20180704_0000
# ka1.py	20180520_1300
# ===========================
# convert map_venice.jpg    -page +142+242 push_pin.png \ -flatten  map_push_pin.jpg


# from __future__ import unicode_literals
import sys
# reload(sys)
# sys.setdefaultencoding('utf8')

# /usr/lib/python2.7/sitecustomize.py
# /usr/local/lib/python2.7/site-packages/sitecustomize.py
# sys.setdefaultencoding("utf-8")


whitespace = ' \t\n\r\v\f'
ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_letters = ascii_lowercase + ascii_uppercase
digits = '0123456789'
hexdigits = digits + 'abcdef' + 'ABCDEF'
octdigits = '01234567'
punctuation = r"""!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~"""
printable = digits + ascii_letters + punctuation + whitespace
# .decode("utf-8") .encode("utf-8")



import sys
import os, os.path, time, fnmatch
import subprocess
import datetime
import time
import re
import base64
import sqlite3
from subprocess import PIPE, Popen
import socket
# print(socket.gethostbyaddr("8.8.8.8"))
# print(socket.gethostbyaddr("10.5.50.112"))

# import urllib
# from urllib.parse import urlparse
# url = urlparse('https://www.pythonpool.com/for-vs-while-loop-python/' )
# host= '{uri.scheme}://{uri.netloc}/'.format(uri=url)
# url = urlparse('http:127.0.0.1')
# url_ka1 = urlparse('http:10.5.50.112')
# url_ko0 = urlparse('http:ko0.us')
# url_ko1 = urlparse('http:ko1.us')
# url_ko2 = urlparse('http:ko2.us')
# host= '{uri.scheme}://{uri.netloc}/'.format(uri=url)
# host_ka1 = '{uri.scheme}://{uri.netloc}/'.format(uri=url_ka1)
# host_ko0 = '{uri.scheme}://{uri.netloc}/'.format(uri=url_ko0)
# host_ko1 = '{uri.scheme}://{uri.netloc}/'.format(uri=url_ko1)
# host_ko2 = '{uri.scheme}://{uri.netloc}/'.format(uri=url_ko2)
# print(host)
# print(host_ka1)
# print(host_ko0)
# print(host_ko1)
# print(host_ka2)
# print(host_ka1)
# print(host_ka1)

# import socket
# hostname=socket.gethostname()
# hostname2=socket.gethostbyaddr(socket.gethostname())[0]
# print("BUGS_011 socket.gethostname hostname={}\n".format(hostname))
# print("BUGS_012 socket.gethostname hostname2={}\n".format(hostname2))

import os, platform
if platform.system() == "Windows":
    print(platform.uname().node)
else:
    print(os.uname()[1]) 

# python -m timeit "import socket; socket.gethostname()" 10000 loops, best of 3: 


alen = len(sys.argv)
(a0,a1,a2,a3,a4,a5,a6,a7,a8,a9) = ("","","","","","","","","","")
progid="ka1"
if( alen > 0 ): a0=sys.argv[0] 
if( alen > 1 ): a1=sys.argv[1]
if( alen > 2 ): a2=sys.argv[2]
if( alen > 3 ): a3=sys.argv[3]
if( alen > 4 ): a4=sys.argv[4]
if( alen > 5 ): a5=sys.argv[5]
if( alen > 6 ): a6=sys.argv[6]
if( alen > 7 ): a6=sys.argv[7]
if( alen > 8 ): a6=sys.argv[8]
if( alen > 9 ): a6=sys.argv[9]
if( alen > 10 ): a6=sys.argv[10]
# print( "argv={} a0={} arg1={} arg2={} arg3={}\n".format( argv, a0, a1, a2, a3 ))


def kodts(fmt):

	now = datetime.datetime.now();
	today = now.date();
	moment = now.time();
	today = datetime.date.today()
	kodt =  now.strftime('%Y-%m-%d_%H:%M:%S')  # This writes "06/24/1984"
	dt =  now.strftime('%Y%m%d_%H%M%S')  # This writes "06/24/1984"
	tm =  now.strftime('%H%M%S')  # This writes "06/24/1984"
	yyyy =  now.strftime('%Y')  # This writes "06/24/1984"
	yyyymmdd =  now.strftime('%Y%m%d')  # This writes "06/24/1984"
	dt=kodt.replace("-","").replace(":","")
	if( fmt == "" ): return(dt)
	if( fmt == "dttm"): return(dttm)
	if( fmt == "dt"): return(dt)
	if( fmt == "tm"): return(tm)
	if( fmt == "yyyy"): return(yyyy)
	if( fmt == "yyyymmdd"): return(yyyymmdd)
	if( fmt == "yyyy"): return(yyyy)
	if( fmt == "yyyy"): return(yyyy)
	return(dttm)


def kosys(cmd,opts):
	print( "BUGS_150 KOSYS cmd={} opts={}".format(cmd,opts))
	koid=sys.argv[0].split(".")[0]
	kodt=kodts("")

	kosys = subprocess.Popen(cmd, shell=True,
		stdout=subprocess.PIPE, 
		stderr=subprocess.PIPE)
	(out, err) = kosys.communicate()

	if ( opts == "br") or (opts == "brief"):
		return( out, err )

	j=0
	k=0
	for sysout in out.split("\n"):
		j=j+1
		print( "{}_{} -= kocmd =- {}-{} sysout={}".format(koid,kodt, j,k, sysout))

	k=0
	for syserr in err.split("\n"):
		k=k+1
		print( "{}_{} -= kocmd =- {}-{} syserr={}".format(koid,kodt, j,k, syserr))
	return( out, err )


def go_topdirs():
	topdirs = "i ht kb o1 i1 vixia3_ko1 epson photos webcam2_jtfdc_ko1 eyetv iphoto saic scan ko1tbr1_graid webcam2_jtfd    c_20160609_0945 sk_ko0us mts vixia2_ko1 eulura Pictures video2_20150811 video o i imgs kb mp4"
	return( topdirs )



import sqlite3 as sql3
import sys

def ocr(dtasrc):
	if( dtasrc == "" ):
		print( "ERR_170 ocr NOTFOUND dtasrc={}\n" )
		exit()
	(out,err)=kosys(dtasrc)













def d2db3(dtasrc,db3file,tbl,id,usrcmd):
	dttm=kodts('')
	(dtamode,ifile,syscmd_find,sql_select)=("","","")
	if( dtasrc == "" ):
		print("ERR_201 {} {} d2db3v file")
		print("ERR_201 {} {} d2db3v find")
		print("ERR_201 {} {} d2db3v select")
		return


	if( len(dtasrc.split("="))): 
		dtasrc=split("=")[0]
	else:
		dtasrc=split("=")[1]
	if( re.search(".txt$",dtasrc)):
		dtamode="file"
		(dtamode,ifile)=("file",dtasrc)
	if( re.search("^file",dtasrc)):
		dtamode="file"
		if( len(dtasrc.split("="))):  
			ifile=dtasrc.split("=")[1]
	if( dtamode=='file'):
		if( os.path.exists(ifile)):
			print( "ERR_155 NOTFOUND dtamode={} ifile={}".format(dtamode,ifile))
			exit()

	if( re.search("^find ",dtasrc)):
		dtamode='find'
		syscmd_find=dtasrc
	if( re.search("^find",dtasrc)):
		dtamode="find"
		if( len(dtasrc.split("="))): syscmd_find=dtasrc.split("=")[1]

	if( re.search("^select from",dtasrc)):
		datamode="select"
		sql_select=dtasrc
	if( re.search("^select",dtasrc)):
		datamode="select"
		if( len(dtasrc.split("="))): sql_select=split("=")[1]



	print("BUGS_200 {} {} d2db3 dtamode={} dtasrc={} db3file={} tbl={} id={}".format(progid,dttm,dtamode,dtasrc,db3file,tbl,id))

	if( datamode == 'file'):
		print("BUGS_210 {} {} d2db3 dtamode={} ifile={} db3file={} tbl={} id={}".format(progid,dttm,dtamode,ifil,db3file,tbl,id))
		data=open(ifile,"r").readlines()
		datalen=len(data)
			


	if( datamode == 'find'):
		print("BUGS_220 {} {} d2db3 dtamode={} syscmd_find={} db3file={} tbl={} id={}".format(progid,dttm,dtamode,syscmd_find,db3file,tbl,id))
		(out,err)=kosys(syscmd_find)
		data=out.split("\n")
		datalen=len(data)


	if( datamode == 'select'):
		print("BUGS_230 {} {} d2db3 dtamode={} sql_select={} db3file={} tbl={} id={}".format(progid,dttm,dtamode,sql_select,db3file,tbl,id))
		if( not os.path.exists(db3file)):
			print("BUGS_231 {} {} d2db3 NOTFOUND db3file={}".format(progid,dttm,db3file))
			exit()
		if( sql_select == "" ):
			print("BUGS_232 {} {} d2db3 NOTFOUND sql_select={}".format(progid,dttm,sql_select))
			exit()
		
		sql3 = sqlite3.connect(db3file)
		sql3.row_factory = sqlite3.Row
		rows = sql3.cursor()
		rows.execute(sql_select)
		for row in rows:
			data += row['pathfile']
			datalen=len(data)
		sql3.close()		

	print( "BUGS_400 {} {} dtamode={} datalen={} usrcmd={}".format(progid,dttm,dtamode,datalen,usrcmd))



def newbook(dtasrc,id,txtmode,usrcmd):
	prog=sys.argv[0].split(".")
	dttm=kodts('')
	(msg,err)=("","")
	msgfil="{}_msg.txt".format(prog)
	errfil="{}_err.txt".format(prog)
	(pathfile,pathfiles)=("","")

	if( re.search("^find",dtasrc)):
		path=dtasrc.split(" ")[1]
		if( not os.path.exists(path)):
			print( "ERR_281 newbook NOTFOUND path={}".format(path))
			err="ERR_281 newbook  NOTFOUND path={} dtasrc={} id={} txtmode={} usrcmd={}" .format(path,dtasrc,id,txtmode,usrcmd )
			komsg(msgfil,msg,'')

		print( "MSG_282 newbook ___FOUND path={}".format(path))
		msg="MSG_282 newbook  ___FOUND path={} dtasrc={} id={} txtmode={} usrcmd={}" .format(path,dtasrc,id,txtmode,usrcmd )
		komsg(msgfil,msg,'')

		syscmd_find=dtasrc
		tpathfile=pathfile	
		print( "BUGS_299 syscmd_find={}".format(syscmd_find))
		(out,err)=kosys(syscmd_find,'brief')
		pathfiles=out.split("\n")
		pathfiles_len=len(pathfiles)
		print( "BUGS_300 syscmd_find={} pathfiles_len={}" .format(syscmd_find,pathfiles_len))
			
	print( "MSG_350 newbook dtasrc={} id={} txtmode={} usrcmd={}".format(dtasrc,id,txtmode,usrcmd))

	j=0
	for pathfile in pathfiles:
		if( pathfile == ""): continue
		print( "BUGS_311 j={} pathfile={} tpathfile={}".format(j,pathfile,tpathfile))
		j=j+1


def d2db3v(dtasrc,db3file,tbl,id,txtmode,usrcmd):
	progid="ka1"
	dttm=kodts('')
	db3file_default="{}.db3".format(progid)
	ifile_default="{}.txt".format(progid)
	tbl_default=progid
	(msgfil,msg,errfil,err)=("{}_msg.txt".format(progid),"","{}_err.txt".format(progid),"")


	msg="MSG_200 db3efile_default={} ifile_default={} tbl_default={}" .format(db3file_default,ifile_default,tbl_default)
	komsg(msgfil,msg,'')

	msg="BUGS_200 d2db3v dtasrc={} db3file={} tbl={} id={} txtmode={} usrcmd={}".format(dtasrc,db3file,tbl,id,txtmode,usrcmd)
	komsg(msgfil,msg,'')
	j=0
	for arg in sys.argv:
		j=j+1
		msg="BUGS_220 j={} arg={} dtasrc={} tbl={} id={} txtmode={} usrcmd={}" .format(j,arg,dtasrc,tbl,id,txtmode,usrcmd)
		komsg(msgfil,msg,'')
		if( re.search('.db3$',arg)):
			if( db3file == '' ): db3file=arg
			continue
		if( re.search('go',arg)):
			if( usrcmd == '' ): usrcmd=arg
			continue

		if( re.search('^file=',arg)):
			dtamode="file"
			if( len(arg.split("="))):
				ifile=arg.split("=")[1]
			continue
		if( re.search('.txt$',arg)):
			ifile=arg
			dtamode="file"
			continue
		if( re.search('^find ',arg)):
			dtamode="find"
			syscmd_find=arg
			continue
		if( re.search('^find=',arg)):
			dtamode="find"
			if( len(arg.split("="))):
				syscmd_find=arg.split("=")[1]
			continue
		if( re.search('^select ',arg)):
			dtamode="select"
			sql_select=arg
			continue
		if( re.search('^select=',arg)):
			dtamode="select"
			if( len(arg.split("="))):
				sql_select=arg.split("=")[1]
			continue

		if( tbl == "" ):
			tbl=arg
			continue
		if( id == "" ):
			id=arg
			continue

#	if( not dtamode ): dtamode=""
	(dtamode,sql_select,syscmd_find,ifile)=("","","","")
	print( "\n" );
	print( "pqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpq" )
	msg="BUGS_260 d2db3v {} {} dtasrc={} db3file={} tbl={} id={} usrcmd={}".format(progid,dttm,dtasrc,db3file,tbl,id,usrcmd)
	msg="BUGS_261 d2db3v {} {} dtamode={} sql_select={}".format(progid,dttm,dtamode,sql_select)
	komsg(msgfil,msg,'')
	msg="BUGS_262 d2db3v {} {} dtamode={} syscmd_find={}".format(progid,dttm,dtamode,syscmd_find)
	komsg(msgfil,msg,'')
	msg="BUGS_263 d2db3v {} {} dtamode={} ifile={}".format(progid,dttm,dtamode,ifile)
	komsg(msgfil,msg,'')
	print( "bdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbd" )



	if( not re.search("^g",usrcmd)): 
		print("e=exit q=quit s=skip enter=continue g=go")
# py27		usrcmd=raw_input("prompt: " )
# py27		usrcmd=raw_input("raw_input prompt_310: ")
		usrcmd=input("prompt: ")
		if( re.search("^e", usrcmd)): exit()
		if( re.search("^q", usrcmd)): return()
#		if( re.search("^s", usrcmd)): continue
		print( "BUGS_380 usrcmd={}".format(usrcmd))
		

	if( dtamode == "file" ):
		if( not os.path.exists(ifile)):
			err="ERR_311 NOTFOUND ifile={}".format(ifile)
			koerr(errfil,err,'')
		data=open(ifile,"r").readlines()
		datalen=len(data)

	if( dtamode == "find" ):
		path=""
		if( syscmd_find.split(" ") > 1 ):
			path=syscmd_find.split(" ")[1]
		if( not os.path.exists(path)):
			err="ERR_321 NOTFOUND path={}".format(progid,dttm,path)
			koerr(errfil,err,'')
		(data,err)=kosys(syscmd_find,'brief')
		datalen=len(data)

	if( dtamode == "select" ):
		if( not os.path.exists(db3file)):
			err="ERR_321 NOTFOUND db3file={}".format(db3file)
			koerr(errfil,err,'')
		sql3=sqlite3.connect(db3file)
		rows = sql3.cursor()
		rows.execute(sql_select)
		datalen=0
		for row in rows:
			data += row['pathfile']
			datalen=datalen+1

	print( "e=exit q=quit s=skip enter=continue g=go" )
	if( not re.search("^g",usrcmd)):
# py27		usrcmd=raw_input("raw_input prompt_410: ")
		usrcmd=input("prompt_410: ")
		if( re.search("^e", usrcmd)): exit()
		if( re.search("^q", usrcmd)): return()
		if( re.search("^s", usrcmd)): return()



	sql_create_v = ""
	sql_create_v += "create virtual table if not exists {} using fts3(\n".format(tbl)
	sql_create_v += "	status text,\n"
	sql_create_v += "	progid text,\n"
	sql_create_v += "	dttm text,\n"
	sql_create_v += "	id text,\n"
	sql_create_v += "	grp text,\n"
	sql_create_v += "	title text,\n"
	sql_create_v += "	subject text,\n"
#	sql_create_v += "	subject varchar(256) not null,\n"
	sql_create_v += "	dt text,\n"
	sql_create_v += "	startdate text,\n"
	sql_create_v += "	starttime text,\n"
	sql_create_v += "	enddate text,\n"
	sql_create_v += "	endtime text,\n"
	sql_create_v += "	pathfile text,\n"
	sql_create_v += "	path text,\n"
	sql_create_v += "	file text,\n"
	sql_create_v += "	ext text,\n"
	sql_create_v += "	tmp text,\n"
	sql_create_v += "	codes text,\n"
	sql_create_v += "	txtcnt text,\n"
	sql_create_v += "	content text check(length(body)<10240),\n"
	sql_create_v += "	tokenize=simple en_AU\n"
	sql_create_v += "	)";

	if( not os.path.exists(db3file)):
		print("ERR_440 NOTFOUND db3file={}".fornat(db3file))
		exit()
	print("MSG_450 __FOUND db3file={} sql_create_v={}".format(db3file, sql_create_v))
	sql3=sqlite3.connect(db3file)
	cur=sql3.cursor()
	cur.execute(sql_create_v)
	sql3.close()
	print("MSG_460 SQL3_CLOSE db3file={} sql_create_v={}".format(db3file, sql_create_v))

	dttm=kodts('')
	j=0
	for line in data:
		j=j+1
		pathfile=line
		msg="MSG_350 j={} line={}".format(j,line)
		komsg(msgfil,msg,'')

		(pathfile,path,base,file,ext,size,ctime,isfile)=fileinfo(pathfile)
		msg="BUGS_351 j={} pathfile={} path={} base={} file={} ext={} size={} ctime={} isfile={}".format(j,pathfile,path,base,file,ext,size,ctime,isfile)
		komsg(msgfil,msg,'')

		if( not skipprompt == "" ):
			if( j==skipprompt ): 
				continue 
			else:
				skipprompt=""
				usrcmd=""

		if( not nextprompt == "" ):
			if( j==nextprompt):
				nextprompt=""
				usrcmd=""


		if( not re.search("^g",usrcmd)):
			nextprompt=""
			print( "e=exit q=quit s=skip enter=continue g=go" );
			usrcmd=prompt_raw("prompt: ")
			if( re.search('^e',usrcmd)): exit()
			if( re.search('^q',usrcmd)): return()
			if( re.search('^s',usrcmd)): 
				skipnum=int(usrcmd.replace("^s",""))
				j=j+skipnum
				usrcmd="go"
			if( isnumber(usrcmd)): 
				nextnum=int(usrcmd)
				nextprompt=j=j+int(usrcmd)
				usrcmd="go"


			sql_insert=""
			sql_insert += "insert or replace into table {} (".format(tbl)
			sql_insert += fields
			sql_insert += " ) values ( "
			sql_insert += values
			sql_insert += " );\n";


			sql3 = sqlite3.connect(db3file, isolation_level=None)
			sql = sql3.cursor()
			dttm=kodts('')
			sql .execute("insert into {} ( dttm ) values ('{}')" .format(tbl,dttm))
			dttm=kodts('')
			sql .execute("insert into {} ( progid,dttm ) values ('{}','{}')" .format(tbl,progid,dttm))
			sql .execute("insert into {} ( progid,dttm ) values ('{}','{}')" .format(tbl,progid,dttm))
			sql .execute("insert into {} ( progid,dttm,pathfile ) values ('{}','{}','{}')" .format(tbl,progid,dttm,pathfile))
			sql3.close()

			msg="BUGS_400 j={} sql_insert={}".format(j,sql_insert)
			komsg(msgfil,msg,'')
			if( not re.search("^g",usrcmd)):
				if( re.search("^e",usrcmd)): exit()
				if( re.search("^q",usrcmd)): return()
				if( re.search("s",usrcmd)): continue

			sql3=sqlite3.connect(db3file)
			cur=sql3.cursor()
			cur.execute(sql_insert)

			if( txtmode != '' ):
				if( re.search(".txt$",pathfile)):
					if( not os.path.exists(pathfile)):
						print( "ERR_410 dttm={} j={} NOTFOUND pathfile={}".
format(dttm,j,pathfile)) 
					continue
					data=open(pathfile,"r").readlines()

					sql_update = ""
					sql_update += "update or replace in table if exists {} (".format(table)
					sql_update += "set content='{}' where pathfile='{}';".format(content,pathfile)

					if( not re.search("^g",usrcmd)):
						print( "e=exit q=quit s=skip enter=continue g=go" )
						usrcmd=prompt_raw("prompt: ")
						if( re.search("^e",usrcmd)): exit()
						if( re.search("^q",usrcmd)): return()
						if( re.search("^s",usrcmd)): continue



					sql3=sqlite3.connect(db3file)
					cur=sql3.cursor()
					cur.execute(sql_update)
					sql3.close()


				dttm=kodts('')
				sql_select = ""
				sql_select += "select status,progid,dttm,id,grp,title,subject,dt,startdate,starttime,enddate,endtime, patfile,path,file,ext,tmp "
				sql_select += "from {} ".format(tbl)
				sql_select += "where pathfile =='{}'".format(pathfile)

				msg="BUGS_400 dttm={} j={} sql_select={}".format(dttm,j,sql_select)
				komsg(msgfil,msg,'')

				if( not re.search("^g",usrcmd)):
					print( "e=exit q=quit s=skip enter=continue g=go" )
					usrcmd=prompt_raw("prompt: ")
					if( re.search("^e",usrcmd)): exit()
					if( re.search("^q",usrcmd)): return()
					if( re.search("^s",usrcmd)): continue



				sql3=sqlite3.connect(db3file)
				rows.row_factory = sqlite3.Row
				rows=sql3.cursor()
				cur.execute(sql_select)
				for row in rows:
					if( row['status']): status=row['status']
					if( row['progid']): progid=row['progid']
					if( row['dttm']): dttm=row['dttm']
					if( row['id']): id=row['id']
					if( row['grp']): grp=row['grp']
					if( row['title']): title=row['title']
					if( row['subject']): subject=row['subject']
					if( row['dt']): dt=row['dt']
					if( row['startdate']): startdate=row['startdate']
					if( row['starttime']): starttime=row['starttime']
					if( row['enddate']): enddate=row['enddate']
					if( row['endtime']): endtime=row['endtime']
					if( row['pathfile']): pathfile=row['pathfile']
					if( row['path']): path=row['path']
					if( row['file']): file=row['file']
					if( row['ext']): ext=row['ext']
					if( row['content']): content=row['content']
				sql3.close()


				msg="BUGS_500 j={} status={} progid={} dttm={} id={} grp={}\n".format(j,status,progid,dttm,id,grp)
				komsg(msgfil,msg,'')
				msg="BUGS_501 j={} dt={} startdate={} starttime={} enddate={} endtime={}".format(j,dt,startdate,starttime,enddate,endtime)
				komsg(msgfil,msg,'')
				msg="BUGS_502 j={} pathfile={} path={} file={} ext={} tmp={}\n" .format( j,pathfile,path,file,ext,tmp)
				komsg(msgfil,msg,'')
				if( txtmode != "" ):
					msg="BUGS_503 j={} pathfile={} content=\n".format(j,pathfile)
					komsg(msgfil,msg,'')
					print( "pqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpq\n")
					print( "{}".format(content))
					print( "bdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbd\n\n")
	return()

def sql_select_v(db3file,sql_select,txtmode,fmt):
	progid="ka1.py"
	dttm=kodts('')
	(msgfil,msg,errfil,err)=("{}_msg.txt".format(progid),"","{}_err.txt".format(progid))
	if( not os.path.exists(db3file)):
		err="ERR_481 sql_select_v NOTFOUND db3file={}".format(dttm,db3file)
		koerr(errfil,err,'')
		return(db3file)
	if( sql_select == "" ):
		err="ERR_482 sql_select_v NOTSET sql_select={}".format(dttm,sql_select)
		koerr(errfil,err,'')
		return(db3file)
	sql3=sqlite3.connect(db3file)
	sql3.row_factory = sqlite3.Row
	rows=sql3.cursor()
	rows.execute(sql_select)
	j=0
	for row in rows:
		if( row['status']): status=row['status']
		if( row['progid']): db_progid=row['progid']
		if( row['dttm']): db_dttm=row['dttm']
		if( row['id']): id=row['id']
		if( row['grp']): grp=row['grp']
		if( row['title']): title=row['title']
		if( row['subject']): subject=row['subject']
		if( row['dt']): dt=row['dt']
		if( row['startdate']): startdate=row['startdate']
		if( row['starttime']): starttime=row['starttime']
		if( row['enddate']): enddate=row['enddate']
		if( row['endtime']): endtime=row['endtime']
		if( row['pathfile']): pathfile=row['pathfile']
		if( row['path']): path=row['path']
		if( row['file']): file=row['file']
		if( row['ext']): ext=row['ext']
		if( row['tmp']): tmp=row['tmp']
		if( row['content']): content=row['content']



		komsg(msgfil,msg,'')
		msg="BUGS_500 j={} progid={} dttm={} status={} id={} grp={} \n".format(j,db_progid,db_dttm,status,id,grp)
		komsg(msgfil,msg,'')
		msg="BUGS_501 j={} title={} subject={}\n".format(j,title,subject)
		komsg(msgfil,msg,'')
		msg="BUGS_502 j={} dt={} startdate={} starttime={} enddate={} endtime={} \n".format(j,dt,startdate,starttime,enddate,endtime)
		komsg(msgfil,msg,'')
		msg="BUGS_503 j={} pathfile={} path={} file={} ext={} tmp={} \n".format(j, pathfile,path,file,ext,tmp)
	sql3.close()


def koerr(errfil,err,brief):
	progid="ka1.py"
	dttm=kodts('')
	fp=open(errfil,"a")
	fp.write("{}|{}|err|{}\n".format(progid,dttm,err))
	fp.close()
	if( brief != ""): print("{}|{}|{}\n".format(progid,dttm,err))
	
def komsg(msgfil,msg,brief):
	progid="ka1.py"
	dttm=kodts('')
	fp=open(msgfil,"a")
	fp.write("{}|{}|msg|{}\n".format(progid,dttm,msg))
	fp.close()
	if( brief != ""): print("{}|{}|{}\n".format(progid,dttm,msg))
	

def fileinfo(pathfile):
	(path,base,file,ext,size,ctime,isfile)=("","","","","","","")
	path=os.path.dirname(pathfile)
	base=os.path.basename(pathfile)
	file=os.path.splittext(base)[0]
	ext=os.path.splittext(base)[1]
	size=os.path.getsize(pathfile)
	ctime=time.ctime(os.path.getctime(pathfile))
	if( os.path.exists(pathfile)): isfile="y"
	return(pathfile,path,base,file,ext,size,ctime,isfile)

def housatonic(frompath):
	progid="ka1.py"
	dttm=kodts('')
	usrcmd=""
#	frompath="kb/pdf/housatonic_pdf"
#	syscmd_find="find {} -type f -name '*.pdf' | head -5 | grep -v ' '".format(frompath)
	syscmd_find="find {} -type f -name '*.pdf' | grep -v ' '".format(frompath)
	syscmd_cat="cat housatonic_pdfs.txt"
#	print( "BUGS_140 {} {} housatonic frompath={} syscmd_find={}".format(progid,dttm,frompath,syscmd_find))
#	(out,err)=kosys(syscmd_find,'')
	print( "BUGS_140 {} {} housatonic frompath={} syscmd_cat={}".format(progid,dttm,frompath,syscmd_cat))
	(out,err)=kosys(syscmd_cat,'')
	j=1
	pdfs=out.split("\n")
	pdfs_len=len(pdfs)
#	print( "BUGS_141 {} {} housatonic frompath={} syscmd_find={} pdfs_len={}".format(progid,dttm,frompath,syscmd_find,pdfs_len))
	print( "BUGS_141 {} {} housatonic frompath={} syscmd_cat={} pdfs_len={}".format(progid,dttm,frompath,syscmd_cat,pdfs_len))
	for pdf in pdfs:
		dttm=kodts('')
		if( pdf == "" ): continue
		dttm=kodts('')
		if( not os.path.exists(pdf)):
			print("BUGS_150 dttm={} NOTFOUND pdf={}".format(dttm,pdf))
			continue
#		print("BUGS_160 dttm={} FOUND pdf={}".format(dttm,pdf))

		path=os.path.dirname(pdf)
		base=os.path.basename(pdf)
		file=os.path.splitext(base)[0]
		ext=os.path.splitext(base)[1]
		print( "BUGS_170 dttm={} j={} pdf={}". format(dttm,j,pdf))
		print( "BUGS_171 path={} ".format(path))
		print( "BUGS_172 file={}".format(file))
		if( not usrcmd == 'g'): usrcmd=raw_input("prompt: ")
		if( usrcmd == "q"):exit()
		if( usrcmd == "s"):continue
		skipflag=""
#		if  re.search("(",pdf): skipflag="skip"
#		if  re.search(" ",pdf): skipflag="skip"
#		if  re.search(".",pdf): skipflag="skip"
		if  re.search("barr",pdf): skipflag="skip"
		if( skipflag != "" ):
			fp=open("housatonic_skip.txt","a")
			print( "dttm={} j={} pdf={}".format(dttm,j,pdf))
			fp.write("dttm={} j={} pdf={}".format(dttm,j,pdf))
			fp.close()
			continue
		tmpdir="/Volumes/ka1tbr1/ht/tmp"
		syscmd_convert="convert '{}' 'tmp/{}.png'".format(pdf,file)
#		syscmd_convert="convert '{}' '{}/{}.png'".format(pdf,tmpdir,file)


		print( "BUGS_180 dttm={} j={} syscmd_convert={}".format(dttm,j,syscmd_convert))
		if( not usrcmd == "g" ): usrcmd=raw_input("CONVERT_prompt: ")
		if( usrcmd == "q"):exit()
		if( usrcmd == "s"):continue
		(out,err)=kosys(syscmd_convert,'')

#		newfile=file.replace("(","").replace(")","").replace(" - ","-").replace(".","_").replace(" ","")
#		newpdf="{}/{}.pdf".format(path,newfile)
#		syscmd_cp="cp {} {}".format(pdf,newpdf)
#		syscmd_pngs='find {} -type f -maxdepth 1 -name "*.png"'.format(path)
		syscmd_pngs='find tmp -type f -maxdepth 1 -name "{}*.png"'.format(file)
		(out,err)=kosys(syscmd_pngs,'brief')	
		pngs=out.split("\n")
		pngs_len=len(pngs)
		print( "BUGS_180 dttm={} pngs_len={} syscmd_pngs={}".format(dttm,pngs_len,syscmd_pngs))
		if( not usrcmd == "g" ): usrcmd=raw_input("PNGS_prompt: ")
		if( usrcmd == "q"):exit()
		if( usrcmd == "s"):continue

#		print( "BUGS_190 dttm={} j={} pngs_len={} syscmd_convert={}". format(dttm,j,pngs_len,syscmd_convert))	
#		print( "BUGS_191 housatonic dttm={} j={} pdf={} ==============".format(dttm,j,path))
#		print( "BUGS_192 housatonic dttm={} j={} pngs={} file={}".format(dttm,j,pngs,file))

		k=1
		for png in pngs:
			dttm=kodts('')
			print( "BUGS_205 png={} pngs={}".format(png,pngs))
			path_png=os.path.dirname(png)
			base_png=os.path.basename(png)
			file_png=os.path.splitext(base_png)[0]
			ext_png=os.path.splitext(base_png)[1]
			outputbase="{}/{}".format(path_png,file_png)
			syscmd_tesseract="tesseract '{}' '{}' -l eng  --psm 3". format(png,outputbase,file_png) 

			print( "===============================" )
			print( "BUGS_300 dttm={} j={} k={} png={} outputbase={}".format(dttm,j,k,png,outputbase))
			print( "BUGS_301 dttm={} j={} k={} syscmd_tesseract=\n{}".format(dttm,j,k,syscmd_tesseract))
			if( not usrcmd == "g" ): usrcmd=raw_input("PNGS_prompt: ")
			if( usrcmd == "q"):exit()
			if( usrcmd == "s"):continue
			if( usrcmd == "g"):continue
			if( not os.path.exists(png)): 
				print( "BUGS_230 NOTFOUND png={}".format(png))
				continue
			(out,err)=kosys(syscmd_tesseract,'')
			print( "BUGS_230 out={}".format(out))
			k=k+1
		j=j+1

	syscmd_mv_png="mv tmp/*.png {}/png".format(tmpdir)
	(out,err)=kosys(syscmd_mv_png,'brief')
	syscmd_mv_txt="mv tmp/*.txt {}/txt".format(tmpdir)
	(out,err)=kosys(syscmd_mv_txt,'brief')

	exit()

# tesseract imagename outputbase [-l lang] [--oem ocrenginemode] [--psm pagesegmode] [configfiles...
# scanimage --batch --batch-print | tesseract -c stream_filelist=true - - pdf > output.pdf
# tesseract myscan.png out -c tessedit_page_number=0
# tesseract savedlist output
# tesseract -c textonly_pdf=1





#	path=os.path.dirname(frompath)
#	base=os.path.basename(frompath)
#	if( not base == "" ):
#		file="os.path.splitext(base)[0]
#		ext="os.path.splitext(base)[1]
	



#	if( re.search('go',frompath)) or (frompath == "" ):
	if( frompath == "" ):
		to_db3file="tl.db3"
		to_tbl="db3s"
		syscmd='find . -type f -maxdepth 2 -name "*.db3"'
		print( "BUGS_1650 FIND to_db3file{} to_tbl={} db3s_todos={} syscmd={}".format(to_db3file,to_tbl,db3s_todos,syscmd))
#		db3s_todos=os.system(syscmd)

		(out,err)=kosys(syscmd,'brief')
		pathfiles=out
		db3files=out.split("\n")

def sql3_executes(db3file, sql_execute):
	(tbl,cnt,schema)=('tbl0','-2','schema0')
	print( "BUGS_140 sql3_execute db3file={} sql_execute={}\n".format(db3file,sql_execute))
	try:
		sql3 = sqlite3.connect(db3file, isolation_level=None)
		db = sql3.cursor()
		if( sql_execute == "" ):
			print( "ERR_140 sql3_exec sql_exec={}".format(sql_exec))
			return('')

#		db.execute("drop table if exists {}".format(to_tbl))
#		db.execute("create table if not exists {} (id INTEGER PRIMARY KEY, name TEXT)".format(tbl))
#		db.execute("create table if not exists {} as select * from files0".format(to_tbl))
		db.execute(sql_execute)


	except sql3.Error as e:
		print( e )
		sys.exit(1)

	finally:
		if sql3:
			sql3.close()
	return((tbl,cnt,schema))

def sql3_select_tbls(db3file,sql_select):
	(tbl,cnt,schema)=('tbl0',-2,'schema0')
	print( "BUGS_140 sql3_selects db3file={} sql_select={}\n".format(db3file,sql_select))
	try:
		if( sql_select == "" ):
			sql_select="select name from sqlite_master where type='table'"

		sql3 = sqlite3.connect(db3file, isolation_level=None)
		sql3.row_factory = sqlite3.Row
		rows = sql3.cursor()
		rows.execute(sql_select)
#		db.execute("drop table if exists {}".format(to_tbl))
#		db.execute("create table if not exists {} (id INTEGER PRIMARY KEY, name TEXT)".format(tbl))
#		db.execute("create table if not exists {} as select * from files0".format(to_tbl))

		print( "BUGS_150 SELECT sql_select={}\n".format(sql_select))

# 		tbl like '&_content'
# 		tbl like '&_segments'
# 		tbl like '&_segdir'
		j=0; tbls=""
		results=()
		for row in rows:
#			results[j]=row
			tbl=row['name']
#			tbl=row[0]
			if( re.search('_content',tbl)): continue
			if( re.search('_segments',tbl)): continue
			if( re.search('_segdir',tbl)): continue
			if( tbl == "" ): continue
			tbls += "{}\n".format(tbl)
			j=j+1
			print("BUGS_210 db3s ROW j={} db3file={} tbl={}".format(j,db3file,tbl ))
		

	except sql3.Error as e:
		print( e )
		sys.exit(1)

	finally:
		if sql3:
			sql3.close()
#	return((tbl,cnt,schema))
	return(tbls)



def sql3_db(fildb3):
	try:
		db3 = sql3.connect('sql3.db3', isolation_level=None)
    
		db = db3.cursor()
		db.execute("DROP TABLE IF EXISTS friends")
		db.execute("CREATE TABLE friends(id INTEGER PRIMARY KEY, name TEXT)")
		db.execute("INSERT INTO friends(name) VALUES ('jkwii')")
		db.execute("INSERT INTO friends(name) VALUES ('skwii')")
		db.execute("INSERT INTO friends(name) VALUES ('uwii')")
		db.execute("INSERT INTO friends(name) VALUES ('mewii')")
		db.execute("INSERT INTO friends(name) VALUES ('hewii')")
		db.execute("INSERT INTO friends(name) VALUES ('shewii')")
		db.execute("INSERT INTO friends(name) VALUES ('paityn')")
		db.execute("INSERT INTO friends(name) VALUES ('carter')")
		db.execute("INSERT INTO friends(name) VALUES ('blake')")
		db.execute("INSERT INTO friends(name) VALUES ('sk')")
		db.execute("INSERT INTO friends(name) VALUES ('jk')")
		db.execute("INSERT INTO friends(name) VALUES ('Rebecca')")
		db.execute("INSERT INTO friends(name) VALUES ('Jim')")
		db.execute("INSERT INTO friends(name) VALUES ('Robert')")

		db.execute("INSERT INTO friends(name) VALUES ('jak1')")
		db.execute("INSERT INTO friends(name) VALUES ('jak2')")
		db.execute("INSERT INTO friends(name) VALUES ('jak3')")

	except db3.Error as e:
		print( e )
		sys.exit(1)

	finally:
		if db3:
			db3.close()

















def ko_dttm():
	import datetime
	import time

	now = datetime.datetime.now();
	today = now.date();
	moment = now.time();
	today = datetime.date.today()
	dttm =  now.strftime('%Y-%m-%d_%H:%M:%S')  # This writes "06/24/1984"

#	dttm =  now.strftime('%m/%d/%Y')  # This writes "06/24/1984"
#	today =today.year + today.month + today.day + "_" 
#	today += today.hour + today.minute + today.second

#	print('The current time is :', time.ctime())
#	newtime = time.time() + 20
#	print('20 secs from now :', time.ctime(newtime))
#	print( progid, "MSG: dttm today=",today,time.ctime())


#  9. Obtain the number of days and seconds between the epoch and now, or the total number of seconds that have passed:
#	delta = now - epoch
#	days = delta.days
#	seconds = delta.seconds
#	total_seconds = delta.total_seconds()
#	delta = now - epoch
#	days = delta.days

#	string_date = str(my_date)
# 12. Recover a date object from a string like ?1984-06-24?:
#	my_date = datetime.date(*[int(i) for i in string_date.split("-")])
	

	return(dttm)

def ko_do(a0,a1,a2,a3):
	print( '{} {} ko_do: a0={} a1={} a2={} a3={}'.format(progid,dttm, a0,a1,a2,a3))
	print( __file__ )
	print( os.path.join(os.path.dirname(__file__), '..'))


def ko_dodo(a0,a1,a2,a3):
	print( '{} {} ko_dodo: a0={} a1={} a2={} a3={}'.format(progid,dttm, a0,a1,a2,a3))
	print( __file__ )
	print( os.path.join(os.path.dirname(__file__), '..'))


def ko_do_mp42gif(a0,a1,a2,a3):
	dttm=kodts('')
	print( '{} {} ko_do_mp42gif: a0={} a1={} a2={} a3={}'.format(progid,dttm, a0,a1,a2,a3))
	print( __file__ )
	print( os.path.join(os.path.dirname(__file__), '..'))
	print( os.path.dirname(os.path.realpath(__file__)))
	print( os.path.abspath(os.path.dirname(__file__)))



	print( progid,dttm,"ko_do a1,a2=", a1,a2)
	colors = "white black ivory darkslategrey red white blue yellow".split(" ")
	colors = "ivory yellow".split(" ")
	fonts = "./fonts/yokkmokk.ttf ariel".split(" ")
	
	cats = "cat acct biz cont test".split(" ")
	cats = "cat acct biz cont edu food gov konabus law lib med med media org phy rel sci stlc util".split(" ")
	fonts = "ShearBeauty LokiCola fixed Courier AvantGarde-Book Bookman-Demi Helvetica NewCenturySchlok-Roman Palatino-Roman Symbol ./fonts/yokkmokk.ttf Times-Roman ".split(" ")
	ifile="./imgs/btn/koeye.png"
	pointsize_default = 38


# print(os.path.isdir("./us/imgs/cat"))
# print(os.path.exists("/home/el/myfile.txt"))
#	results = os.popen('cat us.psv').read()
#	print( "results=".format(results))

	mkdir_flag='true'
	mktn_flag='true'
	mkim_flag='true'

	document_root_ko0="/home2/kozerus/public_html"
	document_root_ko2="/home1/kotwous/public_html"
	document_root_ka10="/ht"
	document_root_ka11="/Volumes/ka1tbr1/ht"
	document_root_ka12="/Volumes/ka1tbr2/ht"
	document_root=document_root_ka12
	print( '{} {} do BUGS_101: document_root={}'.format( progid, dttm, document_root ))
	print( '{} {} do BUGS_102: mktn_flag={}'.format( progid, dttm, mktn_flag ))
	print( '{} {} do BUGS_103: mkim_flag={}'.format( progid, dttm, mkim_flag ))

	if not os.path.isfile(a2):
		print("{} {} ERR: NOTFOUND ifile={}  ".format( progid,dttm,a2))
		sys.exit()

	print( progid,dttm, "runwl a1={} a2={} a3={}".format( a1,a2,a3 ))
	wl_filename=a2
	linematch_beg='<div id="div_runwl">'
	linematch_end="</div>"

	out_filename=a2.replace(".txt", ".out" )
	index_sl_filename=a2.replace(".txt", ".html" )
	index_slv_filename=a2.replace(".txt", ".html" )
	index_tl_filename=a2.replace(".txt", ".html" )

	print("{} {} MSG_110: a2={}  ".format( progid,dttm,a2))
	print("{} {} MSG_111: index_sl_filename={}  ".format( progid,dttm,index_sl_filename))
	print("{} {} MSG_112: index_slv_filename={}  ".format( progid,dttm,index_slv_filename))
	print("{} {} MSG_113: index_tl_filename={}  ".format( progid,dttm,index_tl_filename))



	wl_file=open( wl_filename, "r" )
	out_file=open( out_filename, "wb" )





	if( os.path.exists( a2 )):
		with open(a2) as f:
			j=0
			for line in f:
				j += 1
				pathfile=line.split()[8]
				path=os.path.dirname(pathfile)
				base=os.path.basename(pathfile)
				file=os.path.splitext(base)[0]
				ext=os.path.splitext(base)[1]

				path=path.replace(document_root_ko0,'')
				path=path.replace(document_root_ko2,'')
				path=path.replace(document_root_ka10,'')
				path=path.replace(document_root_ka11,'')
				path=path.replace(document_root_ka12,'')

				o_pathfile_htm=a2.replace(".txt", ".htm")
				divid=a2.replace(".txt","")
				htmdiv='<div id="{}">\n'.format( divid )

# for filename in os.listdir(DIRECTORY):
#    if (filename.endswith(".mp4"): #or .avi, .mpeg, whatever.
#        os.system("ffmpeg -i {0} -f image2 -vf fps=fps=1 output%d.png".format(filename))
#    else:
#        continue

				i_pathfile='{}/{}/{}'.format(document_root,path,base)
				i_pathfile_mp4='{}/{}/{}'.format(document_root,path,base)
				o_pathfile_jpg='{}/{}/img/{}_%03d.jpg'.format(document_root,path,file)
				i_pathfile_jpg1='{}/{}/img/{}_001.jpg'.format(document_root,path,file)
				i_pathfile_jpgs='{}/{}/img/{}_*.jpg'.format(document_root,path,file)
				o_pathfile_png='{}/{}/tn/tn_{}.png'.format(document_root,path,file)
				o_pathfile_gif='{}/{}/tn/tn_{}.gif'.format(document_root,path,file)


				o_pathfile='{}/{}/img/{}_%03d.jpg'.format(document_root,path,file)
				o_pathfile_im='{}/{}/img/{}_%03d.jpg'.format(document_root,path,file)
				o_pathfile_tn='{}/{}/img/{}_%03d.gif'.format(document_root,path,file)

				print( "BUGS_141 i_pathfile_mp4={}".format(i_pathfile_mp4))
				print( "BUGS_142 o_pathfile_jpg={}".format(o_pathfile_jpg))
				print( "BUGS_144 i_pathfile_jpg1={}".format(i_pathfile_jpg1))
				print( "BUGS_145 i_pathfile_jpgs={}".format(i_pathfile_jpgs))
				print( "BUGS_146 o_pathfile_gif={}".format(o_pathfile_gif))


				abs_tn_path='{}/{}/tn/'.format(document_root, path)
				tn_path='{}/tn/'.format(path)
				tn_base='tn_{}.gif'.format(file)

				abs_tn_pathfile='{}/{}{}'.format( document_root, tn_path, tn_base )
				tn_pathfile='{}{}'.format( tn_path, tn_base )

				abs_im_path='{}/{}/img/'.format(document_root,path)
				im_path='{}/img/'.format(path)
				im_base='{}.png'.format(file)
				abs_im_pathfile='{}/{}{}'.format( document_root, im_path, im_base )
				im_pathfile='{}{}'.format(  im_path, im_base )

				print( 'i_pathfile={}'.format( i_pathfile)	)
				print( 'o_pathfile={}'.format( o_pathfile)	)

				print( 'abs_tn_path={}'.format( abs_tn_path)	)
				print( 'abs_tn_pathfile={}'.format( abs_tn_pathfile )	)
				print( 'abs_im_path={}'.format( abs_im_path)	)
				print( 'abs_im_pathfile={}'.format( abs_im_pathfile )	)

				print( 'tn_path={}'.format( tn_path)	)
				print( 'tn_pathfile={}'.format( tn_pathfile )	)
				print( 'im_path={}'.format( im_path)	)
				print( 'im_pathfile={}'.format( im_pathfile )	)

				print( '{} pathfile={}'.format( j, pathfile ))
#				print( '   path={} base={} file={} ext={}'.format( path, base, file, ext ))
#				print( '   tn_pathfile={}'.format(tn_pathfile))
#				print( '   im_pathfile={}'.format(im_pathfile))


# BUGS160
#				mybase="kludge"
#				syscmd="ffmpeg -i 1.mp4 -vf fps=1/60 ffmpeg_img%03d.jpg"
#				syscmd="ffmpeg -i 1.mp4 -vf fps=1/60 {}_%03d.jpg".format(mybase)
#				os.system(syscmd)
				





				if( not os.path.exists( abs_tn_path )):
					syscmd_mkdir='mkdir {}'.format( abs_tn_path )
					print( '{} {} NOTFOUND: abs_tn_path={} {}'.format( progid, dttm, abs_tn_path, syscmd_mkdir ))
					if( mkdir_flag == 'true' ): os.system( syscmd_mkdir )
				else:
					print( '{} {} FOUND: abs_tn_path={}'.format( progid, dttm, abs_tn_path ))
					syscmd_mktn='cp {}/imgs/btn/koeye.png {}'.format( document_root, abs_tn_pathfile )
					print( '{} {} syscmd_mktn={}'.format( progid, dttm, syscmd_mktn ))
					if( mktn_flag == 'true' ): os.system( syscmd_mktn )

				if( not os.path.exists( abs_im_path )):
					syscmd_mkdir='mkdir {}'.format( abs_im_path )
					print( '{} {} NOTFOUND: abs_im_path={}'.format( progid, dttm, abs_im_path ))
					if( mkdir_flag == 'true' ): os.system( syscmd_mkdir )
				else:
					print( '{} {} FOUND: abs_im_path={}'.format( progid, dttm, abs_im_path ))
					syscmd_mkim='cp {}/imgs/btn/koeyeb.png {}'.format( document_root, abs_im_pathfile )
					print( '{} {} syscmd_mkim={}'.format( progid, dttm, syscmd_mkim ))
					if( mkim_flag == 'true' ): os.system( syscmd_mkim )


					flag_im = "y"
					ffmpeg_fps="1"
					ffmpeg_fps="1/60"
					ffmpeg_fps="1/10"
					ffmpeg_fps="1/20"

					syscmd_ffmpeg="ffmpeg -i {} -vf fps=1/60 {}".format(i_pathfile_mp4, o_pathfile_jpg )
					syscmd_ffmpeg="ffmpeg -i {} -vf fps=1 {}".format(i_pathfile_mp4, o_pathfile_jpg )
#					syscmd_ffmpeg="ffmpeg -i {} -vf fps=1/10 -s 360x240 {}".format(i_pathfile_mp4, o_pathfile_jpg )
					syscmd_ffmpeg="ffmpeg -i {} -vf fps={} -s 360x240 {}".format(i_pathfile_mp4, ffmpeg_fps, o_pathfile_jpg )
					print( "{} {} BUGS_200 syscmd_ffmpeg={}\n".format( progid, dttm, syscmd_ffmpeg ))
					if( flag_im == "y" ): os.system( syscmd_ffmpeg )

# mogrify -resize 320 *.jpg 
# convert -delay 15 -loop 0 *.jpg douglas.gif

					flag_tn = "y"
					flag_jpgs_rm = ""
					syscmd_jpg12png="convert {} -size 100x200 {}".format(i_pathfile_jpg1, o_pathfile_png )
#					syscmd_jpgs2gif_mogrify="mogrify -resize 200 {}".format(i_pathfile_jpgs)
					syscmd_jpgs2gif="convert -delay 15 -loop 0 {} {}".format(i_pathfile_jpgs, o_pathfile_gif )
					syscmd_jpgs_rm="rm {}".format(i_pathfile_jpgs )
					print( "{} {} BUGS_201 syscmd_ffmpeg={}\n".format( progid, dttm, syscmd_ffmpeg ))
					print( "{} {} BUGS_202 syscmd_jpg12png={}\n".format( progid, dttm, syscmd_jpg12png ))
					print( "{} {} BUGS_203 syscmd_jpgs2gif={}\n".format( progid, dttm, syscmd_jpgs2gif ))
					print( "{} {} BUGS_204 syscmd_jpgs_rm={}\n".format( syscmd_jpgs_rm ))
					if( flag_tn == "y" ): os.system( syscmd_jpg12png )
#					if( flag_tn == "y" ): os.system( syscmd_jpgs2gif_mogrify )
					if( flag_tn == "y" ): os.system( syscmd_jpgs2gif )
#					if( flag_jpgs_rm == "y" ): os.system( syscmd_jpgs_rm )

#					exit();

# convert   -delay 20   -loop 0  -size 100x200 sphere*.gif   animatespheres.gif


##					flag_ffmpeg_seek = ""
##					seekpoint=10
##					if( flag_ffmpeg_seek == "yes" ): os.system( ffmpeg_seek_cmd )
##					ffmpeg_seek_cmd = 'ffmpeg  -i {} -vf fps={} -vcodec mjpeg -vframes 1 -an -s 1920x1000 -f rawvideo {}'.format( i_pathfile, "1/60", o_pathfile )
##					ffmpeg -y -ss $SEEK_POINT -i input.ogv -vcodec mjpeg -vframes 1 -an -s 120x90 -f rawvideo output.jpg
##					ffmpeg_seek_cmd = 'ffmpeg -y -ss {} -i {} -vcodec mjpeg -vframes 1 -an -s 1920x1000 -f rawvideo {}'.format( seekpoint, i_pathfile, o_pathfile )
##					ffmpeg_seek_cmd = 'ffmpeg  -i {} -vf fps=1/60 -s 1920x1000 -f rawvideo {}'.format( i_pathfile, o_pathfile )
##					print( progid,dttm, "ko_go ffmpeg_seek_cmd={}\n".format( ffmpeg_seek_cmd ))
##					subprocess.call( ffmpeg_seek_cmd )
##					if( flag_ffmpeg_seek == "yes" ): os.system( ffmpeg_seek_cmd )

#					im_cmd='mogrify -resize x100 -write {} {}'.format( abs_tn_pathfile, i_pathfile )
#					print( progid,dttm, "ko_go im_cmd={}\n".format( im_cmd ))
#					if( flag_im == "yes" ): os.system( im_cmd )
#					subprocess.call( im_cmd )
#					os.system( "mogrify  -resize x300 -set filename:name %f  -write './pn/imgs/tn/tn_%[filename:name]' ./pn/imgs/*.jpg" ) 



#				print( '<a href="{}" data-poster="/imgs/btn/koeye.png">'.format(pathfile))
#				print( '<img src="/imgs/btn/koeye.png" alt="{}" data-description="{}"></a>'.format(pathfile,base))


#				print( "{} <a href={} _target=_blank>".format(j, base))
#				print( " <img src={} _target=_blank>".format(base))
#				print( "	</a>")
# 				print( progid,dttm,j, pathfile, path, base, file, ext)

				htmdiv = ''
				htmdiv += '<a href="{}" target=_blank class="thumbnamil">\n'.format(i_pathfile_mp4)
				htmdiv += '	<img src="{}" border=0>\n'.format( o_pathfile_png )
				htmdiv += '	<span><img src="{}" border=0></span>\n\n'.format( o_pathfile_gif )
				print( "{} {} MSG_122:  htmdiv={}".format( progid, dttm, htmdiv ))
				ofile=open(o_pathfile_htm, "a+")
				ofile.write(htmdiv)
				ofile.close()

#		pathfile=a2
#		if( not os.path.isdir( catpath )):
#			syscmd_mkdir = "mkdir ./us/imgs/{}".format( cat )
#			print( progid,dttm, "ko_do: syscmd_mkdir={}".format( syscmd_mkdir ))
#			os.system( syscmd_mkdir )


	ofile=open(o_pathfile_htm, "a+")
	htmdiv += '	</div>\n'

	print( "{} {} MSG_121:  o_pathfile_htm={}".format( progid, dttm, o_pathfile_htm ))
	print( "{} {} MSG_122:  htmdiv={}".format( progid, dttm, htmdiv ))

	ofile.write(htmdiv)
	ofile.close()

	exit()


#	import subprocess
	direct_output = subprocess.check_output('ls', shell=True) #could be anything here.
	proc = subprocess.Popen(["cat", "us.psv"], stdout=subprocess.PIPE, shell=True)
	(out, err) = proc.communicate()
	print( "program output:", out)


	for cat in cats:
		if( not os.path.isdir( catpath )):
			syscmd_mkdir = "mkdir ./us/imgs/{}".format( cat )
			print( progid,dttm, "ko_do: syscmd_mkdir={}".format( syscmd_mkdir ))
#			os.system( syscmd_mkdir )


		for color in colors:
			for font in fonts:
				dttm=kodts('')
				stroke=color
				gravity="center"
				pointsize=28
				fontcode=font.replace("./fonts/","").replace(".ttf","").replace("-","").lower()
				if( fontcode == "newcenteryschlokroman" ): fontcode="schlok"
				pointsize=pointsize_default

#				ofile="./us/imgs/cat_{}.png".format( cat )
				ofile="./us/imgs/koeye_{}_{}_{}.png".format( cat, color, fontcode )
				ifile2="./kodome.png"


#		convert -background none  -fill white \
#			-font Ravie  -pointsize 36   label:A   label_A_white.png
#		composite -gravity center label_A_white.png   rose:   compose_over.gif
#
#		convert  rose:   label_A_white.png \
#			-geometry +5-15   -composite   convert_over.gif
#
#		convert -background none  -fill black \
#			-font Ravie  -pointsize 36   label:A   label_A_black.png
#		composite -compose Dst_Over  -geometry +5+5 \
#			label_A_black.png  label_A_white.png   compose_under.png
#		composite -compose Src  -size 100x100  plasma:tomato-dodgerblue \
#			rose:   compose_crop.gif


#		composite -compose Src -gravity South 
#			hand_point.gif   rose:   -alpha set   compose_expand.gif

#		composite -compose Copy -gravity South 
#			hand_point.gif   rose:   -alpha set   compose_copy.gif
#		composite -compose Dst_In  -gravity center 
#			label_A_white.png  rose: -alpha Set  compose_mask.png
#		convert -size 60x60  compose_xor_2.png  
#			\( xc:none -fill green  -draw 'circle 30,21 30,3'  \) 
#			-compose Xor   -composite   compose_xor_3.png
#		convert -size 60x60 
#			\( xc:none -fill blue   -draw 'circle 21,39 24,57' \) 
#			\( xc:none -fill red    -draw 'circle 39,39 36,57' \) 
#			-compose Xor   -composite   compose_xor_2.png
#		convert -size 64x64 gradient:             gradient_src.png
#		convert -size 64x64 gradient: -rotate 90  gradient_dst.png
#		composite gradient_src.png -compose Multiply gradient_dst.png \
#			gradient_result.png
# two grayscale gradients the brightest colors will wrap to form a second gradient.
#		convert -size 60x60 gradient:    gradient.png
#		composite  gradient.png gradient.png -compose ModulusAdd  compose_add.png
#		composite gradient.png \( gradient.png -rotate -90 \) \
#			-compose ModulusAdd   gradient_diagonal.png
#		convert gradient.png \( +clone +clone +clone +clone \) \
#			-background gray50 -compose ModulusAdd -flatten  gradient_venetian.png
#		convert -size 64x64  xc:dodgerblue \
#			-draw 'fill skyblue   circle 32,32 7,27'  circle_blue.jpg
#		convert circle_blue.jpg -shade 120x30 -auto-level circle_shaded.jpg
#		convert circle_shaded.jpg  circle_blue.jpg \
#			-compose Overlay -composite   circle_shaded_tinted.jpg

#		convert rose: -fill gray50 -colorize 100% \
#			-raise 4 -normalize -blur 0x4  lighting_effect.png
#		convert rose: lighting_effect.png \
#			-compose hardlight -composite  compose_hardlight.png
#		composite -dissolve {argument}  -gravity South \
#			star.gif   dragon_sm.gif -alpha Set   {result}
#		composite -blend {argument}  -gravity South \
#			compose_R.png compose_plus_GB.png  -alpha Set  {result}
#		composite  -tile star.gif   netscape:   tile.gif
#		convert -background none -pointsize 36 label:'Tile Under'  png:- |\
#		composite -tile bg.gif  -   -compose Dst_Over   tile_under.gif

#		convert overlay_figure.gif   overlay_bgnd.gif  \
#			-compose ChangeMask  -composite  overlay_removed.png

# convert handhi.gif -set  delay 20 handhi_20.gif
# convert koeye.png handhi_10.gif -compose CopyOpacity  koeye_hand_10.gif

#		convert overlay_bgnd.gif  overlay_figure.gif \
#			-compose ChangeMask  -composite  overlay_changed.png
#		convert overlay_figure.gif overlay_bgnd.gif -compose ChangeMask  -composite \
#			-channel A -negate      overlay_unchanged.png
#		onvert -size 100x100 xc: +noise Random -separate \
#		          null: \( xc: +noise Random -separate -threshold 30% -negate \) \
#		              -compose CopyOpacity -layers composite \
#		          -set dispose background -set delay 20 -loop 0   glitter_overlay.gif
#		convert glitter_overlay.gif \
#		          -compose Screen -bordercolor GoldenRod -border 0x0  glitter_gold.gif
#		convert glitter_overlay.gif null: -size 100x100 \
#		          plasma:red-firebrick plasma:red-firebrick  plasma:red-firebrick \
#		          -compose Screen -layers composite    glitter_plasma.gif
#		convert -size 100x100 -fill white -background black -font Candice \
#		          -gravity center -pointsize 90 label:A    glitter_mask.gif
#		  convert glitter_plasma.gif null: glitter_mask.gif +matte \
#		          -compose CopyOpacity -layers composite   glitter_masked.gif
#		

#		  convert \( neon_h.gif -coalesce -append \) \
#		          \( neon_e.gif -coalesce -append \) \
#		          \( neon_l.gif -coalesce -append \) \
#		          \( neon_l.gif -coalesce -append \) \
#		          \( neon_o.gif -coalesce -append \) \
#		          +append  -crop x60 +repage  -set delay 100  neon_hello.gif
#		
#		
#		  convert neon_h.gif'[0]' neon_e.gif'[0]' neon_l.gif'[0]' neon_l.gif'[0]' \
#		          +append \( +clone \) -append \
#		          \( neon_o.gif -coalesce -append \)    +append \
#		          \( +clone \) -append \( +clone \) -append \( +clone \) -append \
#		          -crop x60 +repage   -set delay 3 \
#		          \( -clone 0  -set delay 300 \) -swap 0,-1 +delete \
#		          \( -clone 1  -set delay  10 \) -swap 1,-1 +delete \
#		          \( +clone    -set delay 200 \) +swap      +delete \
#		          -quiet -layers OptimizeFrame   neon_hell.gif

#		 convert  -flip  storm.gif   cmd_flip_legacy.gif

#		 identify -format '%k\n' tree.gif
#		 mogrify -format gif  -size 200x200  -pointsize 18 \
#		          -font Candice -gravity north  -annotate 0 "%f" \
#		          -font Ravie   -gravity Center -annotate 0 "%f" \
#		          -font Gecko   -gravity south  -annotate 0 "%f" \
#		          -size 100x64   xc:gold  xc:orange   xc:tomato
#		convert  -size 32x32 xc:none -draw 'circle 15.5,15.5 15.5,0'  circle.gif
#		mogrify  -alpha Set -draw 'image Dst_In 0,0 0,0 "circle.gif"'  mogrify_*.gif

#	convert \( eye.gif    news.gif  +append \) \
#          \( storm.gif  tree.gif  +append \) \
#          -append  cmd_array2.gif
#convert -respect-parenthesis \
#          -font Arial   label:"This is a line of plain text." \
#          \( -font Candice -pointsize 16 -fill red -undercolor lightblue \
#              label:"A line using a lot of different settings." \) \
#          label:"Text is back to normal -- like Magick\!" \
#          -append  cmd_settings_lots.gif
#

# ani.gif resize
# 	convert anim.gif -coalesce anim_coalesce.gif
#	convert -size <original size> anim_coalesce.gif -resize 24x24 anim_resize_24.gif.
#	convert in_animation.gif -coalesce -crop WxH+X+Y +repage -layers optimize out_animation.gif
#	convert tANtN.gif -background white -alpha background tANtN_new.gif
#	convert tANtN.gif -alpha off -channel rgb -evaluate set 0 -channel rgba -alpha on tANtN_new.gif

#	convert logo: -transparent white -duplicate 3 logo_4f.gif
#	convert logo_4f.gif -alpha off logo_4f_aoff.gif
#	convert logo_4f.gif -coalesce -alpha off -evaluate set 0 -alpha on logo_4f_black.gif
#	convert logo_4f_black.gif -alpha off logo_4f_black_aoff.gif

#	convert warning.gif  -coalease -draw 'image DstOver 0,0 0,0 "koeye.png"' -layers optimize koeye_warning.gif






# convert handhi_10.gif -coalesce -gravity NorthEast -draw image over 0,0 0,0 'koeye.png' -layers Optimize koeye_hand10.gif 

# overlay
				cmd_overlay = "convert {} -coalesce -gravity NorthEast -draw image over 0,0 0,0 '{}' -layers Optimize {}".format( ifile, ifile2, ofile )
				print( progid,dttm, "ko_do: cmd_overlay={}".format( cmd_overlay ))

# composite_overlay
# convert handhi_10.gif -draw 'image over 0,0 0,0' koeye.png -composite koeye_hand_10.gif
				cmd_coverlay = "convert {} -colorspace sRGB \ ".format( ifile )
				cmd_coverlay += " \( +clone -size 300x150 -tile gradient:LightYellow \ "
				cmd_coverlay += " -draw 'color 0,0 reset' \) \ "
				cmd_coverlay += " \( +clone -size 300x150 -tile plasma:tomato \ "
				cmd_coverlay += " -draw 'color 0,0 reset' \) \ "
				cmd_coverlay += " -reverse  -composite {}".format( ofile )
#				print( progid,dttm, "ko_do: cmd_coverlay={}".format( cmd_coverlay ))

#				cmd_convert="convert input.jpg -gravity South -annotate 0 '%f' output.jpg"

				if( len( cat ) >5 ):  pointsize=pointsize_default - 20
				if( fontcode == "yokkmokk" ):  pointsize=pointsize_default + 10
				cmd_convert="convert {} -font {} -stroke {} -gravity {} -pointsize {} -annotate 0 '{}' {}".format(ifile,font,stroke,gravity,pointsize,cat,ofile)
				print( progid,dttm, "ko_do: cmd_convert={}".format( cmd_convert ))
				os.system( cmd_convert )
	return("ko_do_return");



def ko_find(a1,a2):
	import subprocess
	import re
# bugs	from ffvideo import VideoStream
# bugs	import VideoStream
# bugs	import ffviceo

#	if( sys.argv[1].match("listdir")):
#	if( sys.argv[1] == "listdir" ):
#	if( a2 != "" ):
	if( a1 != "" ):
		dttm=kodts('')
		print( progid,dttm, "ko_go: a2=",a2)
#		ko_listdir( sys.argv[2], sys.argv[3] )
		pathfile=a2
		path=os.path.dirname(pathfile)
		base=os.path.basename(pathfile)
		file=os.path.splitext(base)[0]
		ext=os.path.splitext(base)[1]
#		filecode_tuple=str(j),"-",file,"-",ext
#		filecode = "".join(filecode_tuple)
#		print( progid,dttm, "ko_go: path=",path," base=",base," ext=",ext)

	if( a2 == "" ): todofile=a2


	dttm=kodts('')
	print( progid,dttm,"ko_go a1=",a1)
	pathfile="."
	ofilename="ko_go.csv"
	ifilename=ofilename
	tmp_pathfile="ko_go.tmp"
	todo_pathfile="ko_go.todo"
	db3_pathfile="ko_go.db3"

	if( a1 != "" ): pathfile=a1

#	syscmd="ls -lat {} | exiftool -s -csv".format( pathfile )
	syscmd_find = 'find {} -name "{}" -exec ls {} \; > {}'.format( path, base, "{}", tmp_pathfile )
	print( progid,dttm, "ko_go_find syscmd={}".format( syscmd_find ))
#	os.system( syscmd_find )

	pathcode=path.replace("/","-")
	pathcode=pathcode.replace(".","")

	if( os.path.isfile(ofilename)):
		print( progid,dttm, "ko_go ofilename={}".format( ofilename ))
	else:
		todofile_dttm="ka1_{}.todo".format(dttm)
		todofile="ka1{}.todo".format( pathcode )
#		syscmd='find . -name "* *.mp4" -exec ls {} \; > '^
#		syscmd='find . -name "*--*.mp4" -exec ls {} \; > 'M
##		syscmd='find . -name "*.mp4" -exec ls {} \; > '
		syscmd+=todofile
		syscmd = 'find {} -name "{}" -exec ls {} \; > {}'.format( path, base,"{}", todofile )
		print( progid,dttm, "ko_go_find syscmd={}".format( syscmd ))
		print( progid,dttm, "ko_go_find pathcode={}".format( pathcode ))
		os.system( syscmd )

	print( progid,dttm, "ko_find todofile={}".format( todofile ))
	return( "ko_find")


def runwl(a1,a2,a3):
	print( progid,dttm, "runwl a1={} a2={} a3={}".format( a1,a2,a3 ))
	wl_filename=a2
	linematch_beg='<div id="div_runwl">'
	linematch_end="</div>"

	db3_filename=wl_filename.replace(".todo", ".db3" )
	out_filename=wl_filename.replace(".todo", ".txt" )

	wl_file=open( wl_filename, "r" )
	out_file=open( out_filename, "wb" )

	j=0
	mode=""
	for line in wl_file:
		j=j+1
		f_file=line
		t_file=pathfile_fmt(f_file)
		print( progid,dttm, "runwl {} t_file={} {}".format( j,t_file,f_file ))
		if re.search( linematch_beg, line ):
			mode = "match"
		if re.search( linematch_end, line ):
			mode = ""

		print( progid,dttm, "runwl wl_filename={} {} {}".format( wl_filename,j,line ))

	wl_file.close
	return( "runwl_break" )

	sys_in, sys_out, sys_err = os.popen3(syscmd) 
	sys_outs = "".join(sys_out.read()).split("\n")
	sys_out_len = len( sys_outs )
	print( "BUGS_410 sys_out_len={} sys_outs={}\n".format( sys_out_len, sys_outs ))

	j=0
	for sys_out in sys_outs:
		j=j+1
		print( "BUGS_430 j={} sys_out={}".format(j,sys_out))

	return( "runwl_ok" )




def f2db3(db3file,ifile,tbl,id):
#	print( "BUGS_700 f2db3 db3file={} ifile={} tbl={} id={}\n".format(db3file,ifile,tbl,id));
	if( db3file == "" ):
		print( "ERR_701 NOTFOUND db3file={}".format(db3file))
		exit()
	if( ifile == "" ):
		print( "ERR_702 NOTFOUND ifile={}".format(ifile))
		exit()
	if( tbl == "" ):
		print( "ERR_703 NO_TBL tbl={}".format(tbl))
		exit()


	datasrc=ifile
	datasrc_len=len(datasrc.split(" "))
	(data,datalen)=("",0)
	if( datasrc_len == 1):
		data = open(ifile).readlines()
		datalen=len(data)
	else:
		syscmd="cat test.txt"
		syscmd=datasrc
		sys_in, sys_out, sys_err = os.popen3(syscmd)
		(data,datalen) = ("",0)
		j=0
		kludge=""
		for line in sys_out:
			if( line == "" ): continue
			if( line == "\n"): continue
			j=j+1
			line=line.replace("\n","")
			kludge += line+"\n"
#			print( "BUG_730 j={} line={}= ".format(j,line))
		data=kludge.split("\n")
		datalen=len(data)

	(headline,text,media,caption,credit) = ("headline","text","media","caption","credit")
# python ka1.py f2db3 tl.db3 "find txt -name '???.txt'" kludge
	j=0
#	for line in data:
	for j in range(0,datalen-1):
		line=data[j]
		if( line == "" ): continue
		if( line == "\n" ): continue
		j=j+1
		pathfile=line
		if( os.path.isfile(pathfile)):
			path=os.path.dirname(pathfile)
			base=os.path.basename(pathfile)
			if( len(base.split(".")) > 1):
				file=base.split(".")[0]
				ext=base.split(".")[1]
			(mode,ino,dev,nlink,uid,gid,size,atime,mtime,ctime)=os.stat(pathfile)
#			ctime=os.path.getctime(pathfile)
			(day,mth,dd,hh_mm_ss,yyyy ) = time.ctime(ctime).split()
			startdate="{}-{}-{}".format(yyyy,mth,dd)
			starttime="{}".format(hh_mm_ss)
		else: 
			path=""
			base=""
			file=""
			ext=""
			ctime=""
			startdate="1900-01-01"
			starttime="00:00:01"

		enddate=startdate
		endtime=starttime

#		print( "BUGS_740 j={} line={}=".format(j,line))
#		print( "BUGS_741 path={} file={} ext={} startdate={} starttime={}".format(path,file,ext,startdate,starttime))

		if( re.match('.txt$',pathfile)):
			if( os.isfile(ifile)):
				content = open( ifile, "rb").readlines() 
				print( "BUGS_750 pathfile={} content={}".format(pathfile,content))
		id="id"
		avid=id
		bkid=id
		tlid=id
		dttm=kodts('')
		status=""
		grp=path
		headline="headline: {} j={} id={} grp={} path={} file={} ext={}".format(dttm,j,id,grp,path,file,ext)
		text="text: {} id={} grp={} path={} file={} ext={}".format(dttm,id,grp,path,file,ext)
		media=pathfile
		caption=pathfile
		credit="<a href=/ target=_blank><img src=/imgs/btn/koeye.png height=20></a>"
		temp="temp"

		

		flds=""
		flds += "'avid',"
		flds += "'dttm',"
		flds += "'status',"
		flds += "'grp',"
		flds += "'pathfile',"
		flds += "'path',"
		flds += "'file',"
		flds += "'ext',"
		flds += "'startdate',"
		flds += "'starttime',"
		flds += "'enddate',"
		flds += "'endtime',"
		flds += "'headline',"
		flds += "'text',"
		flds += "'media',"
		flds += "'caption',"
		flds += "'credit',"
#		flds += "'title',"
#		flds += "'subject',"
#		flds += "'content',"
		flds += "'temp'"

		flds_bind="?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?"
#		flds_bind="?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?"
		fields=flds.split(",")
		

		vals=""
		vals += "'{}',".format(avid)
		vals += "'{}',".format(dttm)
		vals += "'{}',".format(status)
		vals += "'{}',".format(grp)
		vals += "'{}',".format(pathfile)
		vals += "'{}',".format(path)
		vals += "'{}',".format(file)
		vals += "'{}',".format(ext)
		vals += "'{}',".format(startdate)
		vals += "'{}',".format(starttime)
		vals += "'{}',".format(enddate)
		vals += "'{}',".format(endtime)
		vals += "'{}',".format(headline)
		vals += "'{}',".format(text)
		vals += "'{}',".format(media)
		vals += "'{}',".format(caption)
		vals += "'{}',".format(credit)
#		vals += "'{}',".format(title)
#		vals += "'{}',".format(subject)
#		vals += "'{}',".format(content)
		vals += "'{}'".format(temp)

		values = vals.split(",")
		sql_insert="insert or replace into {} ( {} ) values ( {} );".format(tbl,flds,vals)
		sql_insert_bind="insert or replace into {} ( {} ) values ( {} )".format(tbl,flds,flds_bind)

		sqlfil="{}.sql".format(progid)
		if( j == 0 ):
			fp=open(sqlfil,"w") 
		else:
			fp=open(sqlfil,"a")
		fp.write(sql_insert)
		fp.close()


	if(not os.path.isfile(db3file)):
		print( "ERR_861 NOTFOUND db3file={}".format(db3file))
		exit()

	if(not os.path.isfile(sqlfil)):
		print( "ERR_861 NOTFOUND sqlfil={}".format(sqlfil))
		exit()


	syscmd_db3_insert="sqlite3 {} < {}".format(db3file,sqlfil)
	print( "BUGS_860 syscmd_db3_insert={}".format(syscmd_db3_insert))
	os.system(syscmd_db3_insert)
	exit()



	bkid=id
	ofile=db3file.replace(".txt",".out")
	psvfil=ifile.replace(".txt",".psv")
	csvfil=ifile.replace(".txt",".csv")
	sqlfil=ifile.replace(".txt",".sql")
#	ifile=open( pathfile, "r" )
#	ofile=open( psvfil, "wb" )
#	fpo=open(sqlfil,"w")
#	fpo.write("-- ka1.py db3file={} ifile={} tbl={} id={}\n".format(db3file, ifile, tbl, id))
#	fpo.close()
#	limit=100

#	if( not os.path.isdir(ifile)): 
#		print( "BUGS_711 f2db3 NOT path.isdir ifile={} \n".format(ifile,ofile))
	if( not os.path.isfile(ifile)): 
		print( "BUGS_712 f2ftsdb3 NOT path.isfile ifile={} \n".format(ifile,ofile))
#	if( not os.path.exists(ifile)): 
#		print( "BUGS_713 f2ftsdb3 NOT path.exists ifile={} \n".format(ifile,ofile))

#	file="txt/txts.txt"
	j=0
	file = open( ifile, "rb").readlines() 
	for line in file:
		print( "BUGS_900 j={} line={}".format(j,line))

	exit()




	if(os.path.exists(ifile)):
		file = open( ifile, "rb").readlines() 
#		file = os.popen('cat {}'.format(ifile)).readlines()
#		file = open( ifile, "rb").read()
#		file_line = open( ifile, "rb").readline(limit) 
#		file_lines = open( ifile, "rb").readlines() 
#		file = open( filename, "r" )
#		print( file.read())
#		print( file.readline(100))
#		print( file.readlines())
		sql_create = ""
		sql_create += "create table if not exists {} ".format(tbl)
		sql_create += "as select * from files0"
		print( "BUGS_730 db3file={} sql_create={}\n".format(db3file,sql_create))
		if( os.path.isfile(db3file)):
			db3 = sqlite3.connect(db3file)
			db3.row_factory = sqlite3.Row
			cursor = db3.cursor()
			cursor.execute(sql_create)
			db3.close()

		htmout=""
		j=0
#		print( "BUGS_720 EXISTS ifile={}".format(ifile))
		for line in file:
			j=j+1
			pathfile=line.replace("\n","")
#			print("BUGS_735 j={} pathfile={}".format(j,line))
			if( not bkid ): bkid=""
			(path,base,file,ext)=("","","","")
			(mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime)= ("", "", "", "", "", "", "", "", "", "")
#			pathfile=pathfile.replace("/kb/","kb/",1)
#			pathfile=pathfile.replace("x","JK")
			if( os.path.isfile(pathfile)):
				path=os.path.dirname(pathfile)
				base=os.path.basename(pathfile)
				file=os.path.splitext(base)[0]
				ext=os.path.splitext(base)[1].replace(".","")
				(mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime) = os.stat(pathfile)
#				print( "BUGS_741 path={} base={} file={} ext={} pathfile={}".format(path,base,file,ext,pathfile))

#				file_time = dt.datetime.fromtimestamp(os.path.getmtime(__file__))
#				startdate=ctime.strftime("%Y-%m-%d")
#				starttime=ctime.strftime("%H:%M:%S")
#				startdt=ctime.strftime("%Y-%m-%d_%H:%M:$S")
#				ctime_fmt=ctime.strftime("%Y-%m-%d_%H:%M:$s")
#				ctime_fmt="{%Y-%m-%d}".format(ctime)
#				print("BUGS_750 ctime={} ctime_fmt={} startdate={} enddate={}\n".format(ctime,ctime_fmt,startdate,enddate))
				print( "BUGS_751 ____ISFILE j={} pathfile={} path={} file={} ext={} size={} ctime={}".format(j,pathfile,path,file,ext,size,ctime))
			else:
				print( "BUGS_752 NOT_ISFILE j={} pathfile={} path={} file={} ext={} size={} ctime={}".format(j,pathfile,path,file,ext,size,ctime))

			startdate="2022-01-24"
			starttime="00:00:01"
			enddate="2022-01-24"
			endtime="00:00:02"
			p=j
			ord=p
			headline="headline: bkid={} p={} tbl={}".format(bkid,p,tbl)
			text="text: bkid={} p={}".format(bkid,p)
			media=pathfile
			caption=pathfile
			credit="<img src=/imgs/btn/koeye.png>"
			avid=bkid

			flds = ""
			flds += "'{}',".format('dttm')
			flds += "'{}',".format('avid')
			flds += "'{}',".format('pathfile')
			flds += "'{}',".format('path')
			flds += "'{}',".format('file')
			flds += "'{}',".format('ext')
			flds += "'{}',".format('startdate')
			flds += "'{}',".format('starttime')
			flds += "'{}',".format('enddate')
			flds += "'{}',".format('endtime')
			flds += "'{}',".format('headline')
			flds += "'{}',".format('text')
			flds += "'{}',".format('media')
			flds += "'{}',".format('caption')
			flds += "'{}'".format('credit')

			fldvals = ""
			fldvals += "?,?,?,?,?,?,?,?,?,?,?,?,?,?,?"

			vals = ""
			vals += "'{}',".format(dttm)
			vals += "'{}',".format(bkid)
			vals += "'{}',".format(pathfile)
			vals += "'{}',".format(path)
			vals += "'{}',".format(file)
			vals += "'{}',".format(ext)
			vals += "'{}',".format(startdate)
			vals += "'{}',".format(starttime)
			vals += "'{}',".format(enddate)
			vals += "'{}',".format(endtime)
			vals += "'{}',".format(headline)
			vals += "'{}',".format(text)
			vals += "'{}',".format(media)
			vals += "'{}',".format(caption)
			vals += "'{}'".format(credit)

			values = vals.split(",")
			sql_insert = "insert or replace into {} ( {} ) values ( {} );".format( tbl, flds, vals )
			print( "BUGS_780 j={} tbl={} db3file={} sql_insert={}\n".format(j,tbl,db3file,sql_insert))

			fpo=open(sqlfil,"a")
#			fpo.write("{}\n".format(sql_insert))
			fpo.write("{}\n".format(sql_insert,values))
			fpo.close()
#
#	sql = ''' INSERT INTO tasks(name,priority,status_id,project_id,begin_date,end_date)
#	VALUES(?,?,?,?,?,?) '''
#	cur = conn.cursor()
#	cur.execute(sql, task)
#	conn.commit()
#	return cur.lastrowid

			db3 = sqlite3.connect(db3file)
			db3.row_factory = sqlite3.Row
			cursor = db3.cursor()
#			cursor.execute(sql_create)
#			cursor.execute(sql_insert)
			cursor.execute(sql_insert,values)
			db3.close()

		syscmd_delete="sqlite3 {} 'delete from {}'".format(db3file,tbl)
#		print( "BUGS_841 syscmd_delete={}\n".format(syscmd_delete ))
		out_outcnt=os.system(syscmd_delete)
#		print( "BUGS_841 syscmd_delete={}\n".format(syscmd_delete ))

		syscmd_insert="sqlite3 {} < {}".format(db3file,sqlfil)
		print( "BUGS_842 syscmd_insert={}\n".format(syscmd_insert ))
		out_insert=os.system(syscmd_insert)
		print( "BUGS_842 syscmd_insert={}\n".format(syscmd_insert ))

		syscmd_outcnt="sqlite3 {} 'select count(*) from {}'".format(db3file,tbl)
		print( "BUGS_842 syscmd_outcnt={}\n".format(syscmd_outcnt ))
		out_outcnt=os.system(syscmd_outcnt)
		print( "BUGS_842 syscmd_outcnt={}\n".format(syscmd_outcnt ))
		exit()


#		sql_select='''select * from {} limit {}'''.format(tbl,limit)
		sql_select="select * from {} limit {}".format(tbl,limit)
		print( "BUGS_793 f2db3 db3file={} sql_select={}\n".format(db3file,sql_select))
#		exit();



		db3 = sqlite3.connect(db3file)
		db3.row_factory = sqlite3.Row
		cursor = db3.cursor()
		cursor.execute(sql_select)
#		cursor.execute('''select bkid, ext,file,path,pathfile,startdate,enddate from {} limit {}'''.format(tbl,limit))

		osflag = ""
		j=0 
		htmout=""
		for row in cursor:
#	 		row['name'] returns the name column in the query, row['email'] returns email column.
			print('{0} {1} {2} {3} {4} {5} {6} {7} {8} {9} {10} {11} {12} {13}'.format(row['bkid'], row['pathfile'], row['path'], row['file'], row['ext'], row['size'], row['ctime'], row['ord'], row['headline'], row['text'], row['media'], row['caption'], row['credit'] ))
			bkid=row['bkid']
			p=row['ord']
			path=row['path']
			file=row['file']
			ext=row['ext']
			headline=row['headline']
			text=row['text']
			media=row['media']
			caption=row['caption']
			credit=row['credit']
			startdate=row['startdate']
			starttime=row['starttime']
			enddate=row['enddate']
			endtime=row['endtime']
	
#			htmout += "f2db3 file j={} line={}\n".format(j,line)
#			htmout += "mode={} gif={} size={} ctime={}\n".format(mode,gid,size,ctime)
#			htmout += "\n"
		return(htmout)
	return(htmout)



# def f2ftsdb3(db3file,ifile,tbl,id):
# def f2ftsdb3(db3file,datasrc,tbl,id,include_flag):
def f2ftsdb3(db3file,datasrc,tbl,id,sql_inserts,content_inserts):
	progid="ka1"
	dttm=kodts('')
	ifile=datasrc
#	print( "BUGS_1000 f2ftsdb3 db3file={} ifile={} tbl={} id={}\n".format(db3file,ifile,tbl,id));
	if( db3file == "" ):
		print( "ERR_1001 NOTFOUND db3file={}".format(db3file))
		exit()
	if( datasrc == "" ):
		print( "ERR_1002 {} {} NO_DATASRC datasrc={}".format(progid,dttm,datasrc))
		exit
	if( tbl == "" ):
		print( "ERR_1003 NO_TBL tbl={}".format(tbl))
		exit()
#	if( ifile == "" ):
#		print( "ERR_1004 NOTFOUND ifile={}".format(ifile))
#		exit()

	datasrc_len=len(datasrc.split(" "))
	if( datasrc_len == 1 ):
		pathfile=datasrc
		if(os.path.isfile(pathfile)):
			data = open(pathfile).readlines()
			datalen=len(data)
			j=0
			list=""
			for line in data:
				j=j+1
				newline=line
				newline=newline.replace("\n\r","")
				newline=newline.replace("\r","")
#				newline=newline.replace("\n","")
				list += newline
			listlen=len(list.split("\n"))
			print( "BUGS_1120 j={} datasrc={} listlen={} list=\n{}".format(j,datasrc,listlen,list))
			
	else:
		syscmd=datasrc
		(sysin,sysout,syserr)=os.popen3(syscmd)
		data=sysout
#		datalen=len(data)
		datalen=1
		if(datalen > 0):
			j=0
			(list,listlen)=("","")

			for line in data:
				j=j+1
				newline=line
				newline=newline.replace("\n\r","")
				newline=newline.replace("\r","")
#				newline=newline.replace("\n","")
				list += newline
			listlen=len(list.split("\n"))
#			print( "BUGS_1140 j={} datasrc={} listlen={} list={}".format(j,datasrc,listlen,list))
		else:
			print( "ERR_1141  NOLIST j={} datasrc={} listlen={} list={}".format(j,datasrc,listlen,list))
			exit()

#	print( "BUGS_1150 j={} listlen={} list={}".format(j,listlen,list))




#	(headline,text,media,caption,credit) = ("headline","text","media","caption","credit")
# python ka1.py f2db3 tl.db3 "find txt -name '???.txt'" kludge
	j=0
	listlen=len(list.split("\n"))
	for line in list.split("\n"):
#		print( "BUGS_1150 j={} line={}=".format(j,line))
		if( line == "" ): continue
		if( line == "\n" ): continue
		j=j+1
		pathfile=line
#		print( "BUGS_1165 j={} pathfile={}=".format(j,pathfile))
#		print( "BUGS_1166 j={} line={}=".format(j,line))
		dt=ko_dttm()
		path=os.path.dirname(pathfile)
		base=os.path.basename(pathfile)
		if( len(base.split(".")) > 1):
			file=base.split(".")[0]
			ext=base.split(".")[1].split(" ")[0]

		if( os.path.isfile(pathfile)):
#			path=os.path.dirname(pathfile)
#			base=os.path.basename(pathfile)
#			if( len(base.split(".")) > 1):
#				file=base.split(".")[0]
#				ext=base.split(".")[1]
#			ctime=os.path.getctime(pathfile)
			(mode,ino,dev,nlink,uid,gid,size,atime,mtime,ctime)=os.stat(pathfile)
			(day,mth,dd,hh_mm_ss,yyyy ) = time.ctime(ctime).split()
			startdate="{}-{}-{}".format(yyyy,mth,dd)
			starttime="{}".format(hh_mm_ss)
#			print( "BUGS_1181 ___FILE pathfile={} path={} file={} ext={} startdate={} starttime={}".format(pathfile,path,file,ext,startdate,starttime))
		else: 
#			path=""
#			base=""
#			file=""
#			ext=""
#			ctime=""
			dttm=kodts('')
			dt=dttm.replace("_"," ")
			startdate=dttm.split("_")[0]
			starttime=dttm.split("_")[1]
#			print( "BUGS_1182 NOTFILE pathfile={}=\n".format(j,line,path={} file={} ext={} startdate={} starttime={}".format(pathfile,path,file,ext,startdate,starttime))

		enddate=startdate
		endtime=starttime
		title="title: dt={} id={} tbl={} datasrc={} line={}".format(dt,id,tbl,datasrc,line)
		subject="subject: dt={} id={} tbl={} datasrc={} line={}".format(dt,id,tbl,datasrc,line)
		content="content: dt={} id={} tbl={} datasrc={} line={}".format(dt,id,tbl,datasrc,line)
		k=0
		i=0
		print( "BUGS_1200 pathfile={} path={} file={} ext={} startdate={} starttime={}".format(pathfile,path,file,ext,startdate,starttime))

		if( not usrcmd == "g" ): usrcmd=raw_input("PNGS_prompt: ")
		if( usrcmd == "q"):exit()
		if( usrcmd == "s"):continue
		if( usrcmd == "g"):continue

#		pathfile=pathfile.replace("\n","")
		if( re.search(".txt$",pathfile)) and ( content_inserts != ""): 
			if( os.path.isfile(pathfile)):
#				print( "BUGS_1200 ISFILE pathfile={}".format(pathfile))
				content=""
				content_raw = ""
				content_raw = open( pathfile, "rb").readlines() 
#				print( "BUGS_1212 pathfile={} content={} content_raw={}".format(pathfile,content,content_raw))
				(k,i,txt,ch)=(0,0,"","")
				content=""
				text=""
				txt=""
				for line in content_raw:
					k=k+1
					text=line
					text = re.sub('\n\r','',text)
					text = re.sub('\r','',text)
					text = re.sub('[?!@#]','=x<br>',text)
					text = re.sub('\n','',text)

					content+=text
#					print( "\n\nBUGS_1230 k={} text={}=\nline={}=\ncontent={}=".format(k,text,line,content))



#					string_unicode = string.replace("u'", "'")
#					string_unicode = " Python is easy \u200c to learn. "
#					string_encode = string_unicode.encode("ascii", "ignore")
#					string_decode = string_encode.decode()
#					print(string_decode)
#					content += line.strip('[?!@#]')
#					content += content.strip('[!@#]')
#					content=re.sub("[^a-zA-Z0-9 ]","",content_raw)
#					content=re.sub("[^a-zA-Z0-9 ]","",content_raw)
#					print( "BUGS_1240 j={} k={}= i={}= text={}= ch={}= line={}=\n pathfile={}".format(j,k,i,text,ch,line,pathfile))
#					print( "BUGS_1241 j={} k={} i={} content={}".format(j,k,i,content))

					i=0
#					for ch in line:
#						i=i+1
##						print( "BUGS_1182 j={} k={}= i={}= text={}= ch={}= line={}=\n pathfile={}".format(j,k,i,text,ch,line,pathfile))
#						if(ch.isalnum()):
##							print( "BUGS_1183 j={} k={}= i={}= txt={}= ch={}= line={}=\n pathfile={}".format(j,k,i,txt,ch,line,pathfile))
#							txt += ch
#							content += ch
##						print( "BUGS_1184 j={} k={}= i={}= text={}= ch={}= line={}=\n pathfile={}".format(j,k,i,text,ch,line,pathfile))
#					print( "BUGS_1185 j={} k={} i={} txt={} ch={} line={}= pathfile={} content={}".format(j,k,i,txt,ch,line,pathfile,content))

#				if( content == "" ): 
#					print( "BUGS_1201 .TXT NOCONTENT j={} k={} i={} txt={} ch={} line={}= pathfile={} content={}".format(j,k,i,txt,ch,line,pathfile,content))
#					exit()


				sql_update_content=""
				sql_update_content+="update {} ".format(tbl)
				sql_update_content+= "set content='{}' ".format(content)
				sql_update_content+= "where pathfile = '{}';\n".format(pathfile)
				sqlfil_content="{}_update.sql".format(progid)
				if( j==1):
					fp.open(sqlfil_content,"w")
				else:
					fp.open(sqlfil_content,"a")
				fb.write(sql_update_content)
				fp.close()

#				print( "BUGS_1202 CONTENT j={} k={} i={} txt={} ch={} line={}= pathfile={} content={}".format(j,k,i,txt,ch,line,pathfile,content))
#				print( "BUGS_1203 pathfile={} content={}".format(pathfile,content))
			else:
				print( "BUGS_1264 NOT ISFILE pathfile={}".format(pathfile))
#		else:
#			print( "BUGS_1265 NOTTXT pathfile={}=".format(pathfile))

#		print( "BUGS_1301 j={} k={} i={} pathfile={}=".format(j,k,i,pathfile))
		print( "BUGS_1300 j={} k={} i={} content={}=".format(j,k,i,content))

		id="id"
		avid=id
		bkid=id
		tlid=id
		dttm=kodts('')
		status=""
		grp=path
		title="title: {} j={} id={} grp={} path={} file={} ext={}".format(dttm,j,id,grp,path,file,ext)
		subject="subject: {} id={} grp={} path={} file={} ext={}".format(dttm,id,grp,path,file,ext)
		tmp="tmp"
		

		flds=""
		flds += "'id',"
		flds += "'status',"
		flds += "'grp',"
		flds += "'title',"
		flds += "'subject',"
		flds += "'dt',"
		flds += "'startdate',"
		flds += "'starttime',"
		flds += "'enddate',"
		flds += "'endtime',"
		flds += "'pathfile',"
		flds += "'path',"
		flds += "'file',"
		flds += "'ext',"
		flds += "'tmp',"
		flds += "'content'"

		flds_bind="?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?"
		fields=flds.split(",")
		

		vals=""
		vals += "'{}',".format(id)
		vals += "'{}',".format(status)
		vals += "'{}',".format(grp)
		vals += "'{}',".format(title)
		vals += "'{}',".format(subject)
		vals += "'{}',".format(dt)
		vals += "'{}',".format(startdate)
		vals += "'{}',".format(starttime)
		vals += "'{}',".format(enddate)
		vals += "'{}',".format(endtime)
		vals += "'{}',".format(pathfile)
		vals += "'{}',".format(path)
		vals += "'{}',".format(file)
		vals += "'{}',".format(ext)
		vals += "'{}',".format(tmp)
		vals += "'{}'".format(content)

		values = vals.split(",")
		sql_insert="insert or replace into {} ( {} ) values ( {} );".format(tbl,flds,vals)
		sql_insert_bind="insert or replace into {} ( {} ) values ( {} )".format(tbl,flds,flds_bind)

		sqlfil="{}.sql".format(progid)
		if( j == 1 ):
#			print( "BUGS_1230 J=0 j={} sqlfil={}".format(j,sqlfil))
			fp=open(sqlfil,"w") 
		else:
#			print( "BUGS_1231 J!=0 j={} sqlfil={}".format(j,sqlfil))
			fp=open(sqlfil,"a")
		fp.write(sql_insert+"\n")
		fp.close()


	if(not os.path.isfile(db3file)):
		print( "ERR_861 NOTFOUND db3file={}".format(db3file))
		exit()

	if(not os.path.isfile(sqlfil)):
		print( "ERR_861 NOTFOUND sqlfil={}".format(sqlfil))
		exit()


	syscmd_db3_insert="sqlite3 {} < {}".format(db3file,sqlfil)
	print( "BUGS_1350 syscmd_db3_insert={}".format(syscmd_db3_insert))
	if( sql_inserts != "" ):
		print( "MSG_1400 sql_inserts={} syscmd_db3_insert={}".format(sql_inserts,syscmd_db3_inserts))
		os.system(syscmd_db3_insert)
	print( "MSG_1401 sql_inserts={} syscmd_db3_insert={}".format(sql_inserts,syscmd_db3_insert))
	print( "MSG_1402 content_inserts={} syscmd_db3_insert={}".format(content_inserts,syscmd_db3_inserts))
	exit()



## new_string = old_string.translate({ord('?'):None})
# https://pythonguides.com/remove-unicode-characters-in-python/

## importing RegEx module
#import re
## take list
#my_list = ['@know*', 'pr#ogra!m^', '(py_th@on_3}']
## using regular expression to remove special characters
#out_list = [re.sub(r'[^a-zA-Z0-9]','',string) for string in my_list]

# my_list = ['@know*', 'pr#ogra!m^', '(py_th@on_3}']
# initializing special characters
# special_char = '@_!#$%^&*()<>?/\|}{~:;.[]'
# using join() + generator to remove special characters
# out_list = [''.join(x for x in string if not x in special_char) for string in my_list]

# using filter() to remove special characters
# out_list = [''.join(filter(str.isalnum, string)) for string in my_list]

# df = pd.read_csv('../data/csv/file_utf-16.csv', encoding='utf-16')
# with open('../data/csv/file_utf-16.csv') as f: print(f)

## convert .py .exe
## pyinstaller --onefile --noconsole -icon myiconfile.ico mypythonfile.py

def f2ftsdb3_content(db3file,tbl,sql_select):
	progid="ka1"
	dttm=kodts('')
#	print( "BUGS_1400 f2ftsdb3 db3file={} tbl={} sql_select={}\n".format(db3file,tbl,sql_select));
	if( db3file == "" ):
		print( "ERR_1401 NOTFOUND db3file={}".format(db3file))
		exit()
	if( tbl == "" ):
		print( "ERR_1403 NO_TBL tbl={}".format(tbl))
		exit()

#	if( sql_select == "" ):
	rowid=sql_select
	sql_select = ""
	sql_select += "select rowid,pathfile from {} ".format(tbl)
#	sql_select += "where pathfile != '' and content == '' and rowid == {}".format(rowid)
	sql_select += "where pathfile != '' and rowid == {}".format(rowid)
	print( "BUGS_1410 {} {} DEFAULT_SQL_SELECT sql_select={}".format(progid,dttm,sql_select))

#	if( ifile == "" ):
#		print( "ERR_1004 NOTFOUND ifile={}".format(ifile))
#		exit()

##	rowid=sql_select
##	rowid=20
##	sql_select="select rowid,pathfile from bks_v where rowid={}".format(rowid)
##	print( "BUGS_1415 rowid={} sql_select={}".format(rowid,sql_select))
#	exit()
#	sql_select="select rowid,pathfile from bks_v where rowid=1"
#	sql_select="select rowid,pathfile from bks_v where rowid=2"

	db3 = sqlite3.connect(db3file)
	db3.row_factory = sqlite3.Row
	cursor = db3.cursor()
	cursor.execute(sql_select)
	rows = cursor.fetchall()
	j=0
	k=0
	content=""
	usrcmd=""
	for row in rows:
		j=j+1
		rowid=row[0]
		pathfile=row[1]
		print( "BUGS_1420 db3_select j={} rowid={} pathfile={}".format(j,rowid,pathfile))
		k=0
#		for fld in row:
#			k=k+1
#			if( fld == "" ): continue
#			print( "BUGS_1421 f2ftsdb3_content db3_select j={} k={} fld={}".format(j,k,fld))
		if( not os.path.isfile(pathfile)):
			print( "BUGS_1423 f2ftsdb3_content NOTFILE j={} k={} pathfile={}".format(j,k,pathfile))
			continue

#		with open(pathfile,'r',errors='replace') as f:
#			lines = f.readlines()
#		lines = open(pathfile).readlines().decode('ISO-8859-1')
#		lines = open(pathfile).readlines().decode('cp1252')
#		lines = open(pathfile).readlines().decode('utf16')
#		lines = open(pathfile).readlines().decode('utf8')
#		lines = open(pathfile).readlines().decode('utf8')
		lines = open(pathfile).readlines()


#		lines_ascii = lines.encode("ascii","ignore")
#		lines_utf8 = lines.encode("utf8","ignore")
#		lines_utf16 = lines.encode("utf16","ignore")
#		lines_cp1252 = lines.encode("cp1252","ignore")
#		lines_iso = lines.encode("ISO-8859-1","ignore")

#		string_unicode = string.replace("u'", "'")
#		string_unicode = " Python is easy \u200c to learn. "
#		string_encode = string_unicode.encode("ascii", "ignore")
#		string_decode = string_encode.decode()
#		line=lines[0]
#		line_encode = line.encode("ascii","ignore")
#		line_decode = line.decode()

		lineslen = len(lines)
#		print(type(lines))
		print("BUGS_1440 LINES j={} k={} lineslen={} lines={}=".format(j,k,lineslen,lines))
		print("BUGS_1441 LINES j={} k={} pathfile={} lineslen={}".format(j,k,pathfile,lineslen))
#		if( usrcmd != "" ):
#			print( "q=quit|e=exit|s=skip|g=go|enter=continue" )
#			usrcmd=raw_input("prompt: ")
#		if( usrcmd == "e"): exit()
#		if( usrcmd == "q"): exit()
#		if( usrcmd == "g"): usrcmd=""
#		if( usrcmd == "s"): continue
		j=0
		usrcmd=""
		content=""
		sqlfil="{}_content.sql".format(progid)
		for line in lines:
			j=j+1
#			print( "BUGS_1450 j={} line={}".format(j,line.replace("\n","")))
			newline=line
			newline = newline.replace("\r\n","")
			newline = newline.replace("\r","")
			newline = newline.replace("'","")
			newline = newline.replace('"','')
			newline = newline.replace('?','')
			newline = newline.replace('(','')
			newline = newline.replace(')','')
			newline = newline.replace('!','')
			newline = newline.replace('@','')
			newline = newline.replace('%','')
			newline = newline.replace('[','')
			newline = newline.replace(']','')
			content += newline

		print( "BUGS_1460 j={} content={}".format(j,content))
		sql_update = ""
		sql_update += "update {} ".format(tbl)
		sql_update += "set content = '{}' ".format(content)
		sql_update += " where pathfile = '{}';\n".format(pathfile)

		print( "BUGS_1470 j={} sql_update={}".format(j,sql_update))
		if( os.path.isfile(pathfile)):
			print( "BUGS_1472 ISFILE j={} rowid={} pathfile={}".format(j,rowid,pathfile))
		else:
			print( "BUGS_1473 NOFILE j={} rowid={} pathfile={}".format(j,rowid,pathfile))

#		print( "q=quit|s=skip|g=go ")
#		if( usrcmd != "g"): usrcmd=raw_input("prompt:  ")
#		if( re.match("e",usrcmd)): exit()
#		if( re.match("q",usrcmd)): exit()
#		if( re.match("s",usrcmd)): continue



#		if( j==1):
#			fp=open(sqlfil,"w")
#		else:
#			fp=open(sqlfil,"a")
		fp=open(sqlfil,"w")
		fp.write(sql_update)
		fp.close()

		syscmd_update = ""
		syscmd_update += "sqlite3 {} < {}".format(db3file,sqlfil)

		print( "BUGS_1461 f2ftsdb3_content db3file={} tbl={} sql_select={}".format(db3file,tbl,sql_select))
		status=os.system(syscmd_update)
		print( "BUGS_1462 f2ftsdb3_content db3file={} tbl={} sql_select={}".format(db3file,tbl,sql_select))
	print( "BUGS_1462 f2ftsdb3_content db3file={} tbl={} sql_select={}".format(db3file,tbl,sql_select))
	exit()

#	datasrc_len=len(datasrc.split(" "))
#	if( datasrc_len == 1 ):
#		pathfile=datasrc
#		if(os.path.isfile(pathfile)):
#			data = open(pathfile).readlines()
#			datalen=len(data)
#			j=0
#			list=""
#			for line in data:
#				j=j+1
##				newline=line
#				newline=newline.replace("\n\r","")

def string_cleanup(x, notwanted):

# Get rid of html elements
	html_elements = ["<title>", "</title>", "<strong>", "</strong>"]
	line = string_cleanup(line, html_elements)
	print("1st clean: ", line)

# Get rid of special characters
	special_chars = ["[!@#$]", "%"]
	line = string_cleanup(line, special_chars)
	print("2nd clean: ", line)


	for item in notwanted:
		x = re.sub(item, '', x)
	return x

	line = "<title>My example: <strong>A text %very% $clean!!</strong></title>"
	print("Uncleaned: ", line)

# Get rid of html elements
	html_elements = ["<title>", "</title>", "<strong>", "</strong>"]
	line = string_cleanup(line, html_elements)
	print("1st clean: ", line)

# Get rid of special characters
	special_chars = ["[!@#$]", "%"]
	line = string_cleanup(line, special_chars)
	print("2nd clean: ", line)




def stripchars(content_raw):
#	print( "BUGS_1281 content_raw={}".format(content_raw))

#	print [re.sub('[^a-zA-Z0-9]+', '', _) for _ in content_raw]
#	content = [re.sub('[^a-zA-Z0-9]+', '_XYZ_', _) for _ in content_raw]


#	print( type(content_raw))
#	content_new = content_raw.encode("ascii","ignore")
#	print( "BUGS_1282 content_new={}".format(content_new))
#	content=content_new.decode()
#	print( "BUGS_1283 content={}".format(content))
	exit()
	return(content)
	content=""
	j=0
	for line in content_raw:
		j=j+1
		line=line.replace("\n","")
		linelen=len(line)
		if( line.isalnum()):
			print( "BUGS_1281 ISALNUM j={} line={}".format(j,line))
		else:
			print( "BUGS_1281 NOT_ISALNUM j={} line={}".format(j,line))
		print( "BUGS_1281 j={} len={} line={}".format(j,linelen,line))
	exit()
	return(content)

def find(string):
#	symbols = {'`','~','!','@','#','$','%','^','&','*','(',')','_','-','+','=','{','[','}','}','|','\',':',';','"',''','<',',','>','.','?','/'}

# from string import punctuation
# set(punctuation)
# {'~', ':', "'", '+', '[', '\\', '@', '^', '{', '%', '(', '-', '"', '*', '|', ',', '&', '<', '`', '}', '.', '_', '=', ']', '!', '>', ';', '?', '#', '$', ')', '/'}
# `''' `,~,!,@,#,$,%,^,&,*,(,),_,-,+,=,{,[,},},|,\,:,;,",',<,,,>,.,?,/'''`

	special_char=re.compile('[@_!$%^&*()<>?/\|}{~:]#')
	if special_char.search(string) == None:
		return "string is accepted"
	else:
	        return "string not accpeted"
   
def db3s_update(to_db3file,to_tbl,db3s_todos):
	print( "BUGS_1640 db3s_update to_db3file={} to_tbl={} db3s_todos={}".format(to_db3file,to_tbl,db3s_todos))
	(syscmd,sql_select,db3files,db3files_len,pathfiles)=("","","","","")


#	if( re.search('f',to_db3file)) or ( to_db3file == '') or (to_db3file == 'find'):
#	if( re.search('f',to_db3file)) or ( to_db3file != '') or (to_db3file == 'find'):
#	if( db3s_todos == "" ): to_db3file="select"
	print( "BUGS_1745 to_db3file={} db3s_todos={}".format(db3s_todos,to_db3file))
	if( re.search('f',to_db3file)) or (to_db3file == "" ):
		to_db3file="tl.db3"
		to_tbl="db3s"
		syscmd='find . -type f -maxdepth 2 -name "*.db3"'
		print( "BUGS_1650 FIND to_db3file{} to_tbl={} db3s_todos={} syscmd={}".format(to_db3file,to_tbl,db3s_todos,syscmd))
#		db3s_todos=os.system(syscmd)

		(out,err)=kosys(syscmd,'brief')
		pathfiles=out
		db3files=out.split("\n")
#		print( "BUGS_1654 out={} err={}".format(out,err))
#		print("BUGS_1645 db3s={} ".format(db3s))
#		print("BUGS_1640 syscmd={} db3s_todos={} db3s={} db3s_len={}".format(syscmd,db3s_todos,db3s,db3s_len))
#		print("BUGS_1659 FIND db3s_todos={}".format(db3s_todos))

#	if( re.search('s',to_db3file)) or ( to_db3file == '') or (to_db3file == 'select'):
	if( re.search('s',to_db3file )) or ( to_db3file==""):
		to_db3file="tl.db3"
		print( "BUGS_1760 SELECT to_db3file={}".format(to_db3file))
		to_tbl="db3s"
		tbl="tbl"
		sql_select="select pathfile from {} limit 5".format(to_tbl)
		if( not os.path.exists(to_db3file)):	
			print("ERR_1641 db3s NOT_ISFILE to_db3file={} to_tbl={} db3files={} db3files_len={}".format(to_db3file,to_tbl, db3files, db3files_len))
			exit
		print( "BUGS_1775 SELECT sql_select={}\n".format(sql_select))
		sql3 = sqlite3.connect(to_db3file)
		sql3.row_factory = sqlite3.Row
		rows = sql3.cursor()
		rows.execute(sql_select)
		(pathfiles,j)=("",0)
		db3files=()
		for row in rows:
			pathfile=row['pathfile']
			pathfiles += pathfile	
			db3file=pathfile
			db3files = db3file
			j=j+1
			print("BUGS_1850 db3s ROW j={} to_db3file={} db3file={}".format(j,to_db3file,db3file ))
		sql3.close()

		db3files=pathfiles.split("\n")
#		db3files_len=len(db3s)
#		print("BUGS_1860 db3s to_db3file={} to_tbl={} db3s={}".format(to_db3file,to_tbl, db3files))

	pathfiles_len=len(pathfiles)
	db3files_len=len(db3files)
	print( "BUGS_1866 pathfiles_len={} db3files_len={}\n".format(pathfiles_len,db3files_len))
	if( db3files_len == 0 ):		
		print( "ERR_1810 NOTFOUND db3s db3files_len={}".format(db3files_len))
		exit()
#	print( "MSG_1871 FOUND db3s db3files={}".format(db3files))
	print( "MSG_1872 FOUND db3s db3files_len={}".format(db3files_len))
	print( "MSG_1873 FOUND db3s pathfiles_len={}".format(pathfiles_len))

	j=0
	schema=""
	cnt=""
	print( "BUGS_1877 to_db3file={} to_tbl={}\n".format(to_db3file,to_tbl))
	for db3file in db3files:
		if( db3file == "" ): continue
		if( db3file == "./dgs.db3"): continue
		if( db3file == './dp/dp759.db3'): continue

		(tbl,cnt,schema)=("tbl",-1,"schema")
		j=j+1
		print( "BUGS_1880 j={} db3file={} tbl={} cnt={} schema={}\n".format(j,db3file,tbl,cnt,schema))
#		(tbl,cnt,schema)=sql3_selects(db3file,sql_select)
		tbls=sql3_select_tbls(db3file,sql_select)
		k=0

		print( "BUGS_1881 k={} tbl2={}".format(k,tbls))
		progid="ka1.py"
		for tbl in tbls.split("\n"):
			j=j+1
			if( re.search("v_",tbl)): continue
			if( re.search("_v",tbl)): continue
			if( re.search("ko_temp",tbl)): continue
			if( re.search("COLUMNS",tbl)): continue
			if( re.search("AdminLog",tbl)): continue
			if( re.search("Adminlog",tbl)): continue
			if( re.search("Bio",tbl)): continue
			if( re.search("Bulletin",tbl)): continue
			if( re.search("Clock",tbl)): continue
			if( re.search("ConfigBoard",tbl)): continue
			if( re.search("ConfigPages",tbl)): continue
			if( re.search("Contacts",tbl)): continue
			if( re.search("Contribution",tbl)): continue
			if( re.search("Errorlog",tbl)): continue
			if( re.search("FAQ",tbl)): continue
			if( re.search("Feature",tbl)): continue
			if( re.search("Folders",tbl)): continue
			if( re.search("Forumlog",tbl)): continue
			if( re.search("Forumreads",tbl)): continue
			if( re.search("Forums",tbl)): continue
			if( re.search("GameInvitation",tbl)): continue
			if( re.search("GamePlayers",tbl)): continue
				
			dttm=kodts('dttm')
#			print( "BUGS_1881 k={} tbl={}".format(k,tbl))
			(tbl,cnt,schema)=sql3_tblinfo(db3file,tbl)
			media=db3file
			sql_insert=""
			sql_insert+="insert into {} (progid,dttm,pathfile,t1,assets,media)".format(to_tbl)
			sql_insert+="values('{}','{}','{}','{}','{}','{}');".format(progid,dttm,tbl,cnt,schema,media)
			print( "BUGS_1898 j={} k={} to_db3file={} sql_insert={}".format(j,k,to_db3file,sql_insert))
			status=sql3_executes(to_db3file,sql_insert)


			sqlfil = open("ka1.sql","w")
			sqlfil.write("{} -- {}\n".format(sql_insert,db3file))
			sqlfil.close()
#			print( "BUGS_1899 status={} to_db3file={} sql_insert={}".format(status,to_db3file,sql_insert))
			k=k+1

		print( "BUGS_1891 tbls={}".format(tbls))
		print( "BUGS_1892 j={} db3file={} tbl={} cnt={} schema={}\n".format(j,db3file,tbl,cnt,schema))

	print("BUGS_1899 EXIT  db3files_len={} syscmd={} sql_select={}".format(db3files_len,syscmd,sql_select))
	exit()

def sql3_tblinfo(db3file,tbl):
	print( "BUGS_1900 sql_tblinfo db3file={} tbl={}\n".format(db3file,tbl))
#	(cnt,schema)=(123,'create table tbl (fld1 text,fld2 text)')
	(cnt,schema)=("","")
	if( db3file == "" ):
		print( "ERR_1901 NO_DB3FILE db3file={}".format(db3file))
		return(tbl,cnt,schema)
	if( tbl == "" ):
		print( "ERR_1901 NO_TBL tbl={}".format(tbl))
		return(tbl,cnt,schema)
	if( not os.path.exists(db3file)):
		print( "ERR_1901 NOFOUND_DB3FILE db3file={}".format(db3file))
		return(tbl,cnt,schema)

	cnt=0 
	sql3 = sqlite3.connect(db3file)
	sql3.row_factory = sqlite3.Row
	rows = sql3.cursor()
	sql_select="select count(*) cnt from {}".format(tbl)
#	rows.execute("select count(*) cnt from {}".format(tbl))
	rows.execute(sql_select)
	for  row in rows:
		cnt=row['cnt']
	sql3.close()

	schema=""
	sql3 = sqlite3.connect(db3file)
	sql3.row_factory = sqlite3.Row
	rows = sql3.cursor()
	rows.execute("select sql from sqlite_master where name == '{}' and type=='table'".format(tbl))
	for row in rows:
		schema=row['sql']
		schema=schema.replace("\n","").lower().replace("  "," ").replace("\t","")
	sql3.close()
	return(tbl,cnt,schema)


def ftsdb3(db3file,ifile,tbl,id):
#	print( "BUGS_1925 f2ftsdb3 db3file={} ifile={} tbl={} id={}\n".format(db3file,ifile,tbl,id));
	ofile=db3file.replace(".txt",".out")
	psvfil=ifile.replace(".txt",".psv")
	csvfil=ifile.replace(".txt",".csv")
	sqlfil=ifile.replace(".txt",".sql")

#	ifile=open( pathfile, "r" )
#	ofile=open( psvfil, "wb" )
#	print( "BUGS_915 f2ftsdb3 ifile={} ofile={}".format(ifile,ofile))
	limit=100

#	if not os.path.isdir(ifile): os.system(syscmd)
	if( not os.path.isdir(ifile)): 
		print( "BUGS_811 f2ftsdb3 NOT path.isdir ifile={}".format(ifile,ofile))
	if( not os.path.exists(ifile)): 
		print( "BUGS_811 f2ftsdb3 NOT path.exists ifile={}".format(ifile,ofile))

#	db3_drop(db3file,tbl)

	db3_create_v(db3file,tbl)


#	tbl0=""
#	print( "BUGS_932 ftsdb3 db3file={} tbl={} \n".format(db3file,tbl))
#	db3_create(db3file,sql_create,tbl,tbl0)
#	return(db3file)	


	sql_delete=""
	rowid=""
#	db3_delete(db3file,sql_delete,tbl,rowid)

	values=""
	ifile=""
	sql_insert=""
#	print( "BUGS_941 db3file={} tbl={} sql_insert={} values={} ifile={} id={}".format( db3file,tbl,sql_insert,values,ifile,id))
	db3_insert(db3file,tbl,sql_insert,values,ifile,id)

#	print( "BUGS_951 db3file={} tbl={} sql_insert={} values={} ifile={} id={}".format( db3file,tbl,sql_insert,values,ifile,id))
	sql_update=""
	db3_update(db3file,sql_update,tbl)
#	print( "BUGS_952 db3file={} tbl={} sql_insert={} values={} ifile={} id={}".format( db3file,tbl,sql_insert,values,ifile,id))


	if( tbl == "" ):
		print( "BUGS_950 NO_TBL tbl={}".tbl )
		exit

	(fld,val,rowid,limit) = ("","","",123)
	sql_select="select * from {} limit {}".format(tbl,limit)
	db3_select(db3file,sql_select,tbl,fld,val,rowid,limit)
	print( "BUGS_1003 sql_select={}\n".format(sql_select))

#	db3_insert(db3file,sql_update,tbl)
#	db3_delete(db3file,sql_delete,tbl,rowid)
#	db3_select(db3file,sql_select,tbl,limit)

#	print( "BUGS_1001 sql_insert={}\n".format(sql_insert))
#	print( "BUGS_1002 sql_update={}\n".format(sql_update))
#	print( "BUGS_1003 sql_delete={}\n".format(sql_delete))
#	print( "BUGS_1003 sql_drop={}\n".format(sql_drop))
	return(db3file);
	exit()





	htmout=""
	j=0
#	print( "BUGS_720 EXISTS ifile={}".format(ifile))
	for line in file:
		j=j+1
		pathfile=line.replace("\n","")
#		print("BUGS_735 j={} pathfile={}".format(j,line))
		if( not bkid ): bkid=""
		(path,base,file,ext)=("","","","")
		(mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime)= ("", "", "", "", "", "", "", "", "", "")
#		pathfile=pathfile.replace("/kb/","kb/",1)
#		pathfile=pathfile.replace("x","JK")


		if(os.path.exists(ifile)):
			file = open( ifile, "rb").read()
			file_line = open( ifile, "rb").readline(limit) 
			file_lines = open( ifile, "rb").readlines() 
#			file = open( filename, "r" )
#			print( file.read())
#			print( file.readline(100))
#			print( file.readlines())

			j=0
			for line in file:
				j=j+1
				htmout += "f2ftsdb3 file______ j={} line={}\n".format(j,line)
	

			j=0;
			for line in file_line:
				j=j+1
				htmout += "f2ftsdb3 file_line_ j={} line={}\n".format(j,line)
			j=0
			for line in file_lines:
				j=j+1
				htmout += "f2ftsdb3 file_lines j={} line={}\n".format(j,line)
			return(htmout)
		return(htmout)


	htmout=""
	j=0
	for line in file:
		j=j+1
		pathfile=line
#		if re.search( "</head>", line ): f_new.write( "	-->\n\n" )
		print( "BUGS_702 j={} line={}".format(j,line))
		htmout += "{}|{}\n".fornat(j,line)

#		ofile.write( oline )
#		if re.search( match_beg, line ):
#			ofile.write( oline )

	return(htmout)

def db3_create(db3file,sql_create,tbl,tbl0):
	if(( tbl != "" ) and ( tbl0 != "" )):
		sql_create = ""
		sql_create += "create table if not exists {} ".format(tbl)
		sql_create += "as select * from {} limit 1".format(tbl0)
		print( "BUGS_1000 sql_create db3file={} tbl={} sql_create={}".format(db3file,tbl,sql_create))

	if( sql_create == "" ):
		print( "BUGS_1000 sql_create NULL sql_create={}\n".format(sql_create))
		return(sql_create)

	print( "BUGS_1000 sql_create sql_create={}\n".format(sql_create))
	db3 = sqlite3.connect(db3file)
	db3.row_factory = sqlite3.Row
	cursor = db3.cursor()
	cursor.execute(sql_create)
	db3.close()
	return(sql_create)

def db3_create_v(db3file,tbl):
	sql_create = ""
	sql_create += "create table if not exists {} ".format(tbl)
	sql_create += "as select * from files0"

	if( db3file == "" ): db3file="fts/fts.db3"
	if( tbl == "" ): tbl="fts"

	sql_create_v = ""
#	sql_create_v += "-- /fts.sql		20220126_1622\n"
#	sql_create_v += "-- fts/sql/fts.sql\n"
	sql_create_v += "create VIRTUAL TABLE if not exists {} ".format(tbl)
	sql_create_v += "USING fts3(\n"
	sql_create_v += "id text,\n"
	sql_create_v += "status text,\n"
	sql_create_v += "grp text,\n"
#	sql_create_v += "title text,\n"
#	sql_create_v += "subject text,\n"
#	sql_create_v += "title varchar(256) not null,\n"
#	sql_create_v += "subject varchar(256) not null,\n"
	sql_create_v += "title varchar(256),\n"
	sql_create_v += "subject varchar(256),\n"
	sql_create_v += "dt text,\n"
	sql_create_v += "startdate text,\n"
	sql_create_v += "starttime text,\n"
	sql_create_v += "enddate text,\n"
	sql_create_v += "endtime text,\n"
	sql_create_v += "pathfile text,\n"
	sql_create_v += "path text,\n"
	sql_create_v += "file text,\n"
	sql_create_v += "ext text,\n"
	sql_create_v += "tmp text,\n"
	sql_create_v += "content text check(length(body)<10240)\n"
	sql_create_v += "tokenize=simple en_AU\n"
	sql_create_v += ");"

#	print( "BUGS_1070 sql_create_v db3file={} tbl={} sql_create_\n{}\n".format(db3file,tbl,sql_create_v))
#	print( "BUGS_1075 db3file={} sql_create={}\n".format(db3file,sql_create))
	if( not os.path.isfile(db3file)): 
		print( "ERR_1079 NOT_ISFILE db3file={}".format(db3file))

	db3 = sqlite3.connect(db3file)
#	print( "BUGS_1085 sql_create_v db3file={} tbl={} sql_create={}\n".format(db3file,tbl,sql_create_v))
	db3.row_factory = sqlite3.Row
	cursor = db3.cursor()
	cursor.execute(sql_create_v)
	db3.close()
#	print( "BUGS_1090 sql_create_v db3file={} tbl={} sql_create_\n".format(db3file,tbl,sql_create_v))
	return(sql_create_v)



def db3_insert(db3file,tbl,sql_insert,values,ifile,id):
#	print( "BUGS_1020 sql_insert db3file={} tbl={} sql_insert={}\n".format(db3file,tbl,sql_insert))
	if( not sql_insert == "" ):
		print( "BUGS_1021 sql_insert ISSQL db3file={} tbl={} sql_insert={}\n".format(db3file,tbl,sql_insert))
		db3 = sqlite3.connect(db3file)
		db3.row_factory = sqlite3.Row
		cursor = db3.cursor()
#		cursor.execute(sql_insert)
		cursor.execute(sql_insert,values)
		db3.close()
		return(sql_insert)

	if( os.path.isfile(sql_insert)):
		ifile=sql_insert
		print( "BUGS_1021 sql_insert ISFILE db3file={} tbl={} ifile={}\n".format(db3file,tbl,ifile))
		return(sql_insert)



	sqlfil="ftsdb3.sql"
	fp=open(sqlfil,"w")
	fp.close()

	jlim=5
	for j in range(1,5):
		id="id_{}".format(j)
		status="status_{}".format(j)
		grp="grp_{}".format(j)
		title="title_{}".format(j)
		subject="subject_{}".format(j)
		dt=ko_dttm()
		startdate=ko_dttm()
		starttime=ko_dttm()
		enddate=ko_dttm()
		endtime=ko_dttm()
		pathfile="/imgs/btn/koeye.png"
		path="/imgs/btn/"
		file="koeye"
		ext="png"
		tmp="tmp_{}".format(j)
		content="content_{} id={} grp={} title={} subject={} dt={} pathfile={}".format(j,id,grp,title,subject,dt,pathfile)


		flds=""
		flds += "id,"
		flds += "status,"
		flds += "grp,"
		flds += "title,"
		flds += "subject,"
		flds += "dt,"
		flds += "startdate,"
		flds += "starttime,"
		flds += "enddate,"
		flds += "endtime,"
		flds += "pathfile,"
		flds += "path,"
		flds += "file,"
		flds += "ext,"
		flds += "tmp,"
		flds += "content"
		fields = flds.split(",")
	
		fldvals = "?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?"
	
	
		vals = ""
		vals += "'{}',".format(id)
		vals += "'{}',".format(status)
		vals += "'{}',".format(grp)
		vals += "'{}',".format(title)
		vals += "'{}',".format(subject)
		vals += "'{}',".format(dt)
		vals += "'{}',".format(startdate)
		vals += "'{}',".format(starttime)
		vals += "'{}',".format(enddate)
		vals += "'{}',".format(endtime)
		vals += "'{}',".format(pathfile)
		vals += "'{}',".format(path)
		vals += "'{}',".format(file)
		vals += "'{}',".format(ext)
		vals += "'{}',".format(tmp)
		vals += "'{}'".format(content)
		values=vals.split(",")
		values_len=len(values)

#		for j in range(0, values_len):
#			print( "BUGS_1181 j={} values={}".format(j,values[j]))


#		print( "BUGS_1180 vals={}\n".format(vals))
		j=0
		for value in values:
			j=j+1
#			print( "BUGS_1750 j={} value={}".format(j,value))
	
		sql_insert_bind = "insert into {} ( {} ) values ( {} )".format( tbl, flds,fldvals )
		sql_insert = "insert into {} ( {} ) values ( {} );".format( tbl, flds,vals )
		fp=open(sqlfil,"a")
		fp.write(sql_insert+"\n")
		fp.close()

#		print( "BUGS_1750 j={} values_len={} db3file={} sql_insert=\n{}\n".format(j,values_len,db3file,sql_insert))

		db3 = sqlite3.connect(db3file)
		db3.row_factory = sqlite3.Row
		cursor = db3.cursor()
		cursor.execute(sql_insert)
#		cursor.execute(sql_insert_bind,values)
#		print( "BUGS_1189 j={} db3file={} sql_insert={}".format(j,db3file,sql_insert))
		db3.close()


	syscmd_db3_insert="sqlite3 {} < {}".format(db3file,sqlfil)
	os.system(syscmd_db3_insert)

#	print( "BUGS_1220 db3file={} sql_insert={}".format(j,db3file,sql_insert))
	return(sql_insert)

def db3_update(db3file,sql_update,tbl):
#	print( "BUGS_1225 db3_update db3file={} sql_update={} tbl={}\n".format(db3file,sql_update,tbl))
	dttm=kodts('')
	if( sql_update == "" ):
		title="title: dttm={} db3file={} sql_update={} tbl={}\n".format(dttm,db3file,sql_update,tbl)
		sql_update = ""
		sql_update += "update {} ".format(tbl)
		sql_update += "set title='{}'".format(title)
#		sql_update += "UPDATE {} SET title = "
#		sql_update += "'title_update: '||{}||'_'||{}||'_'||{}  WHERE rowid = {}".format(rowid,'date()','time()',rowid)


#	print( "BUGS_1230 db3_update db3file={} sql_update={} tbl={}\n".format(db3file,sql_update,tbl))

	db3 = sqlite3.connect(db3file)
	db3.row_factory = sqlite3.Row
	cursor = db3.cursor()
	cursor.execute(sql_update)
	db3.close()
	return(sql_update)


def db3_drop(db3file,tbl):
	if( tbl == "" ):
		print( "ERR_1790 NO_TBL db3file={} tbl={} sql_drop={} rowid={}\n".format(db3file,tbl))

	sql_drop = ""
	sql_drop += "drop table if exists {}".format(tbl)
	print( "BUGS_1042 sql_drop db3file={} tbl={} sql_drop={}\n".format(db3file,tbl,sql_drop))

	db3 = sqlite3.connect(db3file)
	db3.row_factory = sqlite3.Row
	cursor = db3.cursor()
	cursor.execute(sql_drop)
	db3.close()
	return(sql_drop)


def db3_delete(db3file,sql_delete,tbl,rowid):
	if( sql_delete == "" ) and ( tbl == "" ):
		print( "BUGS_1260 NO_TBL NO_SQL_DELETE" )
		exit()
	if( sql_delete == "" ):
		sql_delete = "delete from {};".format(tbl)
		if( rowid != "" ):
			sql_delete = "delete from {} where rowid={};".format(tbl,rowid)

	print( "BUGS_1260 sql_delete db3file={} sql_delete={} tbl={} rowid={}\n".format(db3file,sql_delete,tbl,rowid))

	db3 = sqlite3.connect(db3file)
	db3.row_factory = sqlite3.Row
	cursor = db3.cursor()
	cursor.execute(sql_delete)
	db3.close()
	return(sql_delete)


def db3_select(db3file,sql_select,tbl,fld,val,rowid,limit):
#	print( "BUGS_1280 db3_select db3file={} sql_select={} tbl={} fld={} val={} rowid={} limit={}".format(db3file,sql_select,tbl,fld,val,rowid,limit))

#	if( limit == "" ): limit=100
#	wheres = ""
#	fld="content"
#	val="matchterm"
#	wheres += "{} matches '{}'".format(fld,val)
	if( sql_select == "" ):
		sql_select = ""
		sql_select += "select * from {} ".format(tbl)
#		sql_select += "where {}".format(wheres)
		sql_select += "where {} like '{}' ".format(fld,val)
		if( limit > 0 ):
			sql_select += " limit {}".format(limit)

	print( "BUGS_1291 sql_select =========================" )
	print( "BUGS_1292 db3file={}".format(db3file))
	print( "BUGS_1293 sql_select={}".format(sql_select))
	print( "BUGS_1294 tbl={} limit={}".format(tbl,limit))
#	cursor.execute("SELECT * FROM tasks WHERE priority=?", (priority,))



	db3 = sqlite3.connect(db3file)
	db3.row_factory = sqlite3.Row
	cursor = db3.cursor()
	cursor.execute(sql_select)
	rows = cursor.fetchall()
	j=0
	k=0
	for row in rows:
		j=j+1
		print( "db3_select j={} row={}".format(j,row))
		for fld in row:
			k=k+1
			print( "db3_select j={} k={} fld={}".format(j,k,fld))








	db3.close()
	print( "BUGS_1239 sql_select db3file={} tbl={} sql_select={}\n".format(db3file,tbl,sql_select))
	return(sql_select)
# kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk


def load_lines_new(pathfiles):
	print( "{} {} load_lines_new:  pathfiles={}".format( progid,dttm, pathfiles))

#	for j in range(1,10):
#		print( "go_jsg j={}".format(j ))
#		if j == 5: continue
#		if j == 8: break



	print( "BUGS_380 pathfiles={}".format(pathfiles))

	lines_new=""	
	j=0
	for pathfile in pathfiles.split("\n"):
		j=j+1
		print( "BUGS_395 j={} pathfile={}=".format(j, pathfile))
		if( len( pathfile ) < 3 ): continue

		path=os.path.dirname(pathfile)
		base=os.path.basename(pathfile)
		file=os.path.splitext(base)[0]
		dotext=os.path.splitext(base)[1]
		ext=dotext.replace(".", "")
		code=file.replace(".", "_")
		print( "BUGS_400 ext={} dotext={}\n".format( ext, dotext ))

		b64_raw = ""

		if(os.path.isdir(path)):
			print( "{} {} FOUND_DIR j={} path={} ".format( progid,dttm, j, path ))
		if(os.path.exists(pathfile)):
			print( "{} {} FOUND_FILE j={} pathfile={} ".format( progid,dttm, j, pathfile ))
			b64_raw = base64.b64encode(open( pathfile, "rb").read()) 

#		print( "BUGS_410 {} {} j={} code={} pathfile={} b64_raw={}".format( progid,dttm, j, code, pathfile, b64_raw ))

		id="{}_{}".format( code, ext )

		b64_htm = ""
		print( "BUGS_415 ext={} dotext={}\n".format( ext, dotext ))
		b64_htm='<script id="{}" src="data:text/plain;base64,{}" ></script>\n'.format( id, b64_raw )

		if( ext == "css"):
			b64_htm='<style id="{}" src="data:text/css;base64,{}" ></style>\n'.format( id, b64_raw )
		if( ext == "js"):
			b64_htm='<script id="{}" src="data:text/plain;base64,{}" ></script>\n'.format( id, b64_raw )
		if( ext == "png" or ext=="gif" or ext=="jpg" or ext=="jpeg" ):
	 		b64_htm='<img id="{}" src="data:img/{};base64,{}" > \n'.format( id, ext, b64_raw )
		if( b64_htm == "" ):
			b64_htm='<script id="{}" src="data:text/plain;base64,{}" ></script>\n'.format( id, b64_raw )
#	 		b64_htm='<!-- <img id="{}" src="data:img/{};base64,{}" > -->\n'.format( id, ext, b64_raw )

#		if ext == "js":
#		if ext == "png":
#			b64_htm='<img id="{}" src="data:img/png;base64,{}" >\n'.format( id, b64_raw )
#		if ext == "gif":
#			b64_htm='<img id="{}" src="data:img/gif;base64,{}" >\n'.format( id, b64_raw )
#		if ext == "jpg":
#			b64_htm='<img id="{}" src="data:img/jpg;base64,{}" >\n'.format( id, b64_raw )


#		if n == 0:
#			print( "You typed zero.\n")
#		elif n== 1 or n == 9 or n == 4:
#		    print( "n is a perfect square\n")
#		elif n == 2:
#		    print( "n is an even number\n")
#		elif  n== 3 or n == 5 or n == 7:
#		    print( "n is a prime number\n")



		lines_new += "{}".format( b64_htm )

#	print( "BUGS_410 {} {} lines_new={} pathfile={}".format( progid,dttm, lines_new, pathfile))
	return( lines_new )





def go_jsg(a1,a2):
	dttm=kodts('')
	print( "{} {} a={} a2={}".format( progid, dttm, a1, a2 ))

	j=0
	file_cur="index_jsg_basic.html"
	file_new="index_jsg_basic_new.html"
	file_old="index_jsg_basic_old.html"

	file_cur="./jsg/demos/basic.html"
#	file_new="./jsg/demos/basic_new.html"
	file_new="index_jsg_basic.html"
	file_old="./jsg/demos/basic_old.html"

	match_status=""
	match_beg="<title>"
	match_end="</title>"

	f_cur=open( file_cur, "r" )
	f_new=open( file_new, "wb" )
	print( "{} {} go_jsg cur={} new={} ".format( progid,dttm, file_cur, file_new ))

	pathfiles = """
./jsg/demos/demos.css
./jsg/demos/jsg_google.css
./jsg/css/jsgrid.css
./jsg/css/theme.css
./jsg/external/jquery/jquery-1.8.3.js
./jsg/demo/db.js
./jsg/src/jsgrid.core.js
./jsg/src/jsgrid.load-indicator.js
./jsg/src/jsgrid.load-strategies.js
./jsg/src/jsgrid.sort-strategies.js
./jsg/src/jsgrid.field.js
./jsg/src/fields/jsgrid.field.text.js
./src/fields/jsgrid.field.number.js
./jsg/src/fields/jsgrid.field.select.js
./jsg/src/fields/jsgrid.field.checkbox.js
./jsg/src/fields/jsgrid.field.control.js
"""
	lines_new=load_lines_new(pathfiles)
#	print( "{} {} new={}  go_jsg pathfiles={}".format( progid,dttm, lines_new, pathfiles ))

	for line in f_cur:
		j=j+1
		f_file=line
		if re.search( "</head>", line ): f_new.write( "	-->\n\n" )
		f_new.write( line )
		if re.search( match_beg, line ):
			f_new.write( lines_new )
			f_new.write( "\n\n<!--\n" )
			match_status = "match"
			print( "{} {} go_jsg MATCH_BEG  j={} match={} line={}".format( progid, dttm, j, match_beg, line ))
			print( "{} {} go_jsg MATCH_BEG  j={} match={} lines_new={}".format( progid, dttm, j, match_beg, lines_new ))
		if re.search( match_end, line ):
			print( "{} {} go_jsg MATCH_END  j={} match={} line={}".format( progid, dttm, j, match_end, line ))
			match_status = ""

	f_cur.close
	f_new.close
	print( "{} {} go_jsg j={} cur={} new={} old={}".format( progid, dttm, j, file_cur, file_new, file_old ))
	return( "" )

def ko_kov(a1,a2):
	import subprocess
	import re
	dttm=kodts('')
	print("{} {} ko_kov: a2={} a3={}".format( progid, dttm, sys.argv[2], sys.argv[3] ))
	j=0
	kovlist = ""
	kovlist += "kov_ko|"
	kovlist += "kov_new|"
	kovlist += "kov_focus|"
	kovlist += "kov_food|"
	kovlist += "kov_courtreport|"
	kovlist += "kov_where|"
	kovlist += "kov_work|"
	kovlist += "kov_memes|"
	kovlist += "kov_kids|"
	kovlist += "kov_dogs|"
	kovlist += "kov_preserve|"
	kovlist += "kov_protect|"
	kovlist += "kov_jtfdc|"
	kovlist += "kov_jtfinc|"
	kovlist += "kov_byrdpucker|"
	kovlist += "kov_jkwii|"
	kovlist += "kov_kou|"
	kovlist += "kov_kassil|"
	kovlist += "kov_konet|"
	kovlist += "kov_iperms|"
	kovlist += "kov_konabus|"
	kovlist += "kov_kt|"
	kovlist += "kov_go|"
	kovlist += "kov_old"

	j=0
	for kovid in kovlist.split("|"):
		j=j+1
		syscmd_cp="cp index_kov.html {}.html".format( kovid )
		print( "ko_kov_830 DISABLED j={} syscmd={}".format(j, syscmd_cp))
#		os.system(syscmd_cp)
		
	return()

def mth2mm(month):
	months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
	return months.index(month) + 1

def go_printfix(a1,a2):
	ifil="ka1.py"
	ofil="ka0.py"
	i=open(ifil,"r")
	o=open(ofil,"w")
	j=0
	k=0
	for line in i:
		j=j+1
#		print( "BUGS_881 j={} line={}".format(j,line))
#		if( /print( /.line ):)
#		if( re.match("print( ", line ):)
#		pattern = re.compile("print( "))
#		if( pattern.match(line)):
		line=line.replace("\n","")
		if( re.search("print( ", line )):
			k=k+1
			print( "BUGS_881= j={} k={} PRINT  line={}".format(j,k,line))
#			print_line="{})".format(line.replace("print( ", "print( "))
			print( "BUGS_882=j={} k={} PRINT  line={}".format(j,k,line))
			o.write("{}\n".format(print_line))
			
		else:
			o.write("{}\n".format(line))

#		o.write(line)
	i.close()
	o.close()
	print( "BUGS_899 ifil={} ofil={}".format(ifil,ofil))
	exit()




def go(a1,a2):
	import subprocess
	import re

	dttm=kodts('')

# 	pathfiles="""
# ./zc/docs/implementation-guide-v157.pdf
# pdf/konet.pdf
# ko.png
# ./ko.png
# ./links/Awk Introduction Tutorial  7 Awk Print Examples.pdf
# ./links/Awk Introduction Tutorial - 7 Awk Print Examples.pdf
# ./sl/bg/imgs/space/Display Styled Directory Contents %7C CSS-Tricks.pdf
# """
# 	for pathfile in pathfiles.split("\n"):
# 		pathfile_utf8 = pathfile.encode('utf-8')
# 		if( os.path.exists(pathfile_utf8)):
# 			print( "BUGS_1012 ___FOUND pathfile={} {}".format( pathfile, pathfile_utf8 ))
# 		else:
# 			print( "BUGS_1012 NOTFOUND pathfile={} {}".format( pathfile, pathfile_utf8 ))
#	exit()
#	print( "go BUGS_850 {} a0={} a1={}".format(dttm, a0, a1))

#	lines="""
# a b s1 m d 2020 x y 1z.pdf
# a b s2 m h 00:00 x y 2z.pdf
# """
#	j=0
#	for line in lines.split("\n"):
#		if( len(line) == 0 ): continue
#		j=j+1
#		print( "j={} line={}".format(j,line))
#		yyyy=line.split(" ")[5]



	wlfile=a1
	tblnam=a2
#	print( "go BUGS_860 {} wlfile={} tblnam={}".format(dttm, wlfile, tblnam))


	psvfil=wlfile.replace(".txt", ".psv" )
	sqlfil=wlfile.replace(".txt", ".sql" )
	jsonfil=wlfile.replace(".txt", ".json" )

	wl = open( wlfile, "r")
	sql = open( sqlfil, "wb")
	psv = open( psvfil, "wb")
	json = open( jsonfil, "wb")

	ext=wlfile.replace("find_","").replace(".txt","")
#	tblnam=ext
	print( "go BUGS_871 psvfil={} tblnam={}".format(psvfil,tblnam))
	print( "go BUGS_872 sqlfil={} tblnam={}".format(sqlfil,tblnam))


	sqlhead=""
	sqlhead += "create table {} as select * from files limit 1;\n".format(tblnam)
	sqlhead += "delete from {};\n".format(tblnam)
	sql.write(sqlhead)



	(i,j,k) = (0,0,0)
	jsonhead = ""
	jsonitem = ""
	jsontail = ""


	startdate_head="1900,1,1"
	enddate_head="1900,1,1"
	startdate_head="2021,10,1"
	headline_head="headline_head"
	headlint_head="konet notice of liability: {}".format(wlfile)
	text_head="text_head: {} {}".format(dttm,tblnam)
	media_head="/fb/konet/pages/1.jpg"
	caption_head="caption_head: konet "
	credit_head="credit_head"
	pathfile_head="/fb/konet/pages/1.jpg"
	tn_head="/imgs/btn/koeyeb.png"
	jsonhead += '{ "timeline": {\n'
	jsonhead += '"headline":"{}",\n'.format(headlint_head)
	jsonhead += '"type":"default",\n'
	jsonhead += '"text":"<a href=\'{}\' target=_blank><img src=\'{}\' height=200></a>",\n'.format(pathfile_head, tn_head)
	jsonhead += '"startDate":"{}",\n'.format(startdate_head)
	jsonhead += '"endDate":"{}",\n'.format(enddate_head)
	jsonhead += '"date": [ \n'
	json.write(jsonhead)

	startdate_tail=startdate_head
	enddate_tail=enddate_head
	headline_tail=headline_head
	text_tail=text_head
	media_tail=media_head
	caption_tail=caption_head
	credit_tail=credit_head
	pathfile_tail=pathfile_head
	tn_tail=tn_head
	jsontail += '{\n'
	jsontail += '	"startDate":"{}",\n'.format(startdate_tail)
	jsontail += '	"endDate":"{}",\n'.format(enddate_tail)
	jsontail += '	"headline":"{}",\n'.format(headline_tail)
	jsontail += '	"text":"<a href=\'{}\' target=_blank><img src=\'{}\' height=200></a>",\n'.format(pathfile_tail,tn_tail)
	jsontail += '	"asset": {\n'
	jsontail += '		"media":"{}",\n'.format(media_tail)
	jsontail += '		"credit":"{}",\n'.format(credit_tail)
	jsontail += '		"caption":"{}"\n'.format(caption_tail)
	jsontail += '		} } ] } }\n'
	jsontail += '\n'

	sqlout = ""
	sqlout += "create table if not exists {} as select * from files limit 5;\n".format(tblnam)
	sqlout += "delete from {};\n".format(tblnam)
	

	j=0	
	for line in wl:
		j=j+1
		dttm=kodts('')
		startdate_line=""
		headline_line=""
		caption_line=""
		credit_line=""
		if( len(line.split()) > 9 ):
			startdate_line=line.split()[9]
		if( len(line.split()) > 10 ):
			headline_line=line.split()[10].replace("_"," ")
		if( len(line.split()) > 11 ):
			caption_line=line.split()[11].replace("_"," ")
		if( len(line.split()) > 12 ):
			credit_line=line.split()[12].replace("_"," ")

#		print( "BUGS_1001 startdate_line={}\n".format(startdate_line))
#		print( "BUGS_1002 headline_line={}\n".format(headline_line))
#		print( "BUGS_1003 caption_line={}\n".format(caption_line))
#		print( "BUGS_1004 credit_line={}\n".format(credit_line))
#		continue


		size=line.split()[4]
		mth=line.split()[5]
		mm=mth2mm(mth)
		day=line.split()[6]
		splitp=line.split()[7]
		if( splitp.find(":")): 
			yyyyhms=line.split()[7]
			yyyy="2021"
		else:
			yyyyhms="00:00"	
			yyyy=line.split()[7]

		if( len(line.split(splitp)) == 0 ):
			pathfile=line.split(splitp)[0]
		else:
			sizedate=line.split(splitp)[0]
			pathfile=line.split(splitp)[1]

#		p = re.compile('ab*', re.IGNORECASE)

		pathfile=pathfile.strip()
		pathfile='"{}"'.format(pathfile)
		tpathfile=pathfile.replace("'","")
		tpathfile=tpathfile.replace(" ","_")


#		file_exists = exists("\"{}\"".format(pathfile))
#		print( "BUGS_1011 j={} len={} line={}".format(j,len(line.split()),line))
#		if( os.path.exists('"{}"'.format(pathfile))):

		pathfile_utf8 = pathfile.encode('utf-8')

#		if not os.path.isfile(a2):
#		if( os.path.exists( a2 )):
#		if( os.path.exists(pathfile_utf8)):
		if( os.path.isfile(pathfile_utf8)):
			print( "BUGS_1012 j={} ___FOUND size={} yyyy={} yyyyhms={} pathfile={}".format( j, size, yyyy, yyyyhms, pathfile ))
		else:
			print( "BUGS_1013 j={} NOTFOUND size={} yyyy={} yyyyhms={} pathfile={}".format( j, size, yyyy, yyyyhms, pathfile ))
#		exit()
#		continue	
#		if( j>10 ): exit()

#		ctime="{},{},{}".format(yyyyhms.split(':'),mm,day)
		ctime="{},{},{}".format(yyyy,mm,day)
		cdate="{},{},{}".format(yyyy,mm,day)



		path=os.path.dirname(pathfile)
		base=os.path.basename(pathfile)
		file=os.path.splitext(base)[0]
		ext=os.path.splitext(base)[1].replace( ".", "" )

#		size=os.path.getsize(pathfile)	
#		ctime=get_ctime(pathfile)
#		print( "BUGS_1021 {}_{} pathfile={} line={}".format(dttm,j,pathfile,line))
		print( "BUGS_1022 {}_{} pathfile={} path={} base={} file={} ext={} size={} ctime={}".format(dttm,j,pathfile,path,base,file,ext,size,ctime ))





		i=i+1
		j=i+1
		startdate="1900,1,1"
		enddate="1900,1,1"
		headline=base
		text="text"
		media=pathfile
		credit="credit"
		caption="caption"
		f_name=file
		f_type=ext
		f_size=size
		fbid="fb_{}".format(ext)
		tlid="tl_{}".format(ext)
		
		starttime="00:00"
		endtime="00:00"
		thumbnail="{}".format("/imgs/btn/ko.png")
		link="{}".format(base)
		tn="{}_{}.png".format("/imgs/btn/btn",ext)
		title="{}".format(base)
		fpathfile=pathfile
		tpathfile=""
		fn_dttm=ctime
		fn_dt=ctime
		fn_tm=ctime
		exif_dttm=""
		desc="pathfile"

		if( startdate_line ):
			startdate=startdate_line
			enddate=startdate_line
	
		if( headline_line ):
			headline=headline_line
		if( caption_line ):
			caption=caption_line
		if( credit_line ):
			credit=credit_line
	
		psvout=""
#		psvout="{}|{}|{}|{}|{}|{}|{}\n".format(pathfile,path,base,file,ext,size,ctime)
		psvout += "{}|".format( progid )
		psvout += "{}|".format( dttm )
		psvout += "{}|".format( "status" )
		psvout += "{}|".format( "krow" )
		psvout += "{}|".format( f_name )
		psvout += "{}|".format( f_type )
		psvout += "{}|".format( f_size )
		psvout += "{}|".format( "f_error" )
		psvout += "{}|".format( "f_tmp" )
		psvout += "{}|".format( "t_name" )
		psvout += "{}|".format( "referer" )
		psvout += "{}|".format( "query_string" )
		psvout += "{}|".format( "user_agent" )
		psvout += "{}|".format( "remote_addr" )
		psvout += "{}|".format( "remote_port" )
		psvout += "{}|".format( "server_addr" )
		psvout += "{}|".format( "server_port" )
		psvout += "{}|".format( "grp" )
		psvout += "{}|".format( "ord" )
		psvout += "{}|".format( "avid" )
		psvout += "{}|".format( fbid )
		psvout += "{}|".format( tlid )
		psvout += "{}|".format( pathfile )
		psvout += "{}|".format( path )
		psvout += "{}|".format( file )
		psvout += "{}|".format( base )
		psvout += "{}|".format( ext )
		psvout += "{}|".format( size )
		psvout += "{}|".format( ctime )
		psvout += "{}|".format( "mtime" )
		psvout += "{}|".format( fpathfile )
		psvout += "{}|".format( "tpathfile" )
		psvout += "{}|".format( fn_dttm )
		psvout += "{}|".format( "fn_dt" )
		psvout += "{}|".format( "fn_tm" )
		psvout += "{}|".format( "exif_dttm" )
		psvout += "{}|".format( "exif_dt" )
		psvout += "{}|".format( "exif_tm" )
		psvout += "{}|".format( "exif_zm" )
		psvout += "{}|".format( "exif_path" )
		psvout += "{}|".format( "exif_file" )
		psvout += "{}|".format( "exif_imgsize" )
		psvout += "{}|".format( "exif_ctime" )
		psvout += "{}|".format( "exif_duration" )
		psvout += "{}|".format( starttime )
		psvout += "{}|".format( endtime )
		psvout += "{}|".format( title )
		psvout += "{}|".format( thumbnail )
		psvout += "{}|".format( "alt" )
		psvout += "{}|".format( link )
		psvout += "{}|".format( "linktarget" )
		psvout += "{}|".format( "src" )
		psvout += "{}|".format( tn )
		psvout += "{}|".format( "tn1" )
		psvout += "{}|".format( "tn2" )
		psvout += "{}|".format( startdate )
		psvout += "{}|".format( enddate )
		psvout += "{}|".format( headline )
		psvout += "{}|".format( text )
		psvout += "{}|".format( "assets" )
		psvout += "{}|".format( media )
		psvout += "{}|".format( credit )
		psvout += "{}|".format( caption )
		psvout += "{}|".format( i )
		psvout += "{}|".format( j )
		psvout += "{}|".format( k )
		psvout += "{}|".format( "l" )
		psvout += "{}|".format( "w" )
		psvout += "{}|".format( "h" )
		psvout += "{}|".format( "t" )
		psvout += "{}|".format( "x" )
		psvout += "{}|".format( "y" )
		psvout += "{}|".format( "z" )
		psvout += "{}|".format( "t1" )
		psvout += "{}|".format( "x1" )
		psvout += "{}|".format( "y1" )
		psvout += "{}|".format( "z1" )
		psvout += "{}|".format( "t2" )
		psvout += "{}|".format( "x2" )
		psvout += "{}|".format( "y2" )
		psvout += "{}|".format( "z2" )
		psvout += "{}|".format( "temp" )
		psvout += "{}\n".format( desc )
	
#		print( "PSVOUT i={} j={} base={} psvout={}".format( i,j,base,psvout))
		psv.write(psvout)

		sqlout=""
		sqlout="insert or replace into {} ('pathfile') values ('{}')\n".format(tblnam,pathfile)
		
#		sqlout="insert or replace into {} ('pathfile','base','ext','size','ctime') values ('{}','{}','{}','{}','{}')".format(tblnam,pathfile,base,ext,size,ctime)
		sqlout="insert or replace into {} ( 'pathfile','path','base', 'file','ext','size','ctime' ) values ( '{}','{}','{}','{}','{}','{}','{}' );\n".format ( tblnam,pathfile,path,base,file,ext,size,ctime ) 
#		print( "SQLOUT={}".format(sqlout))
		sql.write(sqlout)

		jsonitem = ""
		jsonitem += '	{\n'
		jsonitem += '	"startDate":"{}",\n'.format(startdate)
		jsonitem += '	"endDate":"{}",\n'.format(enddate)
		jsonitem += '	"headline":"{}",\n'.format(headline)
		jsonitem += '	"text":"<a href=\'{}\' target=_blank><img src=\'{}\' height=200></a>",\n'.format(pathfile,tn)
		jsonitem += '	"asset": {\n'
		jsonitem += '		"media":"{}",\n'.format(media)
		jsonitem += '		"credit":"{}",\n'.format(credit)
		jsonitem += '		"caption":"{}"\n'.format(caption)
		jsonitem += '		} },\n'
		json.write(jsonitem)

	wl.close()
	psv.close()
	sql.close()

	json.write(jsontail)
	json.close()

	print( "{}_{} go psvfil={}".format(progid,dttm,psvfil))
	print( "{}_{} go sqlfil={}".format(progid,dttm,sqlfil))
	print( "{}_{} go sqlfil={}".format(progid,dttm,jsonfil))
	exit()


	if( sys.argv[2] == "find"):
		print( "pqpqpqpqpqpqpqpqpqpqpqpq")
		pathfile=sys.argv[3]
		path=os.path.dirname(pathfile)
		base=os.path.basename(pathfile)
		file=os.path.splitext(base)[0]
		ext=os.path.splitext(base)[1]
		brackets = "{}"
		sys_lslat = "ls -lat {}".format( pathfile )
		sys_find='find {} -type f -name "{}"  -exec ls -lat {} \;'.format(path,base,brackets)
		print( progid,dttm,"ko_find sys_find=",sys_find)




#		convert_gif2pngs = "convert {} {}".format(newgif, newpngs )
#		print( "BUGS_1670 gif2gifs g={} convert_gif2pngs={}\n".format( g, convert_gif2pngs ))
#		os.system( convert_gif2pngs )


#		lines = kocmd(sys_lslat).split('\n')
		lines = kocmd(sys_find).split('\n')
		lineslen = len(lines)
#		print( "BUGS_1670 line={} llen={}\rn".format( lines, lineslen ))
		
		j=0
		for line in lines:
			j=j+1
			print( "go find j={}  line={}".format(j,line))
			flds=line.split(" ")
			fldlen=len(flds)
			print( "j={} fldlen={} line={}".format(j,fldlen,line))
#			perms=flds[0]
#			kludge=line.split(" ")[1]
#			permu=flds[1]
#			permg=flds[2]
#			size=flds[4]
#			mth=flds[5]
#			dd=flds[6]
#			hh_mm=flds[7]
#			pathfile=flds[8]
#			print( "flds j={} size={} mth={} dd={} hh_mm={} pathfile={}".format(j,size,mth,dd,hh_mm,pathfile))
#
#			lsnam=line.split(" ")[lslen-1]
#			png_file = gif_file
#			pngnam = "{}/{}{}-{}.png".format(gif_path, png_file, giftag, r )
#			if( p < pnglen-1 ):
#				pngs += "{} ".format(pngnam)
#				print( "BUGS_1671 pnglen={} p={} r={}".format( pnglen, p, r))
#				print( "BUGS_1672 pnglen={} p={} r={} pngnam={}".format(pnglen,p,r,pngnam))
#				print( "BUGS_1673 lsnam={}\n".format(lsnam))
#			p=p+1
#
#		convert_pngs2gif = "convert {} {}".format( pngs, newgif )
#		print( "BUGS_1680 pnglen={} convert_pngs2gif={}\n".format( pnglen, convert_pngs2gif ))
#		os.system( convert_pngs2gif )
#		print( "BUGS_1680 pnglen={} ls_png={}\n".format( pnglen, ls_png ))
#		exit()





	print( "bdbdbdbdbdbdbdbdbdbdbdbd")

	exit()

	ko_usid2host( usid, grp )
	exit()

	if( sys.argv[1].match("find")):
		pathfile=sys.argv[2]
		path=os.path.dirname(pathfile)
		base=os.path.basename(pathfile)
		file=os.path.splitext(base)[0]
		ext=os.path.splitext(base)[1]
		print( "GO FIND")
		exit()




	exit()

#	if( sys.argv[1].match("listdir")):
#	if( sys.argv[1] == "listdir" ):
	if( a2 != "" ):
		pathfile=sys.argv[2]
		path=os.path.dirname(pathfile)
		base=os.path.basename(pathfile)
		file=os.path.splitext(base)[0]
		ext=os.path.splitext(base)[1]
#		filecode_tuple=str(j),"-",file,"-",ext
#		filecode = "".join(filecode_tuple)
#		print( progid,dttm, "ko_go: path=",path," base=",base," ext=",ext)


	dttm=kodts('')
	print( progid,dttm,"ko_go a1=",a1)
	pathfile="."
	ofilename="ko_go.csv"
	ifilename=ofilename
	tmp_pathfile="ko_go.tmp"
	todo_pathfile="ko_go.todo"
	db3_pathfile="ko_go.db3"

	if( a1 != "" ): pathfile=a1

	syscmd="pwd;date"
	print( progid,dttm, "ko_go_syscmd syscmd={}".format( syscmd))
	os.system( syscmd)





	exit()

#	syscmd="ls -lat {} | exiftool -s -csv".format( pathfile )
	syscmd_find = 'find {} -name "{}" -exec ls {} \; > {}'.format( path, base, "{}", tmp_pathfile )
	print( progid,dttm, "ko_go_find syscmd={}".format( syscmd_find ))
#	os.system( syscmd_find )

	pathcode=path.replace("/","-")
	pathcode=pathcode.replace(".","")

	if( os.path.isfile(ofilename)):
		print( progid,dttm, "ko_go ofilename={}".format( ofilename ))
	else:
		todofile_dttm="ka1_{}.todo".format(dttm)
		todofile="ka1{}.todo".format( pathcode )
#               syscmd='find . -name "* *.mp4" -exec ls {} \; > '^
#               syscmd='find . -name "*--*.mp4" -exec ls {} \; > 'M
		syscmd='find . -name "*.mp4" -exec ls {} \; > '
		syscmd+=todofile
		syscmd = 'find {} -name "{}" -exec ls {} \; > {}'.format( path, base,"{}", todofile )
		print( progid,dttm, "ko_go_find syscmd={}".format( syscmd ))
		print( progid,dttm, "ko_go_find pathcode={}".format( pathcode ))
		os.system( syscmd )

	ifilename=todofile
	print( progid,dttm, "go ifilename={}".format( ifilename ))
	return("go")


#	ifile = open(ifilename, "r" )
##	j=0
#	ofilename_mv="ko_go_mv.sh"
#	oline_mv = "# ko_go_mv.sh {}\n".format(dttm)
#	ofile_mv = open( ofilename_mv, "wb" )
#	ofile_mv.write( oline_mv )
#	mv.close()








def ko_go(a1,a2):
	import subprocess
	import re
# bugs	from ffvideo import VideoStream
# bugs	import VideoStream
# bugs	import ffviceo

#	if( sys.argv[1].match("listdir")):
#	if( sys.argv[1] == "listdir" ):
#	if( a2 != "" ):
	dttm=kodts('')

	if( sys.argv[2] == "." ):
		print( "{} {} ko_go: go . .".format( progid, dttm ))
		print( "{} {} ko_go: go find ../i 'oagland.mpr' .".format( progid, dttm ))
		print( "{} {} ko_go: go uslist .".format( progid, dttm ))
#		print( "{} {} ko_go: go uslaw .".format( progid, dttm ))
		print( "{} {} ko_go: go usmed .".format( progid, dttm ))
		print( "{} {} ko_go: go cp .".format( progid, dttm ))
		print( "{} {} ko_go: go scp .".format( progid, dttm ))
		print( "{} {} ko_go: go ssh .".format( progid, dttm ))
		exit()

	print( "BUGS_970")
	if( sys.argv[2] == "find" ):
		pathfile=sys.argv[3]
		path=os.path.dirname(pathfile)
		base=os.path.basename(pathfile)
		file=os.path.splitext(base)[0]
		ext=os.path.splitext(base)[1]
		ext = ext.replace( ".", "" )
		filid =os.path.splitext(base)[0]
		findname=base
		findpath=path
		j=0
		findthis = "go find path={} base={}".format(path, base)
		sys_find="find {} -name {} -exec ls -lat {} \;"
		finds = ko_find( path, base )
		for find in finds:
			print( "go find j={} find={}".format( j, find ))
		exit()

	print( "EXIT_1000")
	exit()
	import sqlite3
	dttm=kodts('')
	sqlfil="ko.db3"
	sqlcmd="select cat,test,testdt from lab"
	sqlcmd="select * from uslist"
	sqlcmd="select usid,dttm,status,url,img,tn,id,grp from uslist "
	print( progid,dttm,"ko_sql sqlfil={} sqlcmd={}\n".format( sqlfil, sqlcmd ))
	fildb3="ko.db3"

	try:
		sqldb = sqlite3.connect(fildb3)
	except Error as e:
		print(e)

	cur = sqldb.cursor()
#	cur.execute("SELECT * FROM tasks")
	cur.execute(sqlcmd)
	rows = cur.fetchall()
	for row in rows:
		print( "r0={} r1={} r3={}".format( row[0], row[1], row[2] ))
# err		print( "cat={} test={} testdt={}".format( row['cat'], row['test'], row['testdt'] ))
#		print(row)

	print( progid,dttm,"ko_usid2host sqlfil={} sqlcmd={}\n".format( sqlfil, sqlcmd ))


	db = sqlite3.connect(fildb3)
	db.row_factory = sqlite3.Row
	cursor = db.cursor()

	sqlcmd='''select usid,dttm,status,url,img,tn,id,grp from uslist'''
	cursor.execute(sqlcmd)
#	cursor.execute('''select name, email, phone from uslist limit 4''')

	osflag = ""
	for row in cursor:
# 		row['name'] returns the name column in the query, row['email'] returns email column.
		print('{0} : {1}, {2}'.format(row['usid'], row['url'], row['img'], row['tn'], row['id'], row['grp'], row['status']))
		grp=row['grp']
		id=row['id']
		url=row['url']
		img=row['img']
		tn=row['tn']
		status=row['status']

		syscmd_mkdir_grp = "mkdir uw/{}".format(grp)
		print( "usid2host syscmd_mkdir_grp={}".format( syscmd_mkdir_grp ))

		syscmd_mkdir_grpid = "mkdir uw/{}/{}".format(grp,id)
		print( "usid2host grp={} id={} syscmd_mkdir_grpid={}".format( grp, id, syscmd_mkdir_grp))

		osflag = ""
		print( "osflag={}".format(osflag))
#		if( osflag == "y" ): os.system( syscmd_mkdir_grp )
#		if( osflag == "y" ): os.system( syscmd_mkdir_grpid )


#	db.close()
#	return( "ko_usid2host" )




	def sql_cr(fildb3, sqlcmd ):
		sqlcmd= """ CREATE TABLE IF NOT EXISTS pd (
                                        id integer PRIMARY KEY,
                                        code text NOT NULL,
                                        dttm text NOT NULL,
                                        ctime text,
                                        filsiz text,
                                        pathfile text,
                                        path text,
                                        base text,
                                        ext text,
                                        link text,
                                        title text,
                                        desc text
                                    ); """
		cur.execute(sqlcmd)


	uslist = load_uslist()
	j=0
	status="todo"
	dttm=kodts('')
	for us in uslist:
		print( "j={} us={}".format(j, us))

		url=us.split("|")[0]
		img=us.split("|")[1]
		tn=us.split("|")[2]
		id=us.split("|")[3]
		grp=us.split("|")[4]
		status="todo"

		sqltbl = "uslist"
		sqlcols = "'id', 'grp', 'url', 'img', 'tn','status','dttm'"
		sqlvals = "'id', 'grp', 'url', 'img', 'tn','status','dttm'"
		sqlvals = "'{}','{}','{}','{}','{}','{}','{}'".format(id,grp,url,img,tn,status,dttm)

		sql_insert = "insert or replace into {} ( {} ) values ( {} )".format( sqltbl, sqlcols, sqlvals )
		print( "{}".format(sql_insert))
#		print( "usid2host j={} sql_insert={}".format(j,sql_insert))
#		print( "j={} grp={} id={} url={} img={}".format( j, grp, id, url, img ))
#		cur.execute(sql_insert)
		cursor.execute(sql_insert)

#		def sql_insert(fildb3, sql_insert ):
#			sql_insert = "insert or replace into {} ( {} ) values ( {} )".format( sqltbl, sqlcols, sqlvals )
#
#
#		def sql_insert(fildb3, sqlcmd ):
#		sqlcmd = """INSERT INTO table1 (
#		sqlcmd = """insert or replace into  uslist (
#				'id','grp','url','img','tn','status','dttm' )
#			VALUES (
#				sqlval
##				value1, value2 ,...
#				); """
#
		j=j+1
	db.close()
	return("ko_sql_return");




	if( sys.argv[2] == "filio" ):
		curfil = sys.argv[3]
		base = curfil.split(".")[0]
		base = os.path.basename( curfil )
		ext = os.path.splitext(base)[1]
		ext = ext.replace( ".", "" )
		filid =os.path.splitext(base)[0]

		dttg = dttm
		dttg = dttg.replace( ":","")
		dttg = dttg.replace( "-","")

		oldtxt="<html>"
		curtxt="<!-- html {} -->\n".format( base )
		newtxt=""
		newfil="{}_new_{}.{}\n".format( filid, dttg, ext )
		oldfil="{}_old_{}.{}\n".format( filid, dttg, ext )
		if( os.path.exists(curfil)):
			cpcmd = "cp {} {}".format( curfil, oldfil )
#			print( "{} {} ko_go: go filio cpcmd={}".format( progid, dttm, cpcmd ))
#			os.system( cpcmd )
		print( "{} {} ko_go: go filio \n curfil={} \n oldfil={} \n newfil={} \n oldtxt={} \n newtxt={} ".format( progid, dttm, curfil, oldfil, newfil, oldtxt, newtxt ))
		exit
		newtxt=filio( curfil,filid )
#		newf = open( newfil, "w" )
#		newf.write( newtxt )
#		newf.close		
#		print( "{}".format(newtxt))

	if( sys.argv[2] == "htms2htm" ):
		htmout=htms2htm( "svc/jqgrid")
		print( "{} {} ko_go: go htmout={} ".format( progid, dttm, htmout ))

	if( sys.argv[2] == "phps2php" ):
		phpout=phps2php('')
		print( "{} {} ko_go: go phpout={} ".format( progid, dttm, phpout ))

	if( sys.argv[2] == "newhtm" ):
		print( "{} {} ko_go: go newhtm ".format( progid, dttm ))
		htmids=sys.argv[3]

		if( htmids == '.' ):
			htmout=newhtm('templet kogrids kov_hideshow dragons ajaxdb3 kovs_utl')
			print( ('{}').format(htmout))
			exit()
		if( len(htmids) > 3 ):
			htmout=newhtm(htmids)
			print( ('{}').format(htmout)	)
			exit
#		if( htmids == "txt" ):
#			htmout_txt=newhtm('templet kogrids kov_hideshow dragons ajaxdb3 kovs_utl')
#			print( 'htmout_txt={}'.format(htmout_txt)
#			exit
#		if( htmids == 'psv' ):
#			htmids=newhtm('templet|kogrids|kov_hideshow|dragons|ajaxdb3|kov_utl')
#			print( 'htmout_psv={}'.format(htmout_psv)
#		if( htmids == 'csv'):
#			htmout_csv=newhtm('templet,kogrids,kov_hideshow,dragons,ajaxdb3,kov_utl')
#			print( 'htmout_csv={}'.format(htmout_csv)
#		if( htmids == 'spl' ):
#			htmout_spl=newhtm('templet,kogrids,kov_hideshow,dragons,ajaxdb3,kov_utl')
#			print( 'htmout_spl={}'.format(htmout_spl)
#		return( htmout)
#		exit


#	if( sys.argv[2] == "uslaw" ):
	if( sys.argv[2] == "uslist" ):
		uslist = load_uslist()
		k=0
		for usline in uslist:
			k=k+1
			url = usline.split("|")[0]
			img = usline.split("|")[1]
			tn = usline.split("|")[2]
			id = usline.split("|")[4]
			code=img.replace(".png","")
			code=code.replace("/imgs/us/", "")
			code=code.replace( id, "" )
			code=code.replace( "_", "" )

			urlus="/us/{}/{}/".format( id, code )
			print( "id={} ".format( id ))

			syscmd_mkdir_id = "mkdir us/{}/".format( id )
			syscmd_mkdir_idcode = "mkdir us/{}/{}/".format( id, code )
			syscmd_mkdir_idcode_img = "mkdir us/{}/{}/imgs".format( id, code )
			syscmd_mkdir_idcode_tn = "mkdir us/{}/{}/imgs/tn".format( id, code )
			syscmd_cp_index = "cp index.html us/{}/{}/index.html".format( id, code )
			syscmd_cp_img = "cp imgs/btn/koeyeb.png us/imgs/{}_{}.png".format( id, code )
			syscmd_cp_tn = "cp imgs/btn/koeyew.png us/imgs/tn/tn_{}_{}.png".format( id, code )

			htmout = '\n' 
			htmout += '	<div id="drag">\n'
			htmout += '		<div class="drag">\n'
			htmout += '		<a href="{}" target=_blank class="thumbnail">\n'.format(url)
			htmout += '			<img  class="drg" src=/us/imgs/tn/tn_{}_{}.png border=0 height=200>\n'.format(id, code)
			htmout += '			<span><img class="drg" src=/us/imgs/{}_{}.png border=0 height=400></span>\n'.format(id, code)
			htmout += '			</a>\n'
			htmout += '			</div>\n'
			htmout += '		</div>\n'
			syscmd_htmout = 'echo "{}" >> us/{}/{}/index.html'.format( htmout, id, code )

			print( "syscmd_mkdir_id={}".format( syscmd_mkdir_id ))
			print( "syscmd_mkdir_idcode={}".format( syscmd_mkdir_idcode ))
			print( "syscmd_mkdir_idcode_img={}".format( syscmd_mkdir_idcode_img ))
			print( "syscmd_mkdir_idcode_tn={}".format( syscmd_mkdir_idcode_tn ))

#			print( "syscmd_cp_index={}".format( syscmd_cp_index ))
#			print( "syscmd_htmout={}".format( syscmd_htmout ))
#			print( "syscmd_cp_img={}".format( syscmd_cp_img ))
#			print( "syscmd_cp_tn={}".format( syscmd_cp_tn ))

			os.system( syscmd_mkdir_id )
			os.system( syscmd_mkdir_idcode )
			os.system( syscmd_mkdir_idcode_img )
			os.system( syscmd_mkdir_idcode_tn )
			os.system( syscmd_cp_index )
			os.system( syscmd_cp_img )
			os.system( syscmd_cp_tn )
			os.system( syscmd_htmout )
			exit()

#			print( "code={} k={} id={} ".format(code, k, id ))
#			print( "{} {} go usline k={} code={} url={} id={}".format(progid,dttm,k,code, url,id))
#			print( "{} {} go usline k={} url={} img={} tn={} id={} usline={}".format(progid,dttm,k, url,img,tn,id, usline))
		exit()




	if( sys.argv[2] == "usmed" ):
#		my_date = datetime.date(*[int(i) for i in string_date.split("-")])

		usmeds_default = [
"smith",
"katyal",
"bammimore",
"rechtin",
"mcdonough"
			]
		k=0
		klim=len(usmeds_default)
		usmeds=usmeds_default
		if( sys.argv[3].isdigit() ):	
			print( "BUGS IS_DIGIT k={} klim={}".format(k, klim ))
			k=int(sys.argv[3])
			if( k <= klim ):
				print( "BUGS IS_DIGIT_K k={} klim={}".format(k, klim ))
				usmeds = [usmeds_default[k-1]]
		else:
			print( "BUGS NO_DIGIT k={} klim={}".format(k, klim ))
			


			if( sys.argv[3] == "rechtin" ):
				usmeds =  [sys.argv[3]]
			if( sys.argv[3] == "mcdonough" ):
				usmeds = [sys.argv[3]] 
			if( sys.argv[3] == "jkwii" ):
				usmeds =  ["jkwii"]

#			k=int(sys.argv[3])
#			klim=5
#			if( isinstance(k, int)):

#			print( "{} {} go_usmed argv3=int k={} len={}".format( progid, dttm, k, klim ))
#			if( k <= klim ):
#				print( "{} {} go_usmed ONE argv3=int k={} len={}".format( progid, dttm, k, klim ))
#				usmeds = [usmeds_default[k]]
#			else:
#				print( "{} {} go_usmed ALL  argv3=int k={} len={}".format( progid, dttm, k, klim ))
#				usmeds = usmeds_default
	
			if( sys.argv[3] == "." ):
				usmeds = usmeds_default
	
	



		uhdata = (
"ko0|kozerus@ko0.us|~/public_html",
"ko2|kotwous@ko2.us|~/public_html",
"ka1|konet@ka11|/ht",
"ka2|konet@ka21|/ht",
"ka11|konet@ka11|/Volumes/ka1tbr1",
"ka12|konet@ka11|/Volumes/ka1tbr2",
"ka21|konet@ka21|/Volumes/ka2tbr1",
"ka22|konet@ka21|/Volumes/ka2tbr2"
			)

		uhlist = (
"ko0|kozerus@ko0.us|~/public_html",
"ko2|kotwous@ko2.us|~/public_html"
			)



		j=0
		for uhline in uhlist:
			j=j+1
			uhcode = uhline.split("|")[0]
			uhhost = uhline.split("|")[1]
			uhroot = uhline.split("|")[2]
			print( "{} {} {} uhcode={} uhhost={} uhroot={}".format( progid, dttm, j, uhcode, uhhost,uhroot ))
			k=0
			for usmed in usmeds:
				k=k+1

				j=j+1
				print( "{} {} usmed={} k={} uhhost={} uhroot={}".format( progid, dttm, usmed, k, uhhost, uhroot ))
				sshcmd_mkdir_us_med='ssh {} "mkdir {}/us/med/"'.format( uhhost, uhroot )
				sshcmd_mkdir_us_med_usmed='ssh {} "mkdir {}/us/med/{}/"'.format( uhhost, uhroot, usmed )
				sshcmd_mkdir_us_med_usmed_imgs='ssh {} "mkdir {}/us/med/{}/imgs/"'.format( uhhost, uhroot, usmed )
				sshcmd_mkdir_us_med_usmed_imgs_tn='ssh {} "mkdir {}/us/med/{}/imgs/tn/"'.format( uhhost, uhroot, usmed )
	
				scpcmd_us_img="scp us/imgs/med_{}.png {}:{}/us/imgs/".format( usmed, uhhost, uhroot )
				scpcmd_us_tn="scp us/imgs/tn/tn_med_{}.png kozerus@ko0.us:{}us/imgs/tn/".format( usmed, uhhost, uhroot )
			
				cpcmd_us_med_usmed_index_html = "cp us/med/index.html us/med/{}/index.html".format(usmed)
				cpcmd_us_med_index_us_med_usmed_html = "cp us/med/index_us_med.html us/med/index_us_med_{}.html".format(usmed)
	
				scpcmd_us_med_usmed_imgs_tn="scp us/med/{}/imgs/tn/*.png {}:{}/us/med/{}/imgs/tn/".format( usmed, uhhost, uhroot, usmed )
				scpcmd_us_med_usmed_imgs="scp us/med/{}/imgs/*.png {}:{}/us/med/{}/imgs/".format( usmed,  uhhost, uhroot, usmed )
				scpcmd_us_med_usmed="scp us/med/{}/*.* {}:{}/us/med/{}/".format(usmed, uhhost, uhroot , usmed )
				scpcmd_us_med_usmed_index_html = "scp us/med/{}/index.html {}:{}/us/med/{}".format(usmed, uhhost, uhroot ,usmed )
				scpcmd_us_med_index_us_med_usmed_html = "scp us/med/index_us_med_{}.html {}:{}/us/med/".format(usmed, uhhost, uhroot )


				print( "{} {} usmed={} sshcmd_mkdir_us_med={}".format( progid, dttm,usmed,  sshcmd_mkdir_us_med ))
				print( "{} {} usmed={} sshcmd_mkdir_us_med_usmed={}".format( progid, dttm,usmed,  sshcmd_mkdir_us_med_usmed ))
				print( "{} {} usmed={} sshcmd_mkdir_us_med_usmed_imgs={}".format( progid, dttm,usmed,  sshcmd_mkdir_us_med_usmed_imgs ))
				print( "{} {} usmed={} sshcmd_mkdir_us_med_usmed_imgs_tn={}".format( progid, dttm,usmed,  sshcmd_mkdir_us_med_usmed_imgs_tn ))


				print( "{} {} usmed={} cpcmd_us_med_index_us_med_usmed_html={}".format( progid, dttm, usmed,  cpcmd_us_med_index_us_med_usmed_html ))
				print( "{} {} usmed={} cpcmd_us_med_usmed_index_html={}".format( progid, dttm, usmed,  cpcmd_us_med_usmed_index_html ))


				print( "{} {} usmed={} scpcmd_us_med_usmed_imgs_tn={}".format(  progid, dttm,usmed, scpcmd_us_med_usmed_imgs_tn ))
				print( "{} {} usmed={} scpcmd_us_med_usmed_imgs={}".format(  progid, dttm,usmed, scpcmd_us_med_usmed_imgs))
				print( "{} {} usmed={} scpcmd_us_med_usmed={}".format( progid, dttm,usmed,  scpcmd_us_med_usmed))
	
				print( "{} {} usmed={} scpcmd_us_img={}".format( progid, dttm, usmed, scpcmd_us_img ))
				print( "{} {} usmed={} scpcmd_us_tn={}".format( progid, dttm, usmed,  scpcmd_us_tn ))

				print( "{} {} usmed={} scpcmd_us_med_usmed_index_html={}".format( progid, dttm, usmed,  scpcmd_us_med_usmed_index_html ))
				print( "{} {} usmed={} scpcmd_us_med_index_us_med_usmed_html={}".format( progid, dttm, usmed,  scpcmd_us_med_index_us_med_usmed_html ))

#				os.system( sshcmd_mkdir_us_med )
#				os.system( sshcmd_mkdir_us_med_usmed )
#				os.system( sshcmd_mkdir_us_med_usmed_imgs )
#				os.system( sshcmd_mkdir_us_med_usmed_imgs_tn )

#				os.system( cpcmd_us_med_index_us_med_usmed_html )
#				os.system( cpcmd_us_med_usmed_index_html )

#				os.system( scpcmd_us_med_usmed_imgs_tn )
#				os.system( scpcmd_us_med_usmed_imgs)
#				os.system( scpcmd_us_med_usmed)

#				os.system( scpcmd_us_img )
#				os.system( scpcmd_us_tn )

#				os.system( scpcmd_us_med_usmed_index_html )
#				os.system( scpcmd_us_med_index_us_med_usmed_html )
			exit()

	if( sys.argv[2] == "cp" ):
		print( progid,dttm, "ko_go cp: a2=",a2)
		syscmd_cp_ko0dt="cat index.html | sed s!-=kako=-!-=ko0us=-!g > index_ko0dt.html"
		syscmd_cp_ko2dt="cat index.html | sed s!-=kako=-!-=ko2us=-!g > index_ko2dt.html"
		syscmd_cp_ka1dt="cat index.html | sed s!-=kako=-!-=ka1lo=-!g > index_ka1dt.html"
		syscmd_cp_ka2dt="cat index.html | sed s!-=kako=-!-=ka2lo=-!g > index_ka2dt.html"

		print( "{} {} ko_go cp ko0dt: syscmd_cp_ko0dt={}".format(progid,dttm,syscmd_cp_ko0dt))
		os.system( syscmd_cp_ko0dt )
		print( "{} {} ko_go cp ko2dt: syscmd_cp_ko2dt={}".format(progid,dttm,syscmd_cp_ko2dt))
		os.system( syscmd_cp_ko2dt )
		print( "{} {} ko_go cp ka1dt: syscmd_cp_ka1dt={}".format(progid,dttm,syscmd_cp_ka1dt))
		os.system( syscmd_cp_ka1dt )
		print( "{} {} ko_go cp ka2dt: syscmd_cp_ka2dt={}".format(progid,dttm,syscmd_cp_ka2dt))
		os.system( syscmd_cp_ka2dt )

		syscmd_cp_ko0="cat index_ko0dt.html | sed s!-=dttm=-!-={}=-!g > index_ko0.html".format(dttm)
		syscmd_cp_ko2="cat index_ko2dt.html | sed s!-=dttm=-!-={}=-!g > index_ko2.html".format(dttm)
		syscmd_cp_ka1="cat index_ka1dt.html | sed s!-=dttm=-!-={}=-!g > index_ka1.html".format(dttm)
		syscmd_cp_ka2="cat index_ka2dt.html | sed s!-=dttm=-!-={}=-!g > index_ka2.html".format(dttm)

		print( "{} {} ko_go cp ko0: syscmd_cp_ko0={}".format(progid,dttm,syscmd_cp_ko0))
		os.system( syscmd_cp_ko0 )
		print( "{} {} ko_go cp ko2: syscmd_cp_ko2={}".format(progid,dttm,syscmd_cp_ko2))
		os.system( syscmd_cp_ko2 )
		print( "{} {} ko_go cp ka1: syscmd_cp_ka1={}".format(progid,dttm,syscmd_cp_ka1))
		os.system( syscmd_cp_ka1 )
		print( "{} {} ko_go cp ka2: syscmd_cp_ka2={}".format(progid,dttm,syscmd_cp_ka2))
		os.system( syscmd_cp_ka2 )
		exit()

	if( sys.argv[2] == "ssh" ):
		sshcmd = "pwd;date;uname;"
		sshcmd_ko0='ssh kozerus@ko0.us \"{}\"'.format( sshcmd )
		sshcmd_ko2='ssh kotwous@ko2.us "{}"'.format( sshcmd )
		sshcmd_ka1='ssh konet@ka1.lo "{}"'.format( sshcmd )
		sshcmd_ka2='ssh konet@ka2.lo "{}"'.format( sshcmd )

		if( sys.argv[3] == "." ) or ( sys.argv[3] == "ko" ):
			print( "{} {} ko_go ssh: sshcmd_ko0={}".format(progid,dttm,sshcmd_ko0))
#			os.system( sshcmd_ko0 )
			print( "{} {} ko_go ssh: ssycmd_ko2={}".format(progid,dttm,sshcmd_ko2))
#			os.system( sshcmd_ko2 )

		if( sys.argv[3] == "ko0" ):
			print( "{} {} ko_go ssh: sshcmd_ko0={}".format(progid,dttm,sshcmd_ko0))
#			os.system( sshcmd_ko0 )

		if( sys.argv[3] == "ko2" ):
			print( "{} {} ko_go ssh: ssycmd_ko2={}".format(progid,dttm,sshcmd_ko2))
#			os.system( sshcmd_ko2 )
		if( sys.argv[3] == "ka1" ):
			print( "{} {} ko_go ssh: ssycmd_ka1={}".format(progid,dttm,sshcmd_ka1))
#			os.system( sshcmd_ka1 )
		if( sys.argv[3] == "ka2" ):
			print( "{} {} ko_go ssh: ssycmd_ka2={}".format(progid,dttm,sshcmd_ka2))
#			os.system( sshcmd_ka2 )
		exit()

	if( sys.argv[2] == "scp" ):
		print( progid,dttm, "ko_go scp: a2=",a2)
		scpcmd_ko0 = "scp index_ko0.html kozerus@ko0.us:~/public_html/index.html"
		scpcmd_ko2 = "scp index_ko2.html kotwous@ko2.us:~/public_html/index.html"
		scpcmd_ka1 = "cp index_ka1.html /ht/index.html"
		scpcmd_ka2 = "scp index_ka2.html konet@ka2.lo/ht/index.html"

		scpcmd_ka10 = "cp index_ka10.html /ht/index.html"
		scpcmd_ka11 = "cp index_ka11.html /Volumes/ka1tbr1/ht/index.html"
		scpcmd_ka12 = "cp index_ka12.html /Volumes/ka1tbr2/ht/index.html"
		scpcmd_ka20 = "scp index_ka20.html konet@ka2.lo:~/ht/index.html"
		scpcmd_ka21 = "scp index_ka21.html konet@ka2.lo:~/Volumes/ka2tbr1/index.html"
		scpcmd_ka22 = "scp index_ka22.html konet@ka2.lo:~/Volumes/ka2tbr2/index.html"

		if( sys.argv[3] == "." ) or ( sys.argv[3] == "ko" ):
			print( "{} {} ko_go scp ko0: scpcmd_ko0={}".format( progid, dttm, scpcmd_ko0))
			os.system( scpcmd_ko0 )
			print( "{} {} ko_go scp ko2: scpcmd_ko2={}".format( progid, dttm, scpcmd_ko2))
			os.system( scpcmd_ko2 )

		if( sys.argv[3] == "ko0" ):
			print( "{} {} ko_go scp ko0: scpcmd_ko0={}".format( progid, dttm, scpcmd_ko0))
			os.system( scpcmd_ko0 )
		if( sys.argv[3] == "ko2" ):
			print( "{} {} ko_go scp ko2: scpcmd_ko2={}".format( progid, dttm, scpcmd_ko2))
			os.system( scpcmd_ko2 )


		if( sys.argv[3] == "ka1" ):
			print( "{} {} ko_go scp ka1: scpcmd_ka1={}".format( progid, dttm, scpcmd_ka1))
#			os.system( scpcmd_ka1 )
		if( sys.argv[3] == "ka10" ):
			print( "{} {} ko_go scp ka10: scpcmd_ka10={}".format( progid, dttm, scpcmd_ka10))
#			os.system( scpcmd_ka10 )
		if( sys.argv[3] == "ka11" ):
			print( "{} {} ko_go scp ka11: scpcmd_ka11={}".format( progid, dttm, scpcmd_ka11))
#			os.system( scpcmd_ka11 )
		if( sys.argv[3] == "ka12" ):
			print( "{} {} ko_go scp ka12: scpcmd_ka12={}".format( progid, dttm, scpcmd_ka12))
#			os.system( scpcmd_ka12 )
		if( sys.argv[3] == "ka1" ):
			print( "{} {} ko_go scp ka1: scpcmd_ka1={}".format( progid, dttm, scpcmd_ka1))
#			os.system( scpcmd_ka1 )

		exit()



		if( sys.argv[3] == "ko"):
			sshcmd_ko0 = "scp index_ko0.html kozerus@ko0.us:~/public_html/index.html"
			sshcmd_ko2 = "scp index_ko2.html kozerus@ko2.us:~/public_html/index.html"
			print( progid,dttm, "ko_go ssh ko?: sshcmd_ko0=",sshcmd_ko0)
			print( progid,dttm, "ko_go ssh ko?: sshcmd_ko2=",sshcmd_ko2)
#			os.system( sshcmd_ko0 )
#			os.system( sshcmd_ko2 )
		if( sys.argv[3] == "ko0"):
			sshcmd_ko0 = "scp index_ko0.html kozerus@ko0.us:~/public_html/index.html"
			print( progid,dttm, "ko_go ssh ko?: sshcmd_ko0=",sshcmd_ko0)
#			os.system( sshcmd_ko0 )
		if( sys.argv[3] == "ko2"):
			sshcmd_ko2 = "scp index_ko2.html kozerus@ko2.us:~/public_html/index.html"
			print( progid,dttm, "ko_go ssh ko?: sshcmd_ko2=",sshcmd_ko2)
			os.system( sshcmd_ko0 )
		if( sys.argv[3] == "ka"):
			print( progid,dttm, "ko_go ssh ka?: a2=",a2)
		if( sys.argv[3] == "ka1"):
			print( progid,dttm, "ko_go ssh ka1: a2=",a2)
		if( sys.argv[3] == "ka2"):
			print( progid,dttm, "ko_go ssh ka2: a2=",a2)





	exit()

	if( sys.argv[2] != "" ):
		dttm=kodts('')
		print( progid,dttm, "ko_go: a2=",a2)
#		ko_listdir( sys.argv[2], sys.argv[3] )
		pathfile=sys.argv[2]
		path=os.path.dirname(pathfile)
		base=os.path.basename(pathfile)
		file=os.path.splitext(base)[0]
		ext=os.path.splitext(base)[1]
#		filecode_tuple=str(j),"-",file,"-",ext
#		filecode = "".join(filecode_tuple)
#		print( progid,dttm, "ko_go: path=",path," base=",base," ext=",ext)


	dttm=kodts('')
	print( progid,dttm,"ko_go a1=",a1)
	pathfile="."
	ofilename="ko_go.csv"
	ifilename=ofilename
	tmp_pathfile="ko_go.tmp"
	todo_pathfile="ko_go.todo"
	db3_pathfile="ko_go.db3"

	if( a1 != "" ): pathfile=a1

	syscmd="pwd;date"
	print( progid,dttm, "ko_go_syscmd syscmd={}".format( syscmd))
	os.system( syscmd)





	exit()

#	syscmd="ls -lat {} | exiftool -s -csv".format( pathfile )
	syscmd_find = 'find {} -name "{}" -exec ls {} \; > {}'.format( path, base, "{}", tmp_pathfile )
	print( progid,dttm, "ko_go_find syscmd={}".format( syscmd_find ))
#	os.system( syscmd_find )

	pathcode=path.replace("/","-")
	pathcode=pathcode.replace(".","")

	if( os.path.isfile(ofilename)):
		print( progid,dttm, "ko_go ofilename={}".format( ofilename ))
	else:
		todofile_dttm="ka1_{}.todo".format(dttm)
		todofile="ka1{}.todo".format( pathcode )
#               syscmd='find . -name "* *.mp4" -exec ls {} \; > '^
#               syscmd='find . -name "*--*.mp4" -exec ls {} \; > 'M
		syscmd='find . -name "*.mp4" -exec ls {} \; > '
		syscmd+=todofile
		syscmd = 'find {} -name "{}" -exec ls {} \; > {}'.format( path, base,"{}", todofile )
		print( progid,dttm, "ko_go_find syscmd={}".format( syscmd ))
		print( progid,dttm, "ko_go_find pathcode={}".format( pathcode ))
		os.system( syscmd )

	ifilename=todofile
	print( progid,dttm, "ko_go ifilename={}".format( ifilename ))
	return("ko_go")


	ifile = open(ifilename, "r" )
	j=0
	ofilename_mv="ko_go_mv.sh"
	oline_mv = "# ko_go_mv.sh {}\n".format(dttm)
	ofile_mv = open( ofilename_mv, "wb" )
	ofile_mv.write( oline_mv )


	ofilename_png="ko_go_png.sh"
	oline_png = "# ko_go_png.sh {}\n".format(dttm)
	ofile_png = open( ofilename_png, "wb" )
	ofile_png.write( oline_png )

#	oline_png = "# ko_go_png.sh end\n"
#	ofile_png.write( oline_png )
#	ofile_png.close()

	ofilename_tn="ko_go_tn.sh"
	oline_tn = "# ko_go_tn.sh {}\n".format(dttm)
	ofile_tn = open( ofilename_tn, "wb" )
	ofile_tn.write( oline_tn )

	ifilename_htm = "ka1_av.html"
	ofilename_htm = "ka1_av_out.html"
	iline_htm = ""
	oline_htm = ""
	

	ofilename_psv = "ko_go.psv"
	oline_psv = "idx|status|dttm|id|filnam|png|tn|size|cr_dttm|m_dttm|t1|t2|duration|desc\n"
	ofile_psv = open( ofilename_psv, "wb" )
	ofile_psv.write( oline_psv )

	ifile_htm = open( ifilename_htm, "r" )
	ofile_htm = open( ofilename_htm, "wb" )
	oline_htm = "<!-- {} {} -->\n".format( ofilename_htm, dttm )
	data_htm = '<div id="div_h5g" >'
	
#	data_htm += '<a href="{}" ><img src="{}" alt="{}" data-description="{}"></a>\n'
#		.format( "./pn/imgs/pano_jtf_entrance_jtf.jpg",
#			"./pn/imgs/pano_jtf_entrance_jtf.jpg",
#			"pano_jtf_entrance",
#			"The storm is raging up above, and waves are dashing high."
#			)

#	data_htm = '<a href="{}" ><img src="{}" alt="{}" data-descriptn="{}"></a>\n'.format( jpg_pathfile, tn_pathfile, jpg_pathfile, jpg_pathfile )
	ofile_htm.write( oline_htm )
	ofile_htm.write( data_htm )
	data_htm=""

	t1=20
#	data_htm = '<a href="{}#t={}" data-poster="{}">'.format( "ka11_avril.mp4", t1, tn_pathfile )
#	data_htm += '<img src="{}" alt="{}" data-description="{}"></a>\n'.format( tn_pathfile, t_pathfile, f_pathfile )
#	data_htm = ""


	ofile_htm.write( oline_htm )


#	oline_tn = "# ko_go_tn.sh end\n"
#	ofile_tn.write( oline_tn )
#	ofile_tn.close()



	for iline in ifile:
		pattern = re.compile( "^#" )
		if( pattern.match(iline) ): continue
		j=j+1
		dttm=kodts('')
		pathfile=iline
		path=os.path.dirname(pathfile)
		base=os.path.basename(pathfile)
		file=os.path.splitext(base)[0]
		ext=os.path.splitext(base)[1]
		filecode_tuple=str(j),"-",file,"-",ext
		filecode = "".join(filecode_tuple)

		if( path == "." ): path="./"
		path_imgs="./imgs/mp4/"
		path_tn="./imgs/mp4/tn/"
		f_pathfile=iline
		t_pathfile=t_pathfile.replace(".//","./",1)


		db3_pathfile="ko_go.db3"
		psv_pathfile="ko_go.psv"
		bsv_pathfile="ko_go.bsv"
		tmp_pathfile="ko_go.tmp"
		print( progid,dttm,"db3={}".format( db3_pathfile ))
		print( progid,dttm,"psv={}".format( psv_pathfile ))
		print( progid,dttm,"bsv={}".format( bsv_pathfile ))
		print( progid,dttm,"tmp={}".format( tmp_pathfile ))
		
		png_pathfile="{}{}".format( path_imgs, t_base )
		png_pathfile=png_pathfile.replace(".mp4", "_mp4.png" )
		png_pathfile_000=png_pathfile.replace("_mp4.png", "_mp4_%00d.png" )

		jpg_pathfile=png_pathfile.replace( ".png", ".jpg" )
		jpg_pathfile_000=png_pathfile_000.replace( ".png", ".jpg" )

		tn_pathfile="{}tn_{}".format( path_tn, t_base )
		tn_pathfile=tn_pathfile.replace(".mp4", "_mp4.png" )


		print( progid,dttm,j,"f_pathfile={}".format( f_pathfile ))
		print( progid,dttm,j,"t_pathfile={}".format( t_pathfile ))
		print( progid,dttm,j,"png_pathfile={}".format( png_pathfile ))
		print( progid,dttm,j,"tn_pathfile={}".format( tn_pathfile ))
		print( progid,dttm,j,"png_pathfile_000={}".format( png_pathfile_000 ))

#		print( progid,dttm,j,"pathfile=",pathfile, path, base,file,ext)
#		print( progid,dttm,j,"filecode_tuple=",filecode_tuple)

#		png_filename="./imgs/mp4/"
#		png_filename+=t_filename.replace(".mp4",".png")

#		tn_filename="./imgs/tn/tn_"
#		tn_filename+=t_filename.replace(".mp4",".png")

#		print( progid,dttm, "ko_go ifile {} {} iline={}".format( ifilename, j, iline ))
#		print( progid,dttm, "ko_go ifile {} {} t_filename={}".format( ifilename, j, t_filename ))
#		print( progid,dttm, "ko_go ifile {} {} png_filename={}".format( ifilename, j, png_filename ))
#		print( progid,dttm, "ko_go ifile {} {} tn_filename={}".format( ifilename, j, tn_filename ))

		if( f_pathfile != t_pathfile ):
			oline_mv = 'mv "{}" {}\n'.format( f_pathfile, t_pathfile )
			ofile_mv.write( oline_mv ) 
			print( progid,dttm, "ko_go_mv ofilename_mv={} j={} oline_mv={}".format( ofilename_mv, j, oline_mv ))

		oline_png = "cp ./imgs/mp4/mp4.png {}\n".format( png_pathfile )
		ofile_png.write( oline_png )
		print( progid,dttm, "ko_go_png ofilename_png={} j={} oline_png={}".format( ofilename_png, j, oline_png ))

		oline_tn = "mogrify -resize x100 -write {} {}\n".format( png_pathfile, tn_pathfile )
		ofile_tn.write( oline_tn )
		print( progid,dttm, "ko_go_tn ofilename_tn={} j={} oline_tn={}".format( ofilename_tn, j, oline_tn ))


#		video_input_path = '/your/video.mp4'
#		img_output_path = '/your/image.jpg'
#		subprocess.call(['ffmpeg', '-i', video_input_path, '-ss', '00:00:00.000', '-vframes', '1', img_output_path]

#		syscmd = "['ffmpeg', '-i', f_pathfile, '-ss', '00:00:00.000', '-vframei', '1', png_pathfile]"

		flag_im = ""
		flag_ffmpeg_seek = ""

		seekpoint=10
#		ffmpeg -y -ss $SEEK_POINT -i input.ogv -vcodec mjpeg -vframes 1 -an -s 120x90 -f rawvideo output.jpg
		ffmpeg_seek_cmd = 'ffmpeg -y -ss {} -i {} -vcodec mjpeg -vframes 1 -an -s 1920x1000 -f rawvideo {}'.format( seekpoint, t_pathfile, jpg_pathfile )
		print( progid,dttm, "ko_go ffmpeg_seek_cmd={}\n".format( ffmpeg_seek_cmd ))
#		subprocess.call( ffmpeg_seek_cmd )
		if( flag_ffmpeg_seek == "yes" ): os.system( ffmpeg_seek_cmd )

		im_cmd='mogrify -resize x100 -write {} {}'.format( tn_pathfile, jpg_pathfile )
		print( progid,dttm, "ko_go im_cmd={}\n".format( im_cmd ))
		if( flag_im == "yes" ): os.system( im_cmd )
#		subprocess.call( im_cmd )
#		os.system( "mogrify  -resize x300 -set filename:name %f  -write './pn/imgs/tn/tn_%[filename:name]' ./pn/imgs/*.jpg" ) 

		data_htm += "\n"
		data_htm += '<a href="{}#t={}" data-poster="{}">'.format( t_pathfile, t1, tn_pathfile )
		data_htm += '<img src="{}" alt="{}" data-description="{}"></a>\n'.format( tn_pathfile, t_pathfile, f_pathfile )

		fps="1/20"
		ffmpeg_cmd = "ffmpeg -y -i {} -vf fps={} {}".format(  f_pathfile, fps, jpg_pathfile_000 )
		print( progid,dttm, "ko_go_ffmpeg ffmpeg_cmd={}\n".format( ffmpeg_cmd ))
#		os.system( ffmpeg_cmd )
#		subprocess.call(['ffmpeg', '-i', f_pathfile, '-ss', '00:00:00.000', '-vframes', '1', png_pathfile ])
#		subprocess.call( ffmpeg_seek_cmd )
#		subprocess.call( ffmpeg_cmd )

#		start_tm=5
#		pil_image = VideoStream('0.flv').get_frame_at_sec(5).image()
#		pil_image.save('frame5sec.jpeg')
#		pil_image = VideoStream(f_pathfile ).get_frame_at_sec(start_tm).image()
#		pil_image.save(png_filepath)


	ifile.close()

	ofile_htm.write( data_htm )
#	data_htm = "	</div>"
#	ofile_htm.write( data_htm )
	ofile_htm.close()

	ofile_mv.write( oline_mv )
	oline_mv = "# ko_go_mv.sh end\n"
	ofile_mv.write( oline_mv )
	ofile_mv.close()

	ofile_png.write( oline_png )
	oline_png = "# ko_go_png.sh end\n"
	ofile_png.write( oline_png )
	ofile_png.close()

	ofile_tn.write( oline_tn )
	oline_tn = "# ko_go_tn.sh end\n"
	ofile_tn.write( oline_tn )
	ofile_tn.close()

	ifilename = "ka1_h5g.html"
	ofilename = "ka1_h5g_out.html"
	ifile = open( ifilename, "r" )
	ofile = open( ofilename, "wb" )

	print( dttm, "ifilename=",ifilename, " ofilename=", ofilename	)
	ka1_sl_html_hdr = ""
	ka1_sl_html_dta = ""
	ka1_sl_html_ftr = ""
	j=0
	mode="hdr"
	for line in ifile:
		out="ko_go {} {} {}\n".format( ifilename, j, line )
		print( out)
		j=j+1
# err		if line.match('div_sl_images" ): break
#		if line == 'div_sl_images': 

		if re.search( 'id="div_h5g"', line ):
			mode = "dta"
			ofile.write( line )
			ofile.write( data_htm )
		else:
			ofile.write( line )
	ifile.close()
	ofile.close()
	return( "ko_go")

#	ifile = open(ifilename, "wb" )
#	for line in ifile:
#		print( progid,dttm, "ko_go ifile line={}".format( line ))
#	ifile.read

#	for pathfile in pathfiles:
#		j=j+1
#		dttm=kodts('')
#		path=os.path.dirname(pathfile)
#		base=os.path.basename(pathfile)
#		file=os.path.splitext(base)[0]
#		ext=os.path.splitext(base)[1]
#		filecode_tuple=str(j),"-",file,"-",ext
#		filecode = "".join(filecode_tuple)
#		print( progid,dttm,j,"pathfile=",pathfile, path, base,file,ext)
#		print( progid,dttm,j,"filecode=",filecode)
#		print( progid,dttm,j,"filecode_tuple=",filecode_tuple)
#
#		b64dta=""
#		if( not os.path.isfile( pathfile )):	
#
#
#			filesize = os.path.getsize(pathfile)
#			ctime=time.ctime(os.path.getctime(pathfile))
#			ctime_ymd = time.strftime('%Y-%m-%d_%H:%M:%S', time.gmtime(os.path.getmtime(pathfile)))
#
#			print( progid,dttm,j,"ctime_ymd=",ctime_ymd,filesize,pathfile)
#	files=os.system( syscmd )
#	print( progid,dttm, "ko_im syscmd={}".format( files ))
	return( "ko_go" );


	syscmd="mkdir {}/tn".format( pathfile )
	print( progid,dttm, "ko_im syscmd{}".format( syscmd ))
#	os.system( syscmd )

	syscmd="mogrify  -resize x300 -set filename:name %f  -write '{}/tn/tn_%[filename:name]' {}".format( pathfile, pathfile )
	print( progid,dttm, "ko_im syscmd{}".format( syscmd ))
#	os.system( syscmd )
	os.system( "mogrify  -resize x300 -set filename:name %f  -write './pn/imgs/tn/tn_%[filename:name]' ./pn/imgs/*.jpg" ) 

	exit()

	print( progid,dttm,"ko_im syscmd={}".format( syscmd ))
	os.system( syscmd )


#	my_date = datetime.date(*[int(i) for i in string_date.split("-")])
#	from subprocess import call
#	call(["ls", "-l" )
#	os.system( "ls -lat /Volumes/ka1tbr2/ht/imgs/links/*.*" )
#	print( subprocess.Popen("echo Hello World", shell=True, stdout=subprocess.PIPE).stdout.read(	)
#	return_code = subprocess.call("echo Hello World", shell=True) 
	return("ko_im_return");


def splitgift(delimiters, string, maxsplit=0):
#	import re
	regexPattern = '|'.join(map(re.escape, delimiters))
	return re.split(regexPattern, string, maxsplit)

def kocmd(command):
	process = Popen(
		args=command,
		stdout=PIPE,
		shell=True
		)
	return process.communicate()[0]

def cmdline(command):
	process = Popen(
		args=command,
		stdout=PIPE,
		shell=True
		)
	return process.communicate()[0]

def gif2gifs(gif):

	print( "{} {} gif1={} ".format( progid, dttm, gif ))
	j=0
	gif_path=os.path.dirname(gif)
	gif_base=os.path.basename(gif)
	gif_file=os.path.splitext(gif_base)[0]
	gif_ext=os.path.splitext(gif_base)[1].replace(".","")
	giftags = "b d p q".split(" ")
	g=0
	for giftag in giftags:
		g=g+1
		newgif = "{}/{}{}.{}".format(gif_path, gif_file, giftag, gif_ext)
		newpngs = "{}/{}{}.png".format( gif_path, gif_file, giftag )
		print( "BUGS_1650 gif2gifs g={} newgif = {}\n".format(g, newgif))

		if( giftag == "d" ) or (giftag == "q" ):
			convert_negate = "convert {} -negate {}".format( gif, newgif )
			print( "gif2gifs NEGATE-d g={} convert_negate={}\n".format( g, convert_negate ))
			os.system( convert_negate )
		else:
			cp_newgif = "cp {} {}".format( gif, newgif )
			print( "gif2gifs g={} cp_newgif={}\n".format( g, cp_newgif ))
			os.system( cp_newgif )

		print( "BUGS_1660 gif2gifs g={} newgif = {}\n".format(g, newgif))
		if( giftag == "p" ) or ( giftag == "d" ):

			convert_gif2pngs = "convert {} {}".format(newgif, newpngs )
			print( "BUGS_1670 gif2gifs g={} convert_gif2pngs={}\n".format( g, convert_gif2pngs ))
			os.system( convert_gif2pngs )

			ls_pngs = "ls -lat {}/*.png".format( gif_path )

			lines = cmdline(ls_pngs).split('\n')
			pnglen = len(lines)
			print( "BUGS_1670 line={} pnglen={}\rn".format( lines, pnglen ))

		
			p=0
			r=pnglen-p-2
			pngs = ""
			for line in lines:
				r=pnglen-p-2
				lslen=len(line.split(" "))
				lsnam=line.split(" ")[lslen-1]
				png_file = gif_file
				pngnam = "{}/{}{}-{}.png".format(gif_path, png_file, giftag, r )
				if( p < pnglen-1 ):
					pngs += "{} ".format(pngnam)
#				print( "BUGS_1671 pnglen={} p={} r={}".format( pnglen, p, r))
#				print( "BUGS_1672 pnglen={} p={} r={} pngnam={}".format(pnglen,p,r,pngnam))
#				print( "BUGS_1673 lsnam={}\n".format(lsnam))
				p=p+1

			convert_pngs2gif = "convert {} {}".format( pngs, newgif )
			print( "BUGS_1680 pnglen={} convert_pngs2gif={}\n".format( pnglen, convert_pngs2gif ))
			os.system( convert_pngs2gif )
#			print( "BUGS_1680 pnglen={} ls_png={}\n".format( pnglen, ls_png ))



#			print( "BUGS_1681 ls_pngs={} pnglen=\n{}\n".format( ls_pngs, pnglen ))
#			print( "BUGS_1682 ls_pngs={} lines=\n{}\n".format( ls_pngs, lines ))


#			pnglen=0
#			r=0
#			for line in lines:
#				png_file = line.split("-")[0]
#				newpng = "{}/{}-{}.png".format(gif_path, png_file, pnum )	
#				pnum=pnglen+1
#				print( "BUGS_1682 pgnlen={} pnum={} line={}\n".format(pnglen, line ))
#				print( "BUGS_1682 pnglen={} line={}\n".format(pnglen, line ))
#			print( "BUGS_1681 PNGLEN ls_pngs={} pnglen={}\n".format( ls_pngs, pnglen ))
#			exit()


#			print( cmdline(lslat_pngs))
#			print( "BUGS_1682 lslat_pngs={} cmdout={}\n".format( lslat_pngs, cmdout ))
#			print( cmdline('ls -lat imgs/ani/work/ring/*.gif'))
##			print( "BUGS_1683 ls -lat *.gif={} cmdout={}\n".format( cmdout ))
##			print( "BUGS_16950 gif2gifs g={} ls_pngs={} pngs0={}\n".format( g, ls_pngs, pngs.split("\n") ))
##			print( "BUGS_16951 gif2gifs g={} ls_pngs={} pngs1={}\n".format( g, ls_pngs, pngs.split("\n") ))
##			print( "BUGS_16952 gif2gifs g={} ls_pngs={} pngs2={}\n".format( g, ls_pngs, pngs.split("\n") ))
	
			rm_pngs = "rm {}/{}{}-*.png".format( gif_path, gif_file, giftag )
			print( "gif2gifs g={} rm_pngs={}\n".format( g, rm_pngs ))
			os.system( rm_pngs )


		btnpath="imgs/gif/"
		cp_newgif = "cp {} {}".format( newgif, btnpath )
		print( "gif2gifs g={} cp_newgif={}\n".format( g, cp_newgif ))
		os.system( cp_newgif )

#		delays = "1 5 10 100"
		delays = "1 2 3 4 5 6 7 8 9 10 20 30 40 50 70 80 90 100"
		for delay in delays.split(" "):
			newgif_delay = "{}/{}{}_{}.gif".format( gif_path, gif_file, giftag, delay )
			convert_delay = "convert -delay {} {} {}".format( delay, newgif, newgif_delay )
#			print( "BUGS_1730 delay={} newgif={}".format(delay, newgif))
#			print( "BUGS_1730 convert_delay={}".format( convert_delay ))
			os.system( convert_delay )

			btnpath="imgs/gif/"
			cp_newgif_delay = "cp {} {}".format( newgif_delay, btnpath )
			print( "gif2gifs cp_newgif={}\n".format( cp_newgif_delay ))
			os.system( cp_newgif )


def png2gif(gif,png):


	png="imgs/ani/work/heart/koeye.png"
	gif="imgs/ani/work/heart/heart.gif"
	print( "{} {} png2gif png={} gif={}".format( progid, dttm, png, gif ))

	gif_path=os.path.dirname(gif)
	gif_base=os.path.basename(gif)
	gif_file=os.path.splitext(gif_base)[0]
	gif_ext=os.path.splitext(gif_base)[1].replace(".","")


	png_path=os.path.dirname(png)
	png_base=os.path.basename(png)
	png_file=os.path.splitext(png_base)[0]
	png_ext=os.path.splitext(png_base)[1].replace(".","")
	btn_path="imgs/gif"


	

	newgif = "{}/{}_{}.gif"
	w=200
	h=80
	x=0
	y=0
	pngtag = "koeye"
	newgif = "{}/{}_{}.gif".format( gif_path, png_file, gif_file )
	newbtn = "{}/{}_{}.gif".format( btn_path, png_file, gif_file )

#	print( "new_png\n pngi={}\n gifi={}\n".format( pngi, gifi ))
	for size in "100x40 200x80 400x160".split(" "):
		pngi = "{}/{}{}.png\n".format( gif_path, png_file, size.split("x")[0] )
		gifi = "{}/{}{}.gif\n".format( gif_path, gif_file, size.split("x")[0] )

#		im_pngsize = "convert {} -size {} {}".format( png, size, pngi )
#		print( "im_pngsize={}".format(im_pngsize))
#		os.system( im_pngsize )

#		im_gifsize = "convert {} -size {} {}".format( gif, size, gifi )
#		print( "im_gifsize={}".format(im_gifsize))
#		os.system( im_gifsize )
		
		w=size.split("x")[0]
		h=size.split("x")[1]
		y=0

		for x in "0 50 100 150".split( " " ):
			gifo = "{}/{}_{}{}_{}.gif".format( gif_path, png_file, gif_file, size.split("x")[0], x )

			im_png2gif = "composite  {} {} -compose Dst_Over -geometry {}x{}+{}+{} {}".format( pngi, gifi, w,h,x,y, gifo )
			im_png2gif = "convert  {} -coalese -draw 'image over {},{} {},{}' {} -composite {}".format( gifi, w,h,x,y, pngi, gifo )
			img_png2gif = "convert {} -draw 'image over 0,0 {},0' {} -composite {}".format( gifi, x, pngi, gifo) 
			print( "im_png2gif={}".format(im_png2gif))
			os.system( im_png2gif )

# convert heart200.gif \( koeye200.png -repage 0x0+120+0 \)  heartk200_120.gif

	exit()
			

# convert script_k.gif -coalesce  coalesced_k.gif
# convert coalesced_k.gif  -background black -shadow 100x3+2+5 \
#          -background SkyBlue -alpha remove    shadows_k.gif
# convert shadows_k.gif  null:  coalesced_k.gif \
#          -layers Composite          compose_shadow.gif
#  gif_anim_montage compose_shadow.gif compose_shadow_frames.gif		


#	composite -compose Dst_Over -geometry 520x320+20+80 image.jpeg overlay.png final.pnconvert animation.gif -coalesce -gravity NorthEast -draw 'image over 0,0 0,0 "transparent-watermark.png"' -layers Optimize final.gifg
#	convert animation.gif -coalesce -gravity NorthEast -draw 'image over 0,0 0,0 "transparent-watermark.png"' -layers Optimize final.gif
	im_png2gif = 'convert {} -coalesce -gravity NorthEast -draw \'image over 0,0 0,0 "{}"\' -layers Optimize {}'.format( gif, png, newgif )
	im_png2btn = 'convert {} -coalesce -gravity NorthEast -draw \'image over 0,0 50,50 "{}"\' -layers Optimize {}'.format( gif, png, newbtn )

	im_png2gif1 = "composite -compose Dst_Over -geometry {}x{}+{}+{} {} {} {}".format( w,h,x,y,png,gif,newgif)
	im_png2btn1 = "composite -compose Dst_Over -geometry {}x{}+{}+{} {} {} {}".format( w,h,x,y,png,gif,newbtn)

	print( "png2gif NEWGIF im_png2gif={}\n".format(im_png2gif))
	print( "png2gif NEWBTN im_png2gif={}\n".format(im_png2gif))
	os.system( im_png2gif )
	os.system( im_png2btn )

#	 convert -dispose none -channel RGBA \
#	          \( medical.gif -repage 100x60+5+14  -coalesce -set delay 100 \) \
#	          \( medical.gif -repage 100x44+34+6  -coalesce -set delay 10 \
#	             -motion-blur 0x12+0  -motion-blur 0x12+180 -wave -8x200 \) \
#	          \( medical.gif -repage 100x60+63+14 -coalesce -set delay 100 \) \
#	          \( medical.gif -repage 100x44+34+6  -coalesce -set delay 10 \
#	             -motion-blur 0x12+0  -motion-blur 0x12+180 -wave +8x200 \) \
#	          null: \( +page  -size 120x15 xc:SkyBlue xc:RoyalBlue \
#	                   -size 120x70 gradient:SkyBlue-RoyalBlue \
#	                   +swap -append -blur 0x3 -background white -rotate -25 \
#	                \) -gravity center -compose DstOver -layers Composite \
#	          -loop 0   speed.miff
#	
#	  convert   speed.miff  speed.gif
#	  gif_anim_montage  speed.gif  speed_frames.gif


	exit()


def load_gifs():
	gifs = (

'imgs/ani/work/penny.gif',
'imgs/ani/work/apple.gif',
'imgs/ani/work/rings.gif',
'imgs/ani/work/bh.gif',
'imgs/ani/work/dollars.gif',
'imgs/ani/work/eye1.gif',
'imgs/ani/work/eye2.gif',
'imgs/ani/work/eye3.gif',
'imgs/ani/work/film.gif',
'imgs/ani/work/firebubbles.gif',
'imgs/ani/work/firework.gif',
'imgs/ani/work/geard2.gif',
'imgs/ani/work/gears2.gif',
'imgs/ani/work/header.gif',
'imgs/ani/work/heart.gif',
'imgs/ani/work/knot.gif',
'imgs/ani/work/laser1.gif',
'imgs/ani/work/laser2.gif',
'imgs/ani/work/laser3.gif',
'imgs/ani/work/meterbars.gif',
'imgs/ani/work/meterdots.gif',
'imgs/ani/work/rotate.gif',
'imgs/ani/work/soccorball.gif',
'imgs/ani/work/sun.gif',
'imgs/ani/work/taz.gif',
'imgs/ani/work/trcx_sxygirl_b1.gif',
'imgs/ani/work/trcx_sxygirl_b2.gif',
'imgs/ani/work/trcx_sxygirl_b3.gif',
'imgs/ani/work/trcx_sxygirl_kick.gif',
'imgs/ani/work/trcx_sxygirl_l.gif',
'imgs/ani/work/trcx_sxygirl_w2.gif',
'imgs/ani/work/trcx_sxygirl_w3.gif',
'imgs/ani/work/trcx_szygirl_b4.gif',
'imgs/ani/work/trophy.gif',
'imgs/ani/work/warning.gif',
'imgs/ani/work/welcome.gif',
'imgs/ani/work/worksign.gif'
	)
	return(gifs)





def gif2pngs(gif):
	pngs = ""

	pngs = (
'imgs/ani/work/ring/ring1-0.png',
'imgs/ani/work/ring/ring1-1.png',
'imgs/ani/work/ring/ring1-2.png',
'imgs/ani/work/ring/ring1-3.png',
'imgs/ani/work/ring/ring1-4.png',
'imgs/ani/work/ring/ring1-5.png',
'imgs/ani/work/ring/ring1-6.png',
'imgs/ani/work/ring/ring1-7.png',
'imgs/ani/work/ring/ring1-8.png',
'imgs/ani/work/ring/ring1-9.png',
'imgs/ani/work/ring/ring1-10.png',
'imgs/ani/work/ring/ring1-11.png',
'imgs/ani/work/ring/ring1-12.png',
'imgs/ani/work/ring/ring1-13.png',
'imgs/ani/work/ring/ring1-14.png',
'imgs/ani/work/ring/ring1-15.png',
'imgs/ani/work/ring/ring1-16.png',
'imgs/ani/work/ring/ring1-17.png'
	)
	
#	print( "gif2pngs gif={} path={} base={} file={} ext={}".format( gif,path,base,file,ext))
#	print( "gif2pngs pngs={} ".format( pngs))
	return(pngs)

	gifs = (
"imgs/ani/work/heart.gif|/imgs/btn/koeye.png|koeye_heart.gif"
"imgs/ani/work/ring.gif|imgs/btn/ringb.gif"
"imgs/ani/work/ring.gif|imgs/btn/ringw.gif"
"imgs/ani/work/ring.gif|imgs/btn/ringbl.gif"
"imgs/ani/work/ring.gif|imgs/btn/ringbr.gif"
"imgs/ani/work/ring.gif|imgs/btn/ringwl.gif"
"imgs/ani/work/ring.gif|imgs/btn/ringwr.gif"
"imgs/ani/work/eyeball1.gif|/imgs/btn/koeye.png|koeye_eyeball1.gif",
"imgs/ani/work/eyeball2.gif|/imgs/btn/koeye.png|koeye_eyeball2.gif",
"imgs/ani/work/eyeball3.gif|/imgs/btn/koeye.png|koeye_eyeball3.gif",
"imgs/ani/work/penny.gif|koeye.png|koeye_penny.gif",
"imgs/ani/work/dollar.gif|koeye.png|koeye_dollar.gif",
"imgs/ani/work/rainbow.gifi|/imgs/btn/koeye.png|koeye_laser_rainbow.gif"
	)
	return( gifs )


def filio(pathfile,filid ):
	wl_file = open( pathfile, "r" )
	htmout = ""
	linematch_beg = "jkwii"
	linematch_end = "skwii"
	linematch_txt = "<h1>{}</h1>\n".format( filid )
	j=0
	for line in wl_file:
		j=j+1
		f_file=line
		t_file=pathfile_fmt(f_file)
#		print( "pathfile={} j={} line={}".format(pathfile,j,line))
		newtxt = ""
		newtxt = "	<h1>{}</h1>\n".format(filid)
		if re.search( linematch_beg, line ):
			mode = "match"
			continue
		if re.search( linematch_end, line ):
			mode = ""
			htmout += linematch_txt
			htmout += line
		htmout += line
#		print( progid,dttm, "filio pathfile={} {} {}".format( pathfile,j,line ))

	wl_file.close
	return(htmout)



def htms2htm( path ):
#	path="/svc/jqgrid"
	img = "/imgs/btn/kob.png"
	tn = "/imgs/btn/kow.png"
#	old_pathfile = "{}/{}".format(path,htmid)
	new_pathfile = "jqgrid.html"

	htmids = load_htmids()
	print( '{} {} htms2htm htmids={}'.format( progid, dttm, htmids))

	k=0
	htmout_links=""
	htmout_body=""
	for htmid in htmids:
		k=k+1
		filtxt = "";
		url= "";
		url = "{}/{}.html".format( path, htmid )
		htm_pathfile="{}/{}.html".format( path, htmid)
		filtxt = filio(htm_pathfile,htmid )
		
#		print( '{} {} k={} phps2php htm_pathfile={} htmid={}'.format( progid, dttm, k,htm_pathfile, htmid))
#		print( '{} {} k={} phps2php filtxt={} htmid={}'.format( progid, dttm, k, filtxt, htmid))

		htmout_links += '<a class="popover" href={} target=_blank>\n'.format( url )
		htmout_links += '	<img src="{}" border=0 onclick="htmid();">\n'.format(tn,htmid)
		htmout_links += '	<span><img src="{}" border=0 onclick="htmid()\n">'.format(img,htmid)
		htmout_links += '	</a>\n';

		htmout_body += '	<div id="jqgrid_{}" >\n'.format( htmid )
		htmout_body += '		<h1> jqgrid_{}</h1 >\n'.format( htmid )
		htmout_body += filtxt
		htmout_body += '		</div>'

	htmout = ""
	htmout += "<html><head>\n"
	htmout += "	<title>jqgrid</title>\n"
	htmout += htmcss_popover('ko')
	htmout += "	</head>\n"
	htmout += "<body>\n"
	htmout += htmout_links
	htmout += htmout_body
	htmout += "	</body\n"
	htmout += "	</html\n"

	newfil = open( new_pathfile, "w" )
	newfil.write(htmout)

	print( '{} {} k={} phps2php htmout_links={}'.format( progid, dttm, k, htmout_links))
	print( '{} {} k={} phps2php htmout_body={}'.format( progid, dttm, k, htmout_body))
	newfil.close()


	return(htmout)

def load_phpids():
	phpids = (
"example",
"someurl",
"bigset",
"search",
"subgrid",
"dbconfig",
"server",
"editing",
"server_ado",
"JSON"
	)
	return( phpids )


def phps2php( path ):
	path="svc/jqgrid"
	phpids = load_phpids()
	print( '{} {} phps2php phpids={}'.format( progid, dttm, phpids))
	phpids_len=len(phpids)
	print( '{} {} len={}  phpids={}'.format( progid, dttm,phpids_len, phpids ))

	j=0
	phpout=""
	for phpid in phpids:
		j=j+1
		print( '{} {} j={} phps2php phpid={}'.format( progid, dttm, j, phpid))
		continue
	return(phpout)
	
def load_htmids():
	htmids = (
		"adding", "afterinsrow", "bigset", 
		"calendar", "celledit", "cmultiex", "csvalid", "custbutt", "custfrm",
		"datatype", "defparams", "deleting", "demo", "editing",
		"example", "exportex", "formatter", "getex", "gridwidth",
		"hiddengrid", "hidedyn", "hideex", "hideshow", "jqgrid",
		"jsonex", "jsonmap", "jsonopt", "jsubgrid",
		"loadcml", "loaderror", "loadoncex", "localex", 
		"manipex", "masterex", "methods", "methods32", "multiex", "navgrid", "navgrid2", "postdata", 
		"refactor", "resizecol", "resizeex", 
		"rowedex1", "rowedex2", "rowedex3", "rowedex4", "rowedex5",
		"scrgrid", "search1", "search2", "searching", "selectall", "setcolumns", 
		"setex", "subgrid", "subgrid_grid",
		"tbltogrid", "toolbar", "treegrid", "treegrid2",
		"xmlex", "xmlimp", "xmlmap"
		)
	return(htmids)

def newhtm( htmids ):
	print( '{} {} newhtm htmids={}'.format( progid, dttm, htmids ))

#	htmids_txt=re.split( " ", htmids)
#	htmids_csv=re.split( ",", htmids)
#	htmids_psv=re.split( "|", htmids)
#	htmids_txtlen=len(htmids_txt)
#	htmids_csvlen=len(htmids_csv)
#	htmids_psvlen=len(htmids_psv)
#	htmidss = re.split('; |, |\*|\n', htmids)
#	splitgift(delimiters, htmids, maxsplit=0):

	htmidss = splitgift('; |, |\*|\n\ ', htmids, maxsplit=0)

	htmidss_len = len( htmidss )
	fmt='txt'

	print( '{} {} newhtm htmidss={}'.format( progid, dttm, htmidss))
#	print( '{} {} newhtm htmids={}'.format( progid, dttm, htmids))
#	print( '{} {} newhtm htmids_txt={}'.format( progid, dttm, htmids_txt))
#	print( '{} {} newhtm htmids_csv={}'.format( progid, dttm, htmids_csv))
#	print( '{} {} newhtm htmids_psv={}'.format( progid, dttm, htmids_psv))
	print( '{} {} newhtm len spl={}'.format( progid, dttm, htmidss_len ))
	z=0
	print( '{} {} len={} z={} newhtm htmidss={}'.format( progid, dttm,htmidss_len, z, htmidss ))
	for htmid in htmidss:
		z=z+1
		print( '{} {} z={} newhtm htmid={}'.format( progid, dttm, z, htmid))
		continue
		htmout = ""
		htmout += '<html>\n'
		htmout += '	<head>\n'
		htmout += '	<title>-= {} =- -= {} =- -= {} =-</title>\n'.format( progid, htmid, dttm )
		htmout += '		</title>\n'
		htmout += '		</head>\n'
		htmout += '<body onload="startup">>\n'
		htmout += '	<div id="div_{}" >\n'.format( htmid )
		htmout += '	<h1>{}</h1>'.format( htmid )
		htmout += '	<	/div id="div_{}_end">\n'.format( htmid )
		htmout += '	</body>\n'
		htmout += '	</html>\n'
	return(htmout)
	
	

def pathfile_fmt(f_pathfile):

	path=os.path.dirname(f_pathfile)
	base=os.path.basename(f_pathfile)
	file=os.path.splitext(base)[0]
	ext=os.path.splitext(base)[1]

	t_pathfile=f_pathfile.replace( "\n", "" )
	t_base=base
#	t_filename=iline.replace(" ", "_").replace("#","_").replace("/","-").replace("-","",1).lower().replace("#","")
	t_base=t_base.lower()
	t_base=t_base.replace( "\n", "" )
	t_base=t_base.replace(" ", "_")
	t_base=t_base.replace("#","_")
#	t_base=t_base.replace("/","-")
	t_base=t_base.replace("-","",1)
	t_base=t_base.replace("#","")
	t_base=t_base.replace(":","_")
	t_base=t_base.replace("_pm","")
	t_base=t_base.replace("_am","")
	t_base=t_base.replace("(","")
	t_base=t_base.replace(")","")
	t_base=t_base.replace("&","")
	t_base=t_base.replace("'","")
	t_base=t_base.replace("+","")
	t_base=t_base.replace("~","")
	t_base=t_base.replace("__","_")
	t_base=t_base.replace("__","_")
	t_base=t_base.replace("--","-")
	t_base=t_base.replace("--","-")
	t_pathfile="{}/{}".format( path, t_base )
	return(t_pathfile)

def load_uslist():
	uslist = [
#		"/us/med/kov_rechtin.html|/imgs/us/med_rechtin.png|med_rechtin|/imgs/btn/koeye.png|med",
#		"http://lawdonovan.com|/imgs/us/law_donovan.png|law_donovan|/imgs/btn/koeye.png|law",
		"http://nathanscohen.com/|/imgs/us/law_cohen_nathan_s.png|law__cohen_nathan_s|/imgs/btn/koeye.png|law",

		"https://www.linkedin.com/in/alan-cohen-2314473b/|/imgs/us/law_cohen_alan_w.png|law__cohen_alan_w|/imgs/btn/koeye.png|law",
		"https://twitter.com/AlanWCohenEsq|/imgs/us/cohen_alan_w_twitter.png|cohen_alan_w_twitter|/imgs/btn/koeye.png|law",
		"http://www.primerus.com/attorneys/alexander-h-kuehling-esq-rosenblum-goldenhersh-st-louis-missouri-mo.htm|/imgs/us/law_kuehling_alexander.png|law_law_kuehling_alexander|/imgs/btn/koeye.png|law",
		"http://elsterlaw.com/henry-elster-attorney-missouri-best/|/imgs/us/law_elster_henry.png|law_elster_henry|/imgs/btn/koeye.png|law",
		"https://pview.findlaw.com/view/2830721_1|/imgs/us/law_walters_alan.png|law_walters_alan|/imgs/btn/koeye.png|law",
		"https://www.thompsoncoburn.com/|/imgs/us/law_thompson_coburn.png|law__thompson_coburn|/imgs/btn/koeye.png|law",
		"http://koreintillery.com/|/imgs/us/law_korein_tillery.png|law_korein_tillery|/imgs/btn/koeye.png|law",
		"http://www.smithbrownllc.com/|/imgs/us/law_smith_brown.png|law_smith_brown|/imgs/btn/koeye.png|law",
		"http://www.fdazol.com/|/imgs/us/law_azol.png|law_azol_f|/imgs/btn/koeye.png|law",

		"https://jmhalumni.com|/imgs/us/jmhalumni.png|ed_jmhalumni|/imgs/btn/koeye.png|edu",
		"https://johnmarshallhighschool.com|/imgs/us/johnmarshallhighschool.png|ed_johnmarshallhighschool|/imgs/btn/koeye.png|edu",
		"https://www.greatschools.org/kentucky/brandenburg/1993-Brandenburg-High-School/|/imgs/us/brandenburg_highschool.png|ed_brandenburg-highschool|/imgs/btn/koeye.png|edu",
		"https://www.hazelwoodschools.org/Page/3143|/imgs/us/hazelwood_schools.png|ed_hazelwood_schools|/imgs/btn/koeye.png|edu",
		"https://bw.edu|/imgs/us/bw.png|ed_bw|/imgs/btn/koeye.png|edu",

		"http://oldtowndonuts.com|/imgs/us/oldtowndonuts.png|food_oldtowndonuts|/imgs/btn/koeye.png|food",
		"http://farkaspastries.com|/imgs/us/farkaspastries.png|food_farkaspastries|/imgs/btn/koeye.png|food",
		"https://www.facebook.com/HansaImportHouse|/imgs/us/hansaimporthouse.png|food_hansaimporthouse|/imgs/btn/koeye.png|food",
		"http://havanagrillco.com|/imgs/us/havanagrillco.png|food_havanagrillco|/imgs/btn/koeye.png|food",
		"http://spiros-restaurant.com|/imgs/us/spiros_restaurant.png|food_spiros_restaurant|/imgs/btn/koeye.png|food",
		"https://www.opentable.com/jake-and-tellys-greek-taverna?page=1|/imgs/us/food_jake_tellys.png|food_jake_tellys|/imgs/btn/koeye.png|food",
		"http://edelweissrest.com|/imgs/us/edelweissrest.png|food_edelweissrest|/imgs/btn/koeye.png|food",
		"http://bierwerks.com|/imgs/us/food_bierwerks.png|food_bierwerks|/imgs/btn/koeye.png|food",
		"http://www.savellispizzapastasubs.com/|/imgs/us/food_savellispizza.png|food_savellispizza|/imgs/bmtn/koeye.png|food",
		"https://www.facebook.com/woohoogreekfood2/|/imgs/us/woohoogreekfood2.png|food_woohoogreekfood2|/imgs/btn/koeye.png|food",

		"https://bdo.com/about/us-locations/bdo-st-louis|/imgs/us/bdo-stl.png|acct_bdo-stl|/imgs/btn/koeye.png|fin",
		"https://bdo.com/about/us-locations/bdo-cleveland-office|/imgs/us/bdo-cle.png|acct_bdo-cle|/imgs/btn/koeye.png|fin",
		"http://www.gatewayloan.com/|/imgs/us/gateway_mortgage.png|gateway_mortgage|/imgs/btn/koeye.png|fin",
		"https://chesonsulting.com|/imgs/us/checonsulting.png|biz_checonsulting|/imgs/btn/koeye.png|biz",
		"http://saic.com|/imgs/us/saic.png|saic|/imgs/btn/koeye.png|biz",
		"http://leidos.com|/imgs/us/leidos.png|leidos|/imgs/btn/koeye.png|biz",


		"http://ko2.us/index_focus.com|/imgs/us/focus_solutions.png|focus_solutions|/imgs/btn/koeye.png|biz",
		"http://www.finduslocal.com/hardware-stores/kentucky/brandenburg/allens-s-t-hardware-inc|/imgs/us/biz_allens_hardware.png|biz_allens_hardware|/imgs/btn/koeye.png|biz",
		"http://growwarehouse.com|/imgs/us/grow_warehouse.png|grow_warehouse|/imgs/btn/koeye.png|biz",
		"https://www.facebook.com/avondanceandmartialarts|/imgs/us/avondanceandmartialarts.png|avondanceandmartialarts|/imgs/btn/koeye.png|phy",
		"https://www.facebook.com/avondanceandmartialarts|/imgs/us/avondanceandmartialarts.png|avondanceandmartialarts|/imgs/btn/koeye.png|phy",
		"http://www.savellidanceandmartialarts.com/?load=html|/imgs/us/savelli_dance_martialarts.png|savelli_dance_martialarts|/imgs/btn/koeye.png|phy",
		"http://myfusiondance.com/?load=html|/imgs/us/fusion_dance.png|fusion_dance|/imgs/btn/koeye.png|phy",
		"http://www.superseriesbaseball.com/|/imgs/us/super_series_baseball.png|super_series_baseball|/imgs/btn/koeye.png|phy",

		"https://ftknox.afceachapters.org/|/imgs/us/afcea_knox.png|afcea_knox|/imgs/btn/koeye.png|org",
		"https://scott.afceachapters.org/|/imgs/us/afcea_scott.png|afcea_scott|/imgs/btn/koeye.png|org",
		"https://www.ble-t.org/|/imgs/us/ble.png|ble|/imgs/btn/koeye.png|org",
		"http://www.doevalley.org/|/imgs/us/doe_valley.png|doe_valley|/imgs/btn/koeye.png|org",

		"http://www.chapelofthecross.org/|/imgs/us/chapel_of_the_cross.png|chapel_of_the_cross|/imgs/btn/koeye.png|rel",
		"https://www.lds.org/temples/details/st.-louis-missouri-temple|/imgs/us/lds_stl.png|lds_stl|/imgs/btn/koeye.png|rel",
		"https://www.bethanyenglish.org/|/imgs/us/bethany_english_lutheran.png|bethany_english_lutheran|/imgs/btn/koeye.png|rel",
		"https://www.meadecountymessenger.com/|/imgs/us/meade_county_messenger.png|meade_county_messenger|/imgs/btn/koeye.png|media",
		"/index_byrdpucker.html|/imgs/us/byrdpucker.png|byrdpucker|/imgs/btn/koeye.png|byrdpucker",
		"/index_jtfinc.html|/imgs/us/jtfinc.png|jtfinc|/imgs/btn/koeye.png|jtfinc",
		"/index_jtfdc.html|/imgs/us/jtfdc.png|jtfdcr|/imgs/btn/koeye.png|jtfdc",
		"/index_jtfdcr.html|/imgs/us/jtfdcr.png|jtfdcr|/imgs/btn/koeye.png|jtfdcr",
		"/index_jtfdcr.html|/imgs/us/jtfdcr.png|jtfdcr|/imgs/btn/koeye.png|jtfdcr",
		"https://mars.jpl.nasa.gov/msl/multimedia/raw/?s=#/?slide=2088|/imgs/us/mars_jpl_nasa.png|mars_jpl_nasa|/imgs/btn/koeye.png|sci",
		"https://mars.nasa.gov/mer/gallery/all/opportunity.html|/imgs/us/mars_nasa_gov.png|mars_nasa_gov|/imgs/btn/koeye.png|sci",
		]
	return(uslist)


def load_uslaws ():
	uslaws = [
		"http://lawdonovan.com|/imgs/us/lawdonovan.png|law_donovan|/imgs/btn/koeye.png|law",
		"http://lawdonovan.com|/imgs/us/law_donovan.png|law_donovan|/imgs/btn/koeye.png|law",
		"http://nathanscohen.com/|/imgs/us/law_cohen_nathan_s.png|law__cohen_nathan_s|/imgs/btn/koeye.png|law",
		"https://www.linkedin.com/in/alan-cohen-2314473b/|/imgs/us/law_cohen_alan_w.png|law__cohen_alan_w|/imgs/btn/koeye.png|law",
		"https://twitter.com/AlanWCohenEsq|/imgs/us/law_cohen_alan_w_twitter.png|cohen_alan_w_twitter|/imgs/btn/koeye.png|law",
		"https://twitter.com/AlanWCohenEsq|/imgs/us/cohen_alan_w_twitter.png|cohen_alan_w_twitter|/imgs/btn/koeye.png|law",
		"http://www.primerus.com/attorneys/alexander-h-kuehling-esq-rosenblum-goldenhersh-st-louis-missouri-mo.htm|/imgs/us/law_kuehling_alexander.png|law_law_kuehling_alexander|/imgs/btn/koeye.png|law",
		"http://elsterlaw.com/henry-elster-attorney-missouri-best/|/imgs/us/law_elster_henry.png|law_elster_henry|/imgs/btn/koeye.png|law",
		"https://pview.findlaw.com/view/2830721_1|/imgs/us/law_walters_alan.png|law_walters_alan|/imgs/btn/koeye.png|law",
		"https://www.thompsoncoburn.com/|/imgs/us/law_thompson_coburn.png|law__thompson_coburn|/imgs/btn/koeye.png|law",
		"http://koreintillery.com/|/imgs/us/law_korein_tillery.png|law_korein_tillery|/imgs/btn/koeye.png|law",
		"http://www.smithbrownllc.com/|/imgs/us/law_smith_brown.png|law_smith_brown|/imgs/btn/koeye.png|law",
		"http://www.fdazol.com/|/imgs/us/law_azol.png|law_azol_f|/imgs/btn/koeye.png|law",
		"http://lawdonovan.com|/imgs/us/lawdonovan.png|law_donovan|/imgs/btn/koeye.png|law",
		"http://nathanscohen.com/|/imgs/us/law_cohen_nathan_s.png|law__cohen_nathan_s|/imgs/btn/koeye.png|law",
		"https://twitter.com/AlanWCohenEsq|/imgs/us/cohen_alan_w_twitter.png|cohen_alan_w_twitter|/imgs/btn/koeye.png|law",
		"http://www.primerus.com/attorneys/alexander-h-kuehling-esq-rosenblum-goldenhersh-st-louis-missouri-mo.htm|/imgs/us/law_kuehling_alexander.png|law_law_kuehling_alexander|/imgs/btn/koeye.png|law",
		"http://elsterlaw.com/henry-elster-attorney-missouri-best/|/imgs/us/law_elster_henry.png|law_elster_henry|/imgs/btn/koeye.png|law",
		"https://pview.findlaw.com/view/2830721_1|/imgs/us/law_walters_alan.png|law_walters_alan|/imgs/btn/koeye.png|law",
		"https://www.thompsoncoburn.com/|/imgs/us/law_thompson_coburn.png|law__thompson_coburn|/imgs/btn/koeye.png|law",
		"http://koreintillery.com/|/imgs/us/law_korein_tillery.png|law_korein_tillery|/imgs/btn/koeye.png|law",
		"http://www.smithbrownllc.com/|/imgs/us/law_smith_brown.png|law_smith_brown|/imgs/btn/koeye.png|law",
		"http://index_party.html|/imgs/us/law_donovan.png|law_donovan|/imgs/btn/koeye.png|law",
		"http://index_jtfdc.com/|/imgs/us/law_cohen_nathan_s.png|law__cohen_nathan_s|/imgs/btn/koeye.png|law",
		]
	return(uslaws)





def ko_im(a1,a2):
	print( progid,dttm,"ko_im a1=",a1)
	pathfile="."
	if( a1 != "" ): pathfile=a1
#	syscmd="ls -lat {} | exiftool -s -csv".format( pathfile )
	syscmd="mkdir {}/tn".format( pathfile )
	print( progid,dttm, "ko_im syscmd{}".format( syscmd ))
#	os.system( syscmd )

	syscmd="mogrify  -resize x300 -set filename:name %f  -write '{}/tn/tn_%[filename:name]' {}".format( pathfile, pathfile )
	print( progid,dttm, "ko_im syscmd{}".format( syscmd ))
#	os.system( syscmd )
	os.system( "mogrify  -resize x300 -set filename:name %f  -write './pn/imgs/tn/tn_%[filename:name]' ./pn/imgs/*.jpg" ) 

	exit()

	print( progid,dttm,"ko_im syscmd={}".format( syscmd ))
	os.system( syscmd )


#	my_date = datetime.date(*[int(i) for i in string_date.split("-")])
#	from subprocess import call
#	call(["ls", "-l" )
#	os.system( "ls -lat /Volumes/ka1tbr2/ht/imgs/links/*.*" )
#	print( subprocess.Popen("echo Hello World", shell=True, stdout=subprocess.PIPE).stdout.read(	)
#	return_code = subprocess.call("echo Hello World", shell=True) 
	return("ko_im_return");


def ko_sql(sqlfil,sqlcmd):
	import sqlite3
	sqlfil="ka1.db3"
	sqlcmd="select cat,test,testdt from lab"
	print( progid,dttm,"ko_sql sqlfil={} sqlcmd={}\n".format( sqlfil, sqlcmd ))

	try:
		sqldb = sqlite3.connect(sqlfil)
	except Error as e:
		print(e)

	cur = sqldb.cursor()
#	cur.execute("SELECT * FROM tasks")
#	cur.execute("SELECT * FROM tasks WHERE priority=?", (priority,))
#	sqlcmd="select * from leds"
	cur.execute(sqlcmd)
	rows = cur.fetchall()
	for row in rows:
		print( "cat={} test={} testdt={}".format( row[0], row[1], row[2] ))
# err		print( "cat={} test={} testdt={}".format( row['cat'], row['test'], row['testdt'] ))
#		print(row)

	print( progid,dttm,"ko_sql sqlfil={} sqlcmd={}\n".format( sqlfil, sqlcmd ))


	db = sqlite3.connect(sqlfil)
	db.row_factory = sqlite3.Row
	cursor = db.cursor()
	cursor.execute('''select name, email, phone from us0''')
	for row in cursor:
# 		row['name'] returns the name column in the query, row['email'] returns email column.
		print('{0} : {1}, {2}'.format(row['name'], row['email'], row['phone']))
	db.close()
	return( "ko_sql" )




	def sql_cr(sqldb, sqlcmd ):
		sqlcmd= """ CREATE TABLE IF NOT EXISTS pd (
                                        id integer PRIMARY KEY,
                                        code text NOT NULL,
                                        dttm text NOT NULL,
                                        ctime text,
                                        filsiz text,
                                        pathfile text,
                                        path text,
                                        base text,
                                        ext text,
                                        link text,
                                        title text,
                                        desc text
                                    ); """
		cur.execute(sqlcmd)

	def sql_insert(sqldb, sqlcmd ):
		sqlcmd = """INSERT INTO table1 (
				column1, column2 ,..)
			VALUES (
				value1, value2 ,...
				); """

	return("ko_sql_return");


def ko_usid2host(grp, usid):
	import sqlite3
	dttm=kodts('')
	sqlfil="ko.db3"
	sqlcmd="select cat,test,testdt from lab"
	sqlcmd="select * from uslist"
	sqlcmd="select usid,dttm,status,url,img,tn,id,grp from uslist "
	print( progid,dttm,"ko_sql sqlfil={} sqlcmd={}\n".format( sqlfil, sqlcmd ))
	fildb3="ko.db3"

	try:
		sqldb = sqlite3.connect(fildb3)
	except Error as e:
		print(e)

	cur = sqldb.cursor()
#	cur.execute("SELECT * FROM tasks")
#	cur.execute("SELECT * FROM tasks WHERE priority=?", (priority,))
#	sqlcmd="select * from leds"
	cur.execute(sqlcmd)
	rows = cur.fetchall()
	for row in rows:
		print( "r0={} r1={} r3={}".format( row[0], row[1], row[2] ))
# err		print( "cat={} test={} testdt={}".format( row['cat'], row['test'], row['testdt'] ))
#		print(row)

	print( progid,dttm,"ko_usid2host sqlfil={} sqlcmd={}\n".format( sqlfil, sqlcmd ))


	db = sqlite3.connect(fildb3)
	db.row_factory = sqlite3.Row
	cursor = db.cursor()

	sqlcmd='''select usid,dttm,status,url,img,tn,id,grp from uslist'''
	cursor.execute(sqlcmd)
#	cursor.execute('''select name, email, phone from uslist limit 4''')

	osflag = ""
	for row in cursor:
# 		row['name'] returns the name column in the query, row['email'] returns email column.
		print('{0} : {1}, {2}'.format(row['usid'], row['url'], row['img'], row['tn'], row['id'], row['grp'], row['status']))
		grp=row['grp']
		id=row['id']
		url=row['url']
		img=row['img']
		tn=row['tn']
		status=row['status']

		syscmd_mkdir_grp = "mkdir uw/{}".format(grp)
		print( "usid2host syscmd_mkdir_grp={}".format( syscmd_mkdir_grp ))

		syscmd_mkdir_grpid = "mkdir uw/{}/{}".format(grp,id)
		print( "usid2host grp={} id={} syscmd_mkdir_grpid={}".format( grp, id, syscmd_mkdir_grp))

		osflag = ""
		print( "osflag={}".format(osflag))
#		if( osflag == "y" ): os.system( syscmd_mkdir_grp )
#		if( osflag == "y" ): os.system( syscmd_mkdir_grpid )


#	db.close()
#	return( "ko_usid2host" )




	def sql_cr(fildb3, sqlcmd ):
		sqlcmd= """ CREATE TABLE IF NOT EXISTS pd (
                                        id integer PRIMARY KEY,
                                        code text NOT NULL,
                                        dttm text NOT NULL,
                                        ctime text,
                                        filsiz text,
                                        pathfile text,
                                        path text,
                                        base text,
                                        ext text,
                                        link text,
                                        title text,
                                        desc text
                                    ); """
		cur.execute(sqlcmd)


	uslist = load_uslist()
	j=0
	status="todo"
	dttm=kodts('')
	for us in uslist:
		print( "j={} us={}".format(j, us))

		url=us.split("|")[0]
		img=us.split("|")[1]
		tn=us.split("|")[2]
		id=us.split("|")[3]
		grp=us.split("|")[4]
		status="todo"

		sqltbl = "uslist"
		sqlcols = "'id', 'grp', 'url', 'img', 'tn','status','dttm'"
		sqlvals = "'id', 'grp', 'url', 'img', 'tn','status','dttm'"
		sqlvals = "'{}','{}','{}','{}','{}','{}','{}'".format(id,grp,url,img,tn,status,dttm)

		sql_insert = "insert or replace into {} ( {} ) values ( {} )".format( sqltbl, sqlcols, sqlvals )
		print( "{}".format(sql_insert))
#		print( "usid2host j={} sql_insert={}".format(j,sql_insert))
#		print( "j={} grp={} id={} url={} img={}".format( j, grp, id, url, img ))
#		cur.execute(sql_insert)
		cursor.execute(sql_insert)

#		def sql_insert(fildb3, sql_insert ):
#			sql_insert = "insert or replace into {} ( {} ) values ( {} )".format( sqltbl, sqlcols, sqlvals )
#
#
#		def sql_insert(fildb3, sqlcmd ):
#		sqlcmd = """INSERT INTO table1 (
#		sqlcmd = """insert or replace into  uslist (
#				'id','grp','url','img','tn','status','dttm' )
#			VALUES (
#				sqlval
##				value1, value2 ,...
#				); """
#
		j=j+1
	db.close()
	return("ko_sql_return");


def ko_img(a1,a2):
	from PIL import Image, ImageFilter
	imgfil=a1
	imgout=a2
	print( progid,dttm,"ko_img imgfil=",imgfil," imgout=",imgout)

#Read image
#	im = Image.open( 'image.jpg' )
	im = Image.open( imgfil )
	im.show()
	im_sharp = im.filter( ImageFilter.SHARPEN )
#	im_sharp.save( 'image_sharpened.jpg', 'JPEG' )
	im_sharp.save( imgout, 'JPEG' )

#Splitting the image into its respective bands, i.e. Red, Green,
#and Blue for RGB
	r,g,b = im_sharp.split()

#Viewing EXIF data embedded in image
	exif_data = im._getexif()
	exif_data

	return("ko_img_return");



def wiisk( a1,a2,a3 ):
	dttm=dttm()
	print( "{} {} wiisk ".format(progid, dttm, a1, a2, a3 ))
	exit()

def wiijk( a1,a2,a3 ):
	dttm=dttm()
	print( "{} {} wiijk ".format(progid, dttm, a1, a2, a3 ))
	exit()

def wii( a1,a2,a3 ):
	dttm=dttm()
	print( "{} {} wiijk ".format(progid, dttm, a1, a2, a3 ))
	exit()









def ko_find(path,name):
	import subprocess
	import os

# 	syscmd "find {} -type f {} -exec ls -s \{\} \; | sort -n -r | head -5".format( path, name)
#	syscmd="find ./ht f -exec ls -lat {} \;"
	syscmd='find ./imgs -name "btn_*.gif" f -exec ls -lat {} \;'
	stdout=""
	print( progid,dttm,"ko_find: syscmd=",syscmd)

# ok	p = os.popen('ls -lat')
# ok	p = os.popen('ls -lat ./imgs/ok*.*')
# 	p = os.popen("ls -lat ./imgs/ok*.*")

#	syscmd="ls -lat ./imgs/ok*.*"
	syscmd="ls -lat "+path

	syscmd='find ./imgs -name \"btn_*.gif\"  -exec ls -lat {} \;'
	print( progid,dttm,"ko_find syscmd=",syscmd)
	p = os.popen("syscmd")
	print(p.read())
	
	print( progid,dttm,"MSG:  ko_subprocess p=", p)
	print( progid,dttm,"MSG:  ko_subprocess syscmd=", syscmd)
#	process = subprocess.Popen("syscmd", stdout=subprocess.PIPE, stderr=subprocess.PIPE)
#	process = subprocess.Popen(['ls -lat ', 'rb'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
#	stdout, stderr = process.communicate()
	print( progid,dttm,"MSG:  ko_subprocess stdout=", stdout)
#	print( stdout)
	return(stdout)



def ko_glob( pattern ):
	import glob

	out = glob.glob( pattern )
#	print(glob.glob("/home/adam/*.txt"))
#	out = glob.glob( "./imgs/ko/icons/*.gif" )
#	out = glob.glob( "./imgs/*.gif" )
#	out = glob.glob( "./imgs/*.jpg" )
#	out = glob.glob( "/Volumes/ka1tbr2/ht/*.png" )
#	globcmd = "/Volumes/ka1tbr2/ht/*.php"
#	print( "BUGS95_ko_glob out=",out)

#	out = glob.glob( pattern )
#	print( "ko_glob BUGS_beg:  pattern=", pattern)
#	print( "ko_glob BUGS_beg:  out=", pattern)
	return(out)
	
def ko_ls( dir, endswith ):
	import os
#	arr_txt = [x for x in os.listdir(dir) if x.endswith(".txt")]
#	arr_gif = [x for x in os.listdir(dir) if x.endswith(".gif")]
#	return(os.listdir(dir))
	out = [x for x in os.listdir(dir) if x.endswith(endswith)]
	return( out )


def ko_subprocess( syscmd ):
	import subprocess

#	process = subprocess.Popen("ps -p 2993 -o time --no-headers", stdout=subprocess.PIPE, stderr=subprocess.PIPE)
#	process = subprocess.Popen(syscmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
	syscmd="ls -lat /Volumes/ka1tbr2/ht/"
	process = subprocess.Popen("syscmd", stdout=subprocess.PIPE, stderr=subprocess.PIPE)
	stdout, stderr = process.communicate()
	print( progid,dttm,"MSG:  ko_subprocess")
#	print( stdout)
	return(stdout)



def ko_walk( dir, kludge ):
	for root, dirs, files in os.walk(dir):  
		for filename in files:
			print(filename)



def ko_listdir( dir, pattern ):
#	listOfFiles = os.listdir('.')  
# 	pattern = "*.py"  
	listOfFiles = os.listdir( dir )

	for entry in listOfFiles:  
		if fnmatch.fnmatch(entry, pattern):
			print( (entry))

def startup():
	global progid, dttm
	progid = "ka1"
	dttm=kodts('')


#	print( "arg1=", str(sys.argv[1:]))
#	print( "arg1:1=", str(sys.argv[1:2]))
#	print( "arg2:1=", str(sys.argv[2:3]))
# 	print( progid,dttm, "MSG:  startup\n\n")

#	try:
#		thevariable
#	except NameError:
#		print( "well, it WASN'T defined after all!")
#	else:
#		print( "sure, it was defined."`)






#	if( len(sys.argv) == 1 ):
	if( len(sys.argv) < 2 ):
		print( progid, dttm, "pqpqpqpqpqpqpqpqpq")
		print( progid, "do <a1> <a2>")
		print( progid, "do <a1> <a2>")
		print( progid, "dodo <a1> <a2>")
		print( progid, "do_mp42gif <a1> <a2>")
		print( progid, "do_sl <a1> <a2>")
		print( progid, "do_tl <a1> <a2>")
		print( progid, "do_tlwl <a1> <a2>")
		print( progid, "do_tlpsv <a1> <a2>")
		print( progid, "go <a1> <a2>")
		print( progid, "find <path/file> <todofile>")
		print( progid, "mkwl <path/file> <todofile>")
		print( progid, "viwl <todofile> <a2>")
		print( progid, "runwl <todofile> <a2>")
		print( progid, "go <a1> <a2>")
		print( progid, "go pub ko	# index2index_ko0 <a2>")
		print( progid, "go_jsg <a1> <a2>")
		print( progid, "go <a1> <a2>")
		print( progid, "kov . .  # cp index.html kov_.html")
		print( progid, "ko_go <dir>  # find mp4 with embeded spaces")
		print( progid, "im <dir>  # imagemagic")
		print( progid, "sl <dir> ")
		print( progid, "tl <dir> ")
		print( progid, "b64 <dir> ")
		print( progid, "sql <dir> ")
		print( progid, "glob <dir> ")
		print( progid, "find <dir> ")
		print( progid, "ls <dir> <txt|png|gif|...> ")
		print( progid, "sys <dir> ")
		print( "{} {} pqpqpqpqpqpqpqpqpq".format( progid, dttm ))
		print( progid, "usid2host <usid>	<host># ")
		print( progid, "gif2size <gif>	<wxh># png+gif=png_gif.gif")
		print( progid, "png2gif <gif,png>	# png+gif=png_gif.gif")
		print( progid, "gifs2gifs <gifs>	# gifs.txt")
		print( progid, "gif2gifs <pathfile,oldtxt,newtxt>	# pub med_(rechtin,mcdonough)  index(_ko0_ko2)")
		print( progid, "go filio <pathfile,oldtxt,newtxt>	# pub med_(rechtin,mcdonough)  index(_ko0_ko2)")
		print( progid, "go htms2htm <id,id,id>	# pub med_(rechtin,mcdonough)  index(_ko0_ko2)")
		print( progid, "go phps2php <id,id,id>	# pub med_(rechtin,mcdonough)  index(_ko0_ko2)")
		print( progid, "go newhtm <id,id,id>	# pub med_(rechtin,mcdonough)  index(_ko0_ko2)")
		print( progid, "go uslaw .	# pub med_(rechtin,mcdonough)  index(_ko0_ko2)")
		print( progid, "go usmed usmedid	# pub med_(rechtin,mcdonough)  index(_ko0_ko2)")
		print( progid, "go cp .	# cp index.html index(_ko0_ko2_ka1_ka2).html")
		print( progid, "go scp ko	# scp index(ko0_ko2_ka1_ka2).html ko0us ko2us")
		print( progid, "go ssh ko	# ssh (ko0_ko2) sshcmd")
#		print( progid, "listdir <dir> <pattern>")
#		print( progid, "walk <dir> <pattern>")
#		print( progid, "joshtest <dir> <pattern>")
		print( progid, " ")
		print( progid, "wiisk <usid>	<host># ")
		print( progid, "wiijk <usid>	<host># ")
		print( progid, "wii <usid>	<host># ")
		print( progid, " ")
		print( progid, "d2db3 <dtasrc> <db3file> <tbl> <id> <usrcmd> # data2db3file" )
		print( progid, "d2db3 find= <db3file> <tbl> <id> go # data2db3file" )
		print( progid, "d2db3 select= <db3file> <tbl> <id> <usrcmd> # data2db3file" )
		print( progid, "d2db3 file=  <db3file> <tbl> <id> <usrcmd> # data2db3file" )
		print( progid, " ")
		print( progid, "d2db3v <dtasrc> <db3file> <tbl> <id> <usrcmd> # data2db3file_virtual" )
		print( progid, "d2db3v select <db3file> <tbl> <id> <usrcmd> # data2db3file_virtual" )
		print( progid, "d2db3v find <db3file> <tbl> <id> <usrcmd> # data2db3file_virtual" )
		print( progid, "d2db3v file <db3file> <tbl> <id> <usrcmd> # data2db3file_virtual" )
		print( progid, "newbook <db3file> <tbl> <id> <dtasrc> # data2db3file_virtual" )
#		print( progid, "newbook newbook find='find ../i -name "webb_lockdown*.*"' lb/books/alt/webb/webb_lockdown webb_lockdown  # data2db3file_virtual" ))
		dttm=kodts('')
		print( "{} {} bdbdbdbdbdbdbdbdbd".format( progid, dttm ))

		exit()
	dttm=kodts('')

	if( a1 == "sys" ):
		syscmd = sys.argv[2]
		print( progid,dttm, "MSG: startup_syscmd=",syscmd)
		sysout = ko_subprocess( syscmd )
		print( progid,dttm, "MSG: startup_sysout=",sysout)
		exit()

	if( a1 == "do" ):
		out=ko_do( a0,a1,a2,a3 )
		print( progid,dttm, "MSG: startup_do out=", out,a0,a1,a2,a3)
		exit()

	if( a1 == "dodo" ):
		out=ko_dodo( a0,a1,a2,a3 )
		print( progid,dttm, "MSG: startup_dodo out=", out,a0,a1,a2,a3)
		exit()

	if( a1 == "do_mp42gif" ):
		out=ko_do_mp42gif( a0,a1,a2,a3 )
		print( progid,dttm, "MSG: startup_do_mp42gif out=", out,a0,a1,a2,a3)
		exit()

	if( a1 == "do_sl" ):
		out=ko_do_sl( a0,a1,a2,a3 )
		print( progid,dttm, "MSG: startup_do_tl out=", out, a0,a1,a2,a3)
		exit()

	if( a1 == "do_tl" ):
		out=ko_do_tl( a0,a1,a2,a3 )
		print( progid,dttm, "MSG: startup_do_tl out=", out, a0,a1,a2,a3)
		exit()

	if( a1 == "do_tlwl" ):
		out=ko_do_tlwl( a0,a1,a2,a3 )
		print( progid,dttm, "MSG: startup_do_tlwl out=", out, a0,a1,a2,a3)
		exit()

	if( a1 == "do_tlpsv" ):
		out=ko_do_tlpsv( a0,a1,a2,a3 )
		print( progid,dttm, "MSG: startup_do_tlpsv out=", out, a0,a1,a2,a3)
		exit()

	if( a1 == "ko_dodo" ):
		out=ko_dodo( a0,a1,a2,a3 )
		print( progid,dttm, "MSG: startup_dodo out=", out, a0,a1,a2,a3)
		exit()

	if( a1 == "viwl" ):
		out=ko_find( a1, a2 )
		syscmd_vi="vi {}".format( a1 )
		print( progid,dttm, "MSG: syscmd_vi=".format(syscvmd_vi))
#		os.system(syscmd_vi)
		exit()

	if( a1 == "runwl" ):
		out="runwl a1={} a2={} a3={}\n".format( a1, a2, a3 )
		runwl( a1, a2, a3 )
		print( progid,dttm, "MSG: runwl wlfile=", a1)
		exit()


	if( a1 == "mkwl" ):
		out=ko_find( a1, a2 )
		print( progid,dttm, "MSG: startup_go out=", out)
		exit()
	if( a1 == "find" ):
		out=ko_find( a1, a2 )
		print( progid,dttm, "MSG: startup_go out=", out)
		exit()
	if( a1 == "ko_find" ):
		out=ko_find( a1, "" )
		print( progid,dttm, "MSG: startup_im out=", out)
		exit()

	if( sys.argv[1] == "go" ):
		out=go( sys.argv[2], sys.argv[3] )
		print( progid,dttm, "MSG: startup_go out=", out)
		exit()

	if( sys.argv[1] == "kogo" ):
		out=ko_go( sys.argv[2], sys.argv[3] )
		print( progid,dttm, "MSG: startup_go out=", out)
		exit()

	if( sys.argv[1] == "go_jsg" ):
		out=go_jsg( a1, a2 )
		print( progid,dttm, "MSG: startup_go_jsg out=", out)
		exit()

	if( sys.argv[1] == "kov" ):
		out=ko_kov( a1, a2 )
		print( progid,dttm, "MSG: kov out=", out)
		exit()

	if( sys.argv[1] == "ocr" ):
		(uname,err)=kosys('uname -a'.split(" ")[1],'')
		progid=sys.argv[0]
		print( "BUG_5920 progid={} dttm={} uname={}".format(progid,dttm,uname))
		exit()
		dtasrc=sys.argv[2]
		print( "MSG_5921: ocr BEG dtasrc={}\nout=".format(dtasrc,out))
		out=ocr(dtasrc)
		print( "MSG_5922: ocr END dtasrc={}\nout=".format(dtasrc,out))
		exit()

	if( sys.argv[1] == "f2db3" ):
		db3file=a2
		ifile=a3
		tbl=a4
		id=a5
		print( "f2db3 db3file={} ifile={} tbl={} id={}\n".format(db3file,ifile,tbl,id))
		out=f2db3( db3file, ifile, tbl, id )
#		print( progid,dttm, "MSG: f2db3 out=", out)
		print( "{} {} BUGS_3670: f2db3 out={}\n".format(progid,dttm,out))
		exit()

	if( sys.argv[1] == "ftsdb3" ):
		cmd=a2
		if( cmd == "" ):
			print( "{} {} help: ftsdb3".format(progid,dttm))
			print( "======================" )
			print( "python {} ftsdb3 create db3file,tbl".format(progid))
			print( "python {} ftsdb3 insert db3file,sql_insert,tbl,values,ifile,id".format(progid))
			print( "python {} ftsdb3 update db3file,sql_update,tbl".format(progid))
			print( "python {} ftsdb3 select db3file,sql_select,tbl,limit".format(progid))
			print( "python {} ftsdb3 drop db3file,tbl".format(progid))
			print( "python {} ftsdb3 delete db3file,sql_delete,tbl,rowid".format(progid))
			print( "python {} db3s to_db3file,to_tbl,sql_select rowid".format(progid))
			exit()

		(cmd,db3file,tbl,id) = (a2,a3,a4,a5)
		if( a2 == "creates"):
			(cmd,db3file,tbl,id) = (a2,a3,a4,a5)
			print( "BUGS_4171 f2db3 cmd={} db3file={} tbl={} id={}".format(cmd,db3file,tbl,id))
			exit()
		if( a2 == "inserts"):
			(cmd,db3file,tbl,ifile,id) = (a2,a3,a4,a5,a6)
			print( "BUGS_4172 f2db3 cmd={} db3file={} tbl={} ifile={} id={}".format(cmd,db3file,tbl,ifile,id))
			exit()
		if( a2 == "updates"):
			(cmd,db3file,tbl,fld,val,rowid) = (a2,a3,a4,a5,a6,a7)
			print( "BUGS_4173 f2db3 cmd{} db3file={} tbl={} fld={} val={} rowid={}".format(cmd,db3file,tbl,fld,val,rowid))
			exit()
		if( a2 == "selects"):
			(cmd,db3file,tbl,fld,val,rowid) = (a2,a3,a4,a5,a6,a7)
			print( "BUGS_4173 f2db3 cmd{} db3file={} tbl={} fld={} val={} rowid={}".format(cmd,db3file,tbl,fld,val,rowid))
			exit()
		if( a2 == "drops"):
			(cmd,db3file,tbl) = (a2,a3,a4)
			print( "BUGS_4175 f2db3 {} db3file={} tbl={}".format(cmd,db3file,tbl))
			exit()
		if( a2 == "deletes"):
			(cmd,db3file,tbl,rowid) = (a2,a3,a4,a5)
			print( "BUGS_4176 f2db3 {} db3file={} tbl={} rowid={} ".format(cmd,db3file,tbl,rowid))
			exit()

		if( a2 == "create"):
			(cmd,db3file,tbl,id) = (a2,a3,a4,a5)
			print( "BUGS_4171 f2db3 cmd={} db3file={} tbl={} id={}".format(cmd,db3file,tbl,id))
			status=db3_create(db3file,tbl)
			exit()
		if( a2 == "insert"):
			(cmd,db3file,sql_insert,values,ifile,id) = (a2,a3,a4,a5,a6,a7)
			print( "BUGS_4172 f2db3 cmd={} db3file={} sql_insert={} tbl={} ifile={} id={}".format(cmd,db3file,sql_insert,tbl,ifile,id))
			status=db3_insert(db3file,sql_insert,tbl,values,ifile,id)
			exit()
		if( a2 == "update"):
			(cmd,db3file,sql_update,tbl) = (a2,a3,a4,a5)
			status=db3_update(db3file,sql_update,tbl)
			print( "BUGS_4173 f2db3 cmd{} db3file={} tbl={} fld={} val={} rowid={}".format(cmd,db3file,tbl,fld,val,rowid))
			exit()
		if( a2 == "select"):
			(cmd,db3file,sql_select,tbl,fld,val,rowid,limit) = (a2,a3,a4,a5,a6,a7,a8,a9)
			print( "BUGS_4172 f2db3 db3file={} sql_select={} tbl={} fld={} val={} rowid={} limit={}".format(db3file,sql_select,tbl,fld,val,rowid,limit))
			db3_select(db3file,sql_select,tbl,fld,val,rowid,limit)
			print( "BUGS_4173 f2db3 cmd{} db3file={} tbl={} fld={} val={} rowid={}".format(cmd,db3file,tbl,fld,val,rowid))
			exit()
		if( a2 == "drop"):
			(cmd,db3file,tbl) = (a2,a3,a4)
			print( "BUGS_4175 f2db3 {} db3file={} tbl={}".format(cmd,db3file,tbl))
			status=db3_drop(db3file,tbl)
			exit()
		if( a2 == "delete"):
			(cmd,db3file,tbl,rowid,sql_delete) = (a2,a3,a4,a5,"")
			print( "BUGS_4176 f2db3 {} db3file={} tbl={} rowid={} ".format(cmd,db3file,tbl,rowid))
			status=db3_delete(db3file,sql_delete,tbl,rowid)
			exit()



		(cmd,db3file,ifile,tbl,id) = ("",a2,a3,a4,a5)
		(db3file,ifile,tbl,id) = (a2,a3,a4,a5)
		print( "ftsdb3 db3file={} ifile={} tbl={} id={}\n".format(db3file,ifile,tbl,id))
		out=ftsdb3( db3file, ifile, tbl, id )

#		print( "f2fstdb3 db3file={} ifile={} tbl={} id={}\n".format(db3file,ifile,tbl,id))
#		out=f2fstdb3( db3file, ifile, tbl, id )
		print( "{} {} MSG_4120: ftsdb3 out={}".format(progid,dttm,out))
		exit()

	if( sys.argv[1] == "bugs1" ):
		print( "bugs1 a1={} a2={} a3={} FFFFFFFFFFFFFFFFFFFFFF\n".format(a1,a2,a3) )
		exit()
	if( sys.argv[1] == "f2ftsdb3" ):
		content_inserts="y"
		sql_inserts="y"
		if( a2 == "" ):
			print( "{} {} ".format(progid,dttm))
			print( "{}.py f2ftsdb3 <db3file> <datasrc> <tbl> <id> <content_inserts> ".format(progid))
			print( "{}.py f2ftsdb3 fts/fts.db3 fts.txt fts content_inserts".format(progid))
			print( "{}.py f2ftsdb3 fts/fts.db3 \"ls path/*.txt\" fts content_inserts".format(progid))
			print( "{}.py f2ftsdb3 fts/fts.db3 \"cat path/*.txt\" fts content_inserts".format(progid))
			print( "{}.py f2ftsdb3 fts/fts.db3 \"find path/ -type -maxdepth 2 -name \'ko*.*\'\" fts include_content".format(progid))
			print( "content_inserts={} sql_inserts={}". format(content_inserts,sql_inserts))
			print( "\n" )
			print( "f2ftsdb3 fts/fts.db3 \"find /lb/books/ -type -f -name '*.txt'\" bks_v")
			exit()


		(db3file,datasrc,tbl,id,content_inserts,sql_inserts) = (a2,a3,a4,a5,a6,a7)
#		print( "BUGS_4631 f2ftsdb3 TODO db3file={} ifile={} tbl={} id={} content_inserts={} \n".format(db3file,ifile,tbl,id,content_inserts))
#		status=f2ftsdb3(db3file,ifile,tbl,id,content_inserts)
		status=f2ftsdb3(db3file,datasrc,tbl,id,sql_inserts,content_inserts)
#		print( "BUGS_4632 f2ftsdb3 DONE db3file={} ifile={} tbl={} id={} content_inserts={}\n".format(db3file,ifile,tbl,id,content_inserts) )
		exit()

	if( sys.argv[1] == "housatonic" ):
		(frompath) = (a2)
		if( frompath == ""): frompath="/Volumes/ka1tbr1/ht/kb/pdf/housatonic_pdf"
		print( "BUGS_5101 db3s frompath={}". format(frompath))
		status=housatonic(frompath)
		print( "BUGS_5102 db3s frompath={}". format(frompath))
		exit()

	if( sys.argv[1] == "db3s" ):
		(to_db3file,to_tbl,db3s_todos) = (a2,a3,a4)
		print( "BUGS_5101 db3s to_db3file={} to_tbl={} db3s_todo={}". format(to_db3file,to_tbl,db3s_todos))
		status=db3s_update(to_db3file,to_tbl,db3s_todos)
		print( "BUGS_5102 db3s to_db3file={} to_tbl={} db3s_todo={}". format(to_db3file,to_tbl,db3s_todos))
		exit()

	if( sys.argv[1] == "d2db3" ):
		(dtasrc,db3file,tbl,id,usrcmd) = (a2,a3,a4,a5,a6)
#		print( "BUGS_4925 d2db3 db3file={} dtasrc={} tbl={} id={} usrcmd={}". format(db3file,dtasrc,tbl,id,usrcmd))
		status=d2db3(dtasrc,db3file,tbl,id,usrcmd)
		exit()



	if( sys.argv[1] == "newbook" ):
		(dtasrc,db3file,tbl,id,txtmode,usrcmd) = (a2,a3,a4,a5,a6,a7)
#		print( "BUGS_6121 newbook db3file={} dtasrc={} tbl={} id={} txtmode={} usrcmd={}". format(db3file,dtasrc,tbl,id,txtmode,usrcmd))

#		(out,err)=("","")
#		syscmd="ls -lat "
#		(out,err)=kosys(syscmd,'brief')
#		(out,err)=kosys('find ../i -name="webb*.*"','brief')	
#		print( "BUGS_6130 out={} err={}".format(out,err))
#		exit()

		status=newbook(dtasrc,id,txtmode,usrcmd)
#		status=newbook(dtasrc,db3file,tbl,id,txtmode,usrcmd)
#		print( "BUGS_6122 newbook db3file={} dtasrc={} tbl={} id={} txtmode={} usrcmd={}". format(db3file,dtasrc,tbl,id,txtmode,usrcmd))

		exit()

	if( sys.argv[1] == "d2db3v" ):
		(dtasrc,db3file,tbl,id,txtmode,usrcmd) = (a2,a3,a4,a5,a6,a7)
		print( "BUGS_6150 d2db3 db3file={} dtasrc={} tbl={} id={} txtmode={} usrcmd={}". format(db3file,dtasrc,tbl,id,txtmode,usrcmd))
		exit()
		status=d2db3v(dtasrc,db3file,tbl,id,txtmode,usrcmd)
		exit()

	if( sys.argv[1] == "f2ftsdb3_content" ):
		(db3file,tbl,sql_select) = (a2,a3,a4)
#		print( "BUGS_4925 f2ftsdb3_content db3file={} tbl={} sql_select={}". format(db3file,tbl,sql_select))
		status=f2ftsdb3_content(db3file,tbl,sql_select)
		exit()

	if( sys.argv[1] == "bugs2" ):
		print( "bugs2 a1={} a2={} a3={} FFFFFFFFFFFFFFFFFFFFFF\n".format(a1,a2,a3) )
		exit()

	if( sys.argv[1] == "go" ):
		out=go( a1, a2 )
		print( progid,dttm, "MSG: ko out=", out)
		exit()

	if( sys.argv[1] == "ko_go" ):
		out=ko_go( a1, a2 )
		print( progid,dttm, "MSG: ko_go out=", out)
		exit()

	if( sys.argv[1] == "im" ):
		out=ko_im( sys.argv[2], "" )
		print( progid,dttm, "MSG: startup_im out=", out)
		exit()

	if( sys.argv[1] == "sql" ):
		out=ko_sql( sys.argv[2], sys.argv[3] )
		print( progid,dttm, "MSG: startup_sql out=", out)
		exit()


	if( sys.argv[1] == "find" ):
		out=ko_find( sys.argv[2], sys.argv[3] )
		print( progid,dttm, "MSG: startup_find out=", out)
		exit()


	if( sys.argv[1] == "b64" ):
		import base64
		j=0
		pathdir=sys.argv[2]
		chars_to_remove = [ '.', '*' ]
		pathcode=pathdir.translate(None,''.join(chars_to_remove))
		pathcode=pathcode.replace("/","-")
		pathcode=pathcode.replace("-","", 1)

		if( pathdir == "" ): pathdir="."; pathcode="";

		pathfiles=ko_glob( pathdir )
#		print( progid,dttm, "MSG: startup_b64 pathdir=", pathdir)
#		print( progid,dttm, "MSG: startup_b64 pathcode=", pathcode)
#		b64_pathfile=pathdir+"/"+"b64_"+base

		htm_pathfile="./"+progid+"_b64_"+pathcode+".htm"
		htm_pathfile = htm_pathfile.replace( "-.htm", ".htm" )

		csv_pathfile="./"+progid+"_b64_"+pathcode+".csv"
		csv_pathfile = csv_pathfile.replace( "-.csv", ".csv" )

#		print( progid,dttm, "MSG: startup_b64 htm_pathfile=", htm_pathfile)
#		print( progid,dttm, "MSG: startup_b64 csv_pathfile=", csv_pathfile)
		csvfil = open(csv_pathfile, "wb" )

		csvout = ''
		jsout = ""
		htmout = ""

		csvout = "recno,progid,status,dttm,pathfile,path,base,file,ext,filsiz,ctime,desc"
#		print( "BUGS270 csvout=" + csvout)

		htmfil = open(htm_pathfile, "wb" )
#		jsout += '<script id="script_',pathcode,'" >\n'
		jsout += "<script id='script_myb64'\n"

		jsout += "function load_myb64() {\n"

		jsout += "	var myb64 = new array()\n"

# bugs tuple 	htmout += "	<div id='", pathcode, "' >\n"
# bugs tuple	htmout += '	<div id="', pathcode[0], '" >\n'
		htmout += '	<div id="div_myb64" >\n'

		for pathfile in pathfiles:
			j=j+1
			dttm=kodts('')
			path=os.path.dirname(pathfile)
			base=os.path.basename(pathfile)
			file=os.path.splitext(base)[0]
			ext=os.path.splitext(base)[1]
			filecode_tuple=str(j),"-",file,"-",ext
			filecode = "".join(filecode_tuple)
			print( progid,dttm,j,"pathfile=",pathfile, path, base,file,ext)
			print( progid,dttm,j,"filecode=",filecode)
			print( progid,dttm,j,"filecode_tuple=",filecode_tuple)

			b64dta=""
			if( os.path.isfile( pathfile )):	


				filesize = os.path.getsize(pathfile)
				ctime=time.ctime(os.path.getctime(pathfile))
				ctime_ymd = time.strftime('%Y-%m-%d_%H:%M:%S', time.gmtime(os.path.getmtime(pathfile)))


# err				ctime=os.path.getctime(pathfile)
#				ctime_ymd =  datetime.datetime.strftime(ctime,'%Y-%m-%d_%H:%M:%S')  # This writes "06/24/1984"
#				print( progid,dttm,j,"ctime_ymd=",ctime_ymd)
#				ctime_ymd = "YYYY-MM-SS_hh:mm:ss"
#				ctime_ymd =  ctime.strftime('%Y-%m-%d_%H:%M:%S')  # This writes "06/24/1984"
#				d = datetime.strptime(time.ctime(),"%a %b %d %H:%M:%S %Y")
#				d = datetime.strptime(ctime,"%a %b %d %H:%M:%S %Y")
#				d = time.ctime(os.path.getctime(pathfile))
#				ctime_ymd = d.strftime('%Y-%d-%m_%H:%M:%S')
				print( progid,dttm,j,"ctime_ymd=",ctime_ymd,filesize,pathfile)

				image = open( pathfile, 'rb') 
				imgbin = image.read()
#				b64dta = base64.encodestring(imgbin)
				b64dta = base64.b64encode(imgbin)
				b64ext = ext.replace( '.', '' )	

				csvout += "{},{},{},{},{},{},{},{},{},{},{},\n".format(
					j,"status",progid,dttm,pathfile,path,base,file,ext,
					filesize,ctime_ymd,"desc")

#				jsout += 'myb64[{}] = "data:image/{};base64,{}"\n'.format(j, b64ext, b64dta )
# bugs tuple			jsout += 'myb64['",filecode,"'] = "data:image/png;base64,{}"\n'.format(j, b64dta )
				jsout += 'myb64['
# bugs tuple				jsout += filecode.join()
				jsout += '] = "data:image/{};base64,{}"\n'.format( b64ext, b64dta )
				
				htmout += "\n"
				print( "BUGS_350 filecode=",filecode)
#				htmout += '<a href=?q=myb64,',filecode,' id="',filecode,'" target=_blank >\n'
				htmout += '<a href=?q=myb64_{} id="{}" target=_blank >\n'.format( filecode, filecode )
#				htmout += '	<img id="{}" src="data:image/{};base64,{}"><br>\n'.format(filecode,b64ext,b64dta)
#				htmout += '	<img src="data:image/{};base64,{}"><br>\n'.format(b64ext,b64dta)
				htmout += '{} {} <img src="data:image/{};base64,{}">\n'.format(j,filecode, b64ext, b64dta )

				print( progid,dttm,j, "BUGS_322: b64dta=",b64dta,"xxxxxxxxx")
				
#				if( not os.path.isfile( b64_pathfile )):
#					print( progid,dttm,j,"b64_pathfile=",b64_pathfile)
#					b64ddta = base64.decodestring(b64dta) 
#					b64img = open(b64_pathfile, 'wb')
##					b64img = open('deer_decode.gif', 'wb')
#					b64img.write(b64ddta)

#			print( progid,dttm,j,"pathfile b64dta=",pathfile, b64dta)
			print( progid,dttm,j,"pathfile=",pathfile)

		jsout += "	return(myb64)\n"
		jsout += "	}\n"
		jsout += "	</script>\n"


		htmout += "		</div>\n"

#		htmout += '	<script id="script_myb64">'
#		htmout += '		var img, k;'
#		htmout += '		for( k=0; k<j; k++ ) {'
#		htmout += '			img = "<img src=", myb64[k], "></a><br>"'
#		htmout += '			document.write( img );'
#		htmout += '			}'
#		htmout += '		</script>'

		htmfil.write( htmout )
		htmfil.write( jsout )
		htmfil.close()

		csvfil.write( csvout )
		csvfil.close()
#		print( progid,dttm, "MSG_360: startup_b64 htm_pathfile=", htm_pathfile)
#		print( progid,dttm, "MSG_360: startup_b64 csv_pathfile=", csv_pathfile)
		exit()

	if( sys.argv[1] == "sl" ):
		j=0
		pathdir=sys.argv[2]
		chars_to_remove = [ '.', '*' ]
		pathcode=pathdir.translate(None,''.join(chars_to_remove))
		pathcode=pathcode.replace("/","-")
		pathcode=pathcode.replace("-","", 1)
		path=pathdir.replace( os.path.basename(pathdir),"", 1)

# print(os.path.splitext("path_to_file")[0])
# basenaem no ext if( pathdir == "" ): pathdir="."; pathcode="";
# print(basename("/a/b/c.txt"))

		pathfiles=ko_glob( pathdir )
#		print( progid,dttm, "MSG: startup_b64 pathdir=", pathdir)
#		print( progid,dttm, "MSG: startup_b64 pathcode=", pathcode)
#		b64_pathfile=pathdir+"/"+"b64_"+base

		htm_pathfile="./"+progid+"_b64_"+pathcode+".htm"
		htm_pathfile = htm_pathfile.replace( "-.htm", ".htm" )

		csv_pathfile="./"+progid+"_b64_"+pathcode+".csv"
		csv_pathfile = csv_pathfile.replace( "-.csv", ".csv" )

#		print( progid,dttm, "MSG: startup_b64 htm_pathfile=", htm_pathfile)
#		print( progid,dttm, "MSG: startup_b64 csv_pathfile=", csv_pathfile)
		csvfil = open(csv_pathfile, "wb" )

		csvout = ''
		jsout = ""
		htmout = ""

		csvout = "recno,progid,status,dttm,pathfile,path,base,file,ext,filsiz,ctime,desc"
#		print( "BUGS270 csvout=" + csvout)

		htmfil = open(htm_pathfile, "wb" )
#		jsout += '<script id="script_',pathcode,'" >\n'
		jsout += "<script id='script_myb64'\n"

		jsout += "function load_myb64() {\n"

		jsout += "	var myb64 = new array()\n"

# bugs tuple 	htmout += "	<div id='", pathcode, "' >\n"
# bugs tuple	htmout += '	<div id="', pathcode[0], '" >\n'
		htmout += '	<div id="div_myb64" >\n'

		j=0

#		for letter in 'Python':     # First Example
#			if letter == 'h':
#				break
#			print( 'Current Letter :', letter)
#		exit()

		filename = "ka1_av.html"
		filename = "test_av.html"
		file = open( filename, "r" )
		ka1_av_html_hdr = ""
		ka1_av_html_dta = ""
		ka1_av_html_ftr = ""
		j=0
		mode="hdr"
		for line in file:
# err			if line.match('div_sl_images" ): break
#			if line == 'div_sl_images': 

			if re.search( '<div id="div_sl_images">', line ):
				mode = "dta"
				filenames = [
					'./imgs/btn/ko.png',
					'./imgs/btn/p1.png',
					'./imgs/btn/p12.png',
					'./imgs/btn/ok.png'
					]

#				fruits = ['banana', 'apple',  'mango']
#				for ka1 in range(len(filenames)):
#					print( "BUGS_430 filename=", filenames[ka1])

#				a_href=""

#				fruits = ['banana', 'apple',  'mango']

				tncodes = ['tn', 'tn1', 'tn2', 'tn3']
				for tncode in tncodes:
					tnpath = "{}{}".format( path, tncode )
					tnpathfile = "{}/{}_*".format(tnpath,tncode )
					syscmd = "mkdir {}".format(tnpath )
#					print( 'BUGS_520 tnpath=',tnpath)
#					print( 'BUGS_520 tnpathfile=',tnpathfile)
#					print( 'BUGS_520 mkdir syscmd=', syscmd )
					if not os.path.isdir( tnpath ):
						os.system( syscmd )
# print(os.path.isdir("/home/el"))
# print(os.path.exists("/home/el/myfile.txt"))


# 					syscmd = 'mogrify  -resize x400 -set filename:name %f  -write "./pn/imgs/tng/tng_%[filename:name]' ./pn/imgs/*.png
					syscmd = 'mogrify  -resize x100 -set filename:name %f  -write "{}/{}_%[filename:name]" {}'.format( tnpath, tncode, pathdir ) 
					if ( tncode == "tn1" ):
						syscmd = 'mogrify  -resize x100 -set filename:name %f  -write "{}/{}_%[filename:name]" {}'.format( tnpath, tncode, pathdir ) 
					if ( tncode == "tn2" ):
						syscmd = 'mogrify  -resize x200 -set filename:name %f  -write "{}/{}_%[filename:name]" {}'.format( tnpath, tncode, pathdir )
					if ( tncode == "tn3" ):
						syscmd = 'mogrify  -resize x300 -set filename:name %f  -write "{}/{}_%[filename:name]" {}'.format( tnpath, tncode, pathdir ) 
					print( 'BUGS_530 mogrify syscmd=', syscmd )
					os.system( syscmd )


				for pathfile in pathfiles:
					j=j+1
					dttm=kodts('')
					path=os.path.dirname(pathfile)
					base=os.path.basename(pathfile)
					file=os.path.splitext(base)[0]
					ext=os.path.splitext(base)[1]
					filecode_tuple=str(j),"-",file,"-",ext
					filecode = "".join(filecode_tuple)
#					print( progid,dttm,j,"pathfile=",pathfile, path, base,file,ext)
#					print( progid,dttm,j,"filecode=",filecode)
#					print( progid,dttm,j,"filecode_tuple=",filecode_tuple)
					filename=pathfile
#					tn_filename=pathfile.replace(base,"/tn/tn_".join(base))
					tn_filename="{}/tn/tn_{}".format( path,base )
#					print( progid,dttm,j,"tn_filename=",tn_filename)


					a_href = ""
#					a_href += '<a href="./sl/bg/imgs/space/Universe_and_planets_digital_art_wallpaper_dk.jpg" class="thumb_link"><span class="selected"></span><img src="./sl/bg/imgs/space/Universe_and_planets_digital_art_wallpaper_dk_thumb.jpg" title="X-Wing on patrol" alt="X-Wing on patrol" class="thumb" /></a>'
					a_href += "<a href='{}' class='thumb_link'>\n".format( filename )
					a_href += '<span class="selected"></span>'
					a_href += '<img src="{}" height=100 title="{}" alt="{}" class="thumb" /></a>\n'.format( tn_filename,filename,filename )
					print( a_href)
#				continue

#			if re.match( '<div id="div_sl_images">', line ):
#				mode = "dta_match"
#				continue

			if '<div id="sl_images"' in line.lower():
				mode = "dta"
				continue
#			if j == 88:
#				mode = "dta"
#				continue
			if mode == "hdr":
				ka1_av_html_hdr += line
			if mode == "dta":
				ka1_av_html_dta += line
			print( line)
#			print( "BUGS_409 line=",j," line=", line, " mode=",mode)
			j=j+1
#		print( "BUGS_410 line=",j," ka1_av_html_hdr=", ka1_av_html_hdr)
#		print( "BUGS_410 line_len=",j)
			
				
		
#		print( file.read())
#		ka1_av_html_hdr = file.readline(500)
#		print( "ka1_av_html_hdr=",ka1_av_html_hdr)

#		print( file.readline(100))
#		print( file.readlines())
#		for line in file:
#			print( line,)

#		ka1_av_html = ""
#		ka1_av_html += ka1_av_html_hdr()
#		ka1_av_html += ka1_av_html_hdr
#		ka1_av_html += ka1_av_html_dta()
#		ka1_av_html += ka1_av_html_ftr()
#		print( ka1_av_html)
		exit()

		pathdir=sys.argv[2]
		chars_to_remove = [ '.', '*' ]
		pathcode=pathdir.translate(None,''.join(chars_to_remove))
		pathcode=pathcode.replace("/","-")
		pathcode=pathcode.replace("-","", 1)

		if( pathdir == "" ): pathdir="."; pathcode="";

		pathfiles=ko_glob( pathdir )
#		print( progid,dttm, "MSG: startup_b64 pathdir=", pathdir)
#		print( progid,dttm, "MSG: startup_b64 pathcode=", pathcode)
#		b64_pathfile=pathdir+"/"+"b64_"+base

		htm_pathfile="./"+progid+"_b64_"+pathcode+".htm"
		htm_pathfile = htm_pathfile.replace( "-.htm", ".htm" )

		csv_pathfile="./"+progid+"_b64_"+pathcode+".csv"
		csv_pathfile = csv_pathfile.replace( "-.csv", ".csv" )

#		print( progid,dttm, "MSG: startup_b64 htm_pathfile=", htm_pathfile)
#		print( progid,dttm, "MSG: startup_b64 csv_pathfile=", csv_pathfile)
		csvfil = open(csv_pathfile, "wb" )

		csvout = ''
		jsout = ""
		htmout = ""

		csvout = "recno,progid,status,dttm,pathfile,path,base,file,ext,filsiz,ctime,desc"
#		print( "BUGS270 csvout=" + csvout)

		htmfil = open(htm_pathfile, "wb" )
#		jsout += '<script id="script_',pathcode,'" >\n'
		jsout += "<script id='script_myb64'\n"

		jsout += "function load_myb64() {\n"

		jsout += "	var myb64 = new array()\n"

# bugs tuple 	htmout += "	<div id='", pathcode, "' >\n"
# bugs tuple	htmout += '	<div id="', pathcode[0], '" >\n'
		htmout += '	<div id="div_myb64" >\n'

		for pathfile in pathfiles:
			j=j+1
			dttm=kodts('')
			path=os.path.dirname(pathfile)
			base=os.path.basename(pathfile)
			file=os.path.splitext(base)[0]
			ext=os.path.splitext(base)[1]
			filecode_tuple=str(j),"-",file,"-",ext
			filecode = "".join(filecode_tuple)
			print( progid,dttm,j,"pathfile=",pathfile, path, base,file,ext)
			print( progid,dttm,j,"filecode=",filecode)
			print( progid,dttm,j,"filecode_tuple=",filecode_tuple)

			b64dta=""
			if( os.path.isfile( pathfile )):	


				filesize = os.path.getsize(pathfile)
				ctime=time.ctime(os.path.getctime(pathfile))
				ctime_ymd = time.strftime('%Y-%m-%d_%H:%M:%S', time.gmtime(os.path.getmtime(pathfile)))


# err				ctime=os.path.getctime(pathfile)
#				ctime_ymd =  datetime.datetime.strftime(ctime,'%Y-%m-%d_%H:%M:%S')  # This writes "06/24/1984"
#				print( progid,dttm,j,"ctime_ymd=",ctime_ymd)
#				ctime_ymd = "YYYY-MM-SS_hh:mm:ss"
#				ctime_ymd =  ctime.strftime('%Y-%m-%d_%H:%M:%S')  # This writes "06/24/1984"
#				d = datetime.strptime(time.ctime(),"%a %b %d %H:%M:%S %Y")
#				d = datetime.strptime(ctime,"%a %b %d %H:%M:%S %Y")
#				d = time.ctime(os.path.getctime(pathfile))
#				ctime_ymd = d.strftime('%Y-%d-%m_%H:%M:%S')
				print( progid,dttm,j,"ctime_ymd=",ctime_ymd,filesize,pathfile)

				image = open( pathfile, 'rb') 
				imgbin = image.read()
#				b64dta = base64.encodestring(imgbin)
				b64dta = base64.b64encode(imgbin)
				b64ext = ext.replace( '.', '' )	

				csvout += "{},{},{},{},{},{},{},{},{},{},{},\n".format(
					j,"status",progid,dttm,pathfile,path,base,file,ext,
					filesize,ctime_ymd,"desc")

#				jsout += 'myb64[{}] = "data:image/{};base64,{}"\n'.format(j, b64ext, b64dta )
# bugs tuple			jsout += 'myb64['",filecode,"'] = "data:image/png;base64,{}"\n'.format(j, b64dta )
				jsout += 'myb64['
# bugs tuple				jsout += filecode.join()
				jsout += '] = "data:image/{};base64,{}"\n'.format( b64ext, b64dta )
				
				htmout += "\n"
				print( "BUGS_350 filecode=",filecode)
#				htmout += '<a href=?q=myb64,',filecode,' id="',filecode,'" target=_blank >\n'
				htmout += '<a href=?q=myb64_{} id="{}" target=_blank >\n'.format( filecode, filecode )
#				htmout += '	<img id="{}" src="data:image/{};base64,{}"><br>\n'.format(filecode,b64ext,b64dta)
#				htmout += '	<img src="data:image/{};base64,{}"><br>\n'.format(b64ext,b64dta)
				htmout += '{} {} <img src="data:image/{};base64,{}">\n'.format(j,filecode, b64ext, b64dta )

				print( progid,dttm,j, "BUGS_322: b64dta=",b64dta,"xxxxxxxxx")
				
#				if( not os.path.isfile( b64_pathfile )):
#					print( progid,dttm,j,"b64_pathfile=",b64_pathfile)
#					b64ddta = base64.decodestring(b64dta) 
#					b64img = open(b64_pathfile, 'wb')
##					b64img = open('deer_decode.gif', 'wb')
#					b64img.write(b64ddta)

#			print( progid,dttm,j,"pathfile b64dta=",pathfile, b64dta)
			print( progid,dttm,j,"pathfile=",pathfile)

		jsout += "	return(myb64)\n"
		jsout += "	}\n"
		jsout += "	</script>\n"


		htmout += "		</div>\n"

#		htmout += '	<script id="script_myb64">'
#		htmout += '		var img, k;'
#		htmout += '		for( k=0; k<j; k++ ) {'
#		htmout += '			img = "<img src=", myb64[k], "></a><br>"'
#		htmout += '			document.write( img );'
#		htmout += '			}'
#		htmout += '		</script>'

		htmfil.write( htmout )
		htmfil.write( jsout )
		htmfil.close()

		csvfil.write( csvout )
		csvfil.close()
#		print( progid,dttm, "MSG_360: startup_b64 htm_pathfile=", htm_pathfile)
#		print( progid,dttm, "MSG_360: startup_b64 csv_pathfile=", csv_pathfile)
		exit()

	if( sys.argv[1] == "tl" ):
		import base64
		j=0
		pathdir=sys.argv[2]
		chars_to_remove = [ '.', '*' ]
		pathcode=pathdir.translate(None,''.join(chars_to_remove))
		pathcode=pathcode.replace("/","-")
		pathcode=pathcode.replace("-","", 1)

		ka1_tl_html = ""
		ka1_tl_html += ka1_tl_html_hdr()
		ka1_tl_html += ka1_tl_html_dta()
		ka1_tl_html += ka1_tl_html_json_hdr()
		ka1_tl_html += ka1_tl_html_json_dta()
		ka1_tl_html += ka1_tl_html_json_ftr()
		ka1_tl_html += ka1_tl_html_ftr()
		print( ka1_tl_html)
		exit()

		if( pathdir == "" ): pathdir="."; pathcode="";

		pathfiles=ko_glob( pathdir )
#		print( progid,dttm, "MSG: startup_b64 pathdir=", pathdir)
#		print( progid,dttm, "MSG: startup_b64 pathcode=", pathcode)
#		b64_pathfile=pathdir+"/"+"b64_"+base

		htm_pathfile="./"+progid+"_b64_"+pathcode+".htm"
		htm_pathfile = htm_pathfile.replace( "-.htm", ".htm" )

		csv_pathfile="./"+progid+"_b64_"+pathcode+".csv"
		csv_pathfile = csv_pathfile.replace( "-.csv", ".csv" )

#		print( progid,dttm, "MSG: startup_b64 htm_pathfile=", htm_pathfile)
#		print( progid,dttm, "MSG: startup_b64 csv_pathfile=", csv_pathfile)
		csvfil = open(csv_pathfile, "wb" )

		csvout = ''
		jsout = ""
		htmout = ""

		csvout = "recno,progid,status,dttm,pathfile,path,base,file,ext,filsiz,ctime,desc"
		print( "BUGS270 csvout=" + csvout)

		htmfil = open(htm_pathfile, "wb" )
#		jsout += '<script id="script_',pathcode,'" >\n'
		jsout += "<script id='script_myb64'\n"

		jsout += "function load_myb64() {\n"

		jsout += "	var myb64 = new array()\n"

# bugs tuple 	htmout += "	<div id='", pathcode, "' >\n"
# bugs tuple	htmout += '	<div id="', pathcode[0], '" >\n'
		htmout += '	<div id="div_myb64" >\n'

		for pathfile in pathfiles:
			j=j+1
			dttm=kodts('')
			path=os.path.dirname(pathfile)
			base=os.path.basename(pathfile)
			file=os.path.splitext(base)[0]
			ext=os.path.splitext(base)[1]
			filecode_tuple=str(j),"-",file,"-",ext
			filecode = "".join(filecode_tuple)
			print( progid,dttm,j,"pathfile=",pathfile, path, base,file,ext)
			print( progid,dttm,j,"filecode=",filecode)
			print( progid,dttm,j,"filecode_tuple=",filecode_tuple)

			b64dta=""
			if( os.path.isfile( pathfile )):	


				filesize = os.path.getsize(pathfile)
				ctime=time.ctime(os.path.getctime(pathfile))
				ctime_ymd = time.strftime('%Y-%m-%d_%H:%M:%S', time.gmtime(os.path.getmtime(pathfile)))


# err				ctime=os.path.getctime(pathfile)
#				ctime_ymd =  datetime.datetime.strftime(ctime,'%Y-%m-%d_%H:%M:%S')  # This writes "06/24/1984"
#				print( progid,dttm,j,"ctime_ymd=",ctime_ymd)
#				ctime_ymd = "YYYY-MM-SS_hh:mm:ss"
#				ctime_ymd =  ctime.strftime('%Y-%m-%d_%H:%M:%S')  # This writes "06/24/1984"
#				d = datetime.strptime(time.ctime(),"%a %b %d %H:%M:%S %Y")
#				d = datetime.strptime(ctime,"%a %b %d %H:%M:%S %Y")
#				d = time.ctime(os.path.getctime(pathfile))
#				ctime_ymd = d.strftime('%Y-%d-%m_%H:%M:%S')
				print( progid,dttm,j,"ctime_ymd=",ctime_ymd,filesize,pathfile)

				image = open( pathfile, 'rb') 
				imgbin = image.read()
#				b64dta = base64.encodestring(imgbin)
				b64dta = base64.b64encode(imgbin)
				b64ext = ext.replace( '.', '' )	

				csvout += "{},{},{},{},{},{},{},{},{},{},{},\n".format(
					j,"status",progid,dttm,pathfile,path,base,file,ext,
					filesize,ctime_ymd,"desc")

#				jsout += 'myb64[{}] = "data:image/{};base64,{}"\n'.format(j, b64ext, b64dta )
# bugs tuple			jsout += 'myb64['",filecode,"'] = "data:image/png;base64,{}"\n'.format(j, b64dta )
				jsout += 'myb64['
# bugs tuple				jsout += filecode.join()
				jsout += '] = "data:image/{};base64,{}"\n'.format( b64ext, b64dta )
				
				htmout += "\n"
				print( "BUGS_350 filecode=",filecode)
#				htmout += '<a href=?q=myb64,',filecode,' id="',filecode,'" target=_blank >\n'
				htmout += '<a href=?q=myb64_{} id="{}" target=_blank >\n'.format( filecode, filecode )
#				htmout += '	<img id="{}" src="data:image/{};base64,{}"><br>\n'.format(filecode,b64ext,b64dta)
#				htmout += '	<img src="data:image/{};base64,{}"><br>\n'.format(b64ext,b64dta)
				htmout += '{} {} <img src="data:image/{};base64,{}">\n'.format(j,filecode, b64ext, b64dta )

				print( progid,dttm,j, "BUGS_322: b64dta=",b64dta,"xxxxxxxxx")
				
#				if( not os.path.isfile( b64_pathfile )):
#					print( progid,dttm,j,"b64_pathfile=",b64_pathfile)
#					b64ddta = base64.decodestring(b64dta) 
#					b64img = open(b64_pathfile, 'wb')
##					b64img = open('deer_decode.gif', 'wb')
#					b64img.write(b64ddta)

#			print( progid,dttm,j,"pathfile b64dta=",pathfile, b64dta)
			print( progid,dttm,j,"pathfile=",pathfile)

		jsout += "	return(myb64)\n"
		jsout += "	}\n"
		jsout += "	</script>\n"


		htmout += "		</div>\n"

#		htmout += '	<script id="script_myb64">'
#		htmout += '		var img, k;'
#		htmout += '		for( k=0; k<j; k++ ) {'
#		htmout += '			img = "<img src=", myb64[k], "></a><br>"'
#		htmout += '			document.write( img );'
#		htmout += '			}'
#		htmout += '		</script>'

		htmfil.write( htmout )
		htmfil.write( jsout )
		htmfil.close()

		csvfil.write( csvout )
		csvfil.close()
#		print( progid,dttm, "MSG_360: startup_b64 htm_pathfile=", htm_pathfile)
#		print( progid,dttm, "MSG_360: startup_b64 csv_pathfile=", csv_pathfile)
		exit()

	if( sys.argv[1] == "glob" ):
		j=0
		out=ko_glob( sys.argv[2] )
		print( progid,dttm, "MSG: startup_glob path", sys.argv[2])
		print( progid,dttm, "MSG: startup_glob out=", out)
		for pathfile in out:
			j=j+1
			path=os.path.dirname(pathfile)
			base=os.path.basename(pathfile)
			file=os.path.splitext(base)[0]
			ext=os.path.splitext(base)[1]
			
			print( j,"pathfile=",pathfile, path, base,file,ext)
		exit()

	if( sys.argv[1] == "ls" ):
		out = ko_ls( sys.argv[2], sys.argv[3] )
		print( progid,dttm, "MSG: startup_ls", out)
		exit()


#	if( sys.argv[1].match("listdir")):
	if( sys.argv[1] == "listdir" ):
		print( progid,dttm, "MSG: startup_listdir")
		ko_listdir( a1, a2, a3 )
		exit()

#	if( sys.argv[1].match("walk")):
	if( a1 == "walk" ):
		print( progid,dttm, "MSG: startup_walk")
		ko_walk( sys.argv[2], sys.argv[3] )
		exit()


	if( sys.argv[1] == "gifs2gifs" ):
		gif1 = sys.argv[2]
		gif2 = sys.argv[3]
		gifs = load_gifs()
		j=0
		for gif in gifs:
			j=j+1
			print( "gif2gifs DISABLE j={} gif={}".format(j, gif))
#			gif2gifs( gif )
		exit()

	if( sys.argv[1] == "gif2size" ):
		gifold = sys.argv[2]
		sizexy = sys.argv[3]
#		giftmp = "tmp.gif"
		giftmp = gifold.replace( ".gif", "_tmp.gif" )

		sizexy_default = "200x80"
		if( sizexy == "." ): sizexy = sizexy_default

		giftag = "_{}.gif".format( sizexy )
		gifnew = gifold.replace( ".gif", giftag )

#		convert do.gif -coalesce temporary.gif
		convert_coalesce = "convert {} -coalesce {}".format( gifold, giftmp )
		print( "gif2size convert_coalesce={} ".format(convert_coalesce))
		os.system( convert_coalesce )



#		convert -size <original size> temporary.gif -resize 24x24 smaller.gif
#		convert_gif2size = "convert -size {} -resize {} {}".format(  giftmp, sizexy, gifnew )
		convert_gif2size = "convert {}  -resize {} {}".format(  giftmp, sizexy, gifnew )


#		print( "gif2size gifold={} giftmp={} gifnew={}".format(gifold, giftmp, gifnew))
		print( "gif2size convert_gif2size={} ".format(convert_gif2size))
		os.system( convert_gif2size )







		exit()

	if( sys.argv[1] == "gif2gifs" ):
		gif1 = sys.argv[2]
		gif2 = sys.argv[3]

		print( "gif2gifs gif={}".format(gif1))
		gif2gifs( gif1 )
		exit()

	if( sys.argv[1] == "png2gif" ):
		gif = sys.argv[2]
		png = sys.argv[3]
		if( png == "." ): png="imgs/btn/koeye.png"
		if( png == "." ): png="imgs/ani/work/knot/koeye_100x40.png"
		png2gif( gif,png )
		exit()

	if( sys.argv[1] == "usid2host" ):
		usid = sys.argv[2]
		grp = sys.argv[3]
		ko_usid2host( usid, grp )
		exit()

	if( sys.argv[1] == "wiisk" ):
		usid = sys.argv[2]
		grp = sys.argv[3]
		wiisk( usid, grp,"" )
		exit()
	if( sys.argv[1] == "wiijk" ):
		usid = sys.argv[2]
		grp = sys.argv[3]
		wiijk( usid, grp,"" )
		exit()
	if( sys.argv[1] == "wii" ):
		usid = sys.argv[2]
		grp = sys.argv[3]
		wii( usid, grp,"" )
		exit()
	if( sys.argv[1] == "jkwii" ):
		usid = sys.argv[2]
		grp = sys.argv[3]
		exit()


	print( progid, "ERR: unsupported command")
	print( "argc=", len(sys.argv))
	print( "args=", str(sys.argv))
	print( "a0={} argv0={}".format(a0, str(sys.argv[0])))
	print( "a1={} argv1={}".format(a1, str(sys.argv[1])))
	print( "a2={} argv2={}".format(a2, str(sys.argv[2])))
	print( "a3={} argv3={}".format(a3, str(sys.argv[3])))

def commands():
	import re
	print( sys.argv[1])
	if re.match( sys.argv[1], 'help' ):
		print( progid, "MSG: help")
	print( progid, "ERR: unsupported cmd")
	return 



def ko_dir2b64():
	import base64
	encoded = base64.b64encode(open("ka1.png", "rb").read())

# b64encode ka1.png X | sed '1d;$d' | tr -d '\n' > b64_ka.png
# <img src="data:image/png;base64,ENCODED_PNG"
# 
# im: composite {overlay} {background} [{mask}] [-compose {method}]   {result}
# im: convert  {background} {overlay} [{mask}] [-compose {method}] -composite   {result}


# pqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpq
# bdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbd

def ka1_av_html_read(filename):
	file = open( filename, "r" )
	print( file.read())
	print( file.readline(100))
	print( file.readlines())
	for line in file:
		print( line,)

def ka1_av_html_hdr():
	ka1_av_html_hdr = "ka1_av_html_hdr\n" 
	return( ka1_av_html_hdr );

def ka1_av_html_dta():
	ka1_av_html_dta = "ka1_av_html_dta\n"
	return( ka1_av_html_dta );

def ka1_av_html_ftr():
	ka1_av_html_ftr = "ka1_av_html_ftr\n"
	return( ka1_av_html_ftr);


def ka1_tl_html_hdr():
	ka1_tl_html_hdr = "ka1_tl_html_hdr"
	return( ka1_tl_html_hdr );

def ka1_tl_html_json_htr():
	ka1_tl_html_json_htr = "ka1_tl_html_json_hdr"
	return( ka1_tl_html_json_hdr );

def ka1_tl_html_json_dta():
	ka1_tl_html_json_dta = "ka1_tl_html_json_dta"
	return( ka1_tl_html_json_dta );

def ka1_tl_html_json_ftr():
	ka1_tl_html_json_ftr = "} ] } } \n"
	return( ka1_tl_html_json_ftr );


def ka1_tl_html_ftr():
	ka1_tl_html_ftr = "ka1_tl_html_ftr"
	return( ka1_tl_html_ftr );


def ko_do_sl(a0,a1,a2,a3):
	dttm=kodts('')
	print( '{} {} ko_do_sl: a0={} a1={} a2={} a3={}'.format(progid,dttm, a0,a1,a2,a3))
	json_beg=''
	dttm=kodts('')

	ifile=a2
	ofile=a3
	if ofile == '': 
		ofile=ifile.replace('.wl', '.htm')
	print( '{} {} ko_do_sl MSG_2300 ifile={} ofile={}'.format(progid, dttm, ifile,ofile))

	if os.path.isfile( ofile ):
		print( '{} {} ko_do_sl ERR_FOUND: ofile={}'.format(progid,dttm, ofile ))
#		exit()
	else:
		print( '{} {} ko_do_sl MSG_NOTFOUND: ofile={}'.format(progid,dttm, ofile ))

	if not os.path.isfile( ifile ):
		print( '{} {} ko_do_sl ERR_NOTFOUND: ifile={}'.format(progid,dttm, ifile ))
		exit()
	else:
		print( '{} {} ko_do_sl MSG_FOUND: ifile={}'.format(progid,dttm, ifile ))

#	if not os.path.isdir( tnpath ):
#		os.system( syscmd )
	
#import os.path, time
#	print("last modified: %s" % time.ctime(os.path.getmtime(ifile)))
#	print("created: %s" % time.ctime(os.path.getctime(ifile)))

# import os, time
	(mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime) = os.stat(ifile)
#	print("last modified: %s" % time.ctime(mtime))
#	print("atime: %s" % time.ctime(atime))
	print("created: %s" % time.ctime(ctime))

	(day, mth, dd, hh_mm_ss, yyyy ) = time.ctime(ctime).split()
	hhmmss=hh_mm_ss.replace( ':', ',' )
	mm=mth2num(mth)
	yyyymmdd='{},{},{}'.format( yyyy,mm,dd )
#	print( '{} {} ko_do_tl MSG_DATE: ifile={} day={}, mth={}, dd={},hh_mm_ss={}, yyyy={} size={}'.format(progid,dttm, ifile, day,mth,dd,hh_mm_ss,yyyy, size ))
	print( '{} {} ko_do_tl MSG_DATE: ifile={} yyyymmdd={}, hhmmss={}, size={}'.format(progid,dttm, ifile, yyyymmdd,hhmmss, size ))
	
# json_defail
	document_root_ko0="/home2/kozerus/public_html"
	document_root_ko2="/home1/kotwous/public_html"
	document_root_ka10="/ht"
	document_root_ka11="/Volumes/ka1tbr1/ht"
	document_root_ka12="/Volumes/ka1tbr2/ht"
	document_root=document_root_ka12



	json_detail=''
	psvline=''
	htmline=''
	wlfile=a2
	if( os.path.exists( wlfile )):
		ifmt='wl'
		
		with open(wlfile) as f:
			j=0
			for line in f:
				j += 1

#				m = re.match( '.psv', wlfile )
#				if m:
#				print( 'BUGS_RE re.search={}'.format( re.search( '.psv$', wlfile )))
#				if re.search( '.psv$', wlfile ):

				if ifmt == 'psv':
					pathfile=line.split('|')[13]
					print( '{} {} MSG_PSV: wlfile={} pathfile={}'.format( progid,dttm,wlfile, pathfile))
				else:
					pathfile=line.split()[8]
					print( '{} {} MSG_WL: wlfile={} pathfile={}'.format( progid,dttm,wlfile, pathfile))


				path=os.path.dirname(pathfile)
				base=os.path.basename(pathfile)
				file=os.path.splitext(base)[0]
				ext=os.path.splitext(base)[1]



				path=path.replace(document_root_ko0,'')
				path=path.replace(document_root_ko2,'')
				path=path.replace(document_root_ka10,'')
				path=path.replace(document_root_ka11,'')
				path=path.replace(document_root_ka12,'')

				print( '{} {} do_tl MSG_2500: j={} pathfile={} path={} base={} file={} ext={}'.format( progid, dttm, j, pathfile, path, base, file, ext ))
				ht_pathfile='{}{}{}'.format(path,file,ext)	

				o_pathfile_htm=a2.replace(".txt", ".htm")
				divid=a2.replace(".txt","")
				htmdiv='<div id="{}">\n'.format( divid )

# for filename in os.listdir(DIRECTORY):
#    if (filename.endswith(".mp4"): #or .avi, .mpeg, whatever.
#        os.system("ffmpeg -i {0} -f image2 -vf fps=fps=1 output%d.png".format(filename))
#    else:
#        continue

				i_pathfile='{}{}/{}'.format(document_root,path,base)
				i_pathfile_mp4='{}{}/{}'.format(document_root,path,base)
				o_pathfile_jpg='{}{}/img/{}_%03d.jpg'.format(document_root,path,file)
				i_pathfile_jpg1='{}{}/img/{}_001.jpg'.format(document_root,path,file)
				i_pathfile_jpgs='{}{}/img/{}_*.jpg'.format(document_root,path,file)
				o_pathfile_png='{}{}/tn/tn_{}.png'.format(document_root,path,file)
				o_pathfile_gif='{}{}/tn/tn_{}.gif'.format(document_root,path,file)


				o_pathfile='{}{}/img/{}_%03d.jpg'.format(document_root,path,file)
				o_pathfile_im='{}{}/img/{}_%03d.jpg'.format(document_root,path,file)
				o_pathfile_tn='{}{}/img/{}_%03d.gif'.format(document_root,path,file)

				print( "BUGS_141 i_pathfile={}".format(i_pathfile))
				print( "BUGS_142 ht_pathfile={}".format(ht_pathfile))
				if ext=='.mp4' : print( "BUGS_141 i_pathfile_mp4={}".format(i_pathfile_mp4))
				if ext=='.jpg' : print( "BUGS_142 o_pathfile_jpg={}".format(o_pathfile_jpg))
#				if ext=='.jpg' : print( "BUGS_144 i_pathfile_jpg1={}".format(i_pathfile_jpg1))
#				if ext=='.jpg' : print( "BUGS_145 i_pathfile_jpgs={}".format(i_pathfile_jpgs))
				if ext=='.gif' : print( "BUGS_146 o_pathfile_gif={}".format(o_pathfile_gif))
				if ext=='.png' : print( "BUGS_146 o_pathfile_png={}".format(o_pathfile_png))


				abs_tn_path='{}{}/tn/'.format(document_root, path)
				tn_path='{}/tn/'.format(path)
				tn_base='tn_{}.gif'.format(file)

				abs_tn_pathfile='{}{}{}'.format( document_root, tn_path, tn_base )
				tn_pathfile='{}{}'.format( tn_path, tn_base )

				abs_im_path='{}{}/img/'.format(document_root,path)
				im_path='{}/img/'.format(path)
				im_base='{}.png'.format(file)
				abs_im_pathfile='{}{}{}'.format( document_root, im_path, im_base )
				im_pathfile='{}{}'.format(  im_path, im_base )


				startdate_yyyy='2019'
				startdate_mm='01'
				startdate_dd='01'
				startdate='{},{},{}'.format(startdate_yyyy,startdate_mm,startdate_dd)
				enddate_yyyy='2019'
				enddate_mm='01'
				enddate_dd='31'
				enddate='{},{},{}'.format(enddate_yyyy,enddate_mm,enddate_dd)
				startdate=yyyymmdd
				enddate=yyyymmdd

				headline='headline_end ifile={}'.format(ifile)
				text='text_end ifile={} dttm={} ofile={}'.format(ifile, dttm, ofile )
				tag='tage_end ifile={}'.format( ifile )
				media='/imgs/btn/koeye.png'
				tn=ht_pathfile
				media=ht_pathfile
#				media='<a href="{}" target=_blank><img src="{}" alt="{}" border=0></a>'.format( ht_pathfile, ht_pathfile, tn )
#				thumbnail='/imgs/btn/tn/tn_koeye.png'
				thumbnail='/tn/tn_{}'.format( tn )
				credit='credit_end ht_pathfile={} dttm={}'.format( ht_pathfile, dttm )
				caption='caption ht_pathfile={} dttm={}'.format( ht_pathfile, dttm )
				tn=pathfile.replace('/IMG', '/tn/tn_IMG').replace('JPG','png')

				htmline += '<a href="/{}" class="thumb_link">'.format(pathfile)
				htmline += '	<span class="selected"></span>\n'
				htmline += '	<img src="/{}" height=100 title="{}" alt="{}" class="thumb" />\n'.format(tn, file, file)
				htmline += '\n'

				print( '{} {} MSG_2400 j={} htmline={}'.format(j,progid,dttm,htmline))


	
				psvline += 'id_{}|'.format(j)
				psvline += 'status_{}|'.format(j)
				psvline += 'dttm_{}|'.format(dttm)
				psvline += 'code_{}|'.format(j)
				psvline += 'grp_{}|'.format(j)
				psvline += 'idx_{}|'.format(j)
				psvline += 'tlid_{}|'.format(j)
				psvline += 'title_{}|'.format(j)
				psvline += 'begdt_{}|'.format(startdate)
				psvline += 'enddt_{}|'.format(enddate)
				psvline += 'headline_{}|'.format(ifile)
				psvline += 'tag_{}|'.format(j)
				psvline += 'media_{}|'.format(ifile)
				psvline += 'tn_{}|'.format(ifile)
				psvline += 'credit_{}|'.format(j)
				psvline += 'eras_{}|'.format(j)
				psvline += 'e_begdt_{}|'.format(j)
				psvline += 'e_enddt{}|'.format(j)
				psvline += 'e_head{}|'.format(j)
				psvline += 'etag_{}|'.format(j)
				psvline += 'charts_{}|'.format(j)
				psvline += 'c_begdt{}|'.format(j)
				psvline += 'c_enddt{}|'.format(j)
				psvline += 'c_head{}|'.format(headline)
				psvline += 'c_val{}|'.format(j)
				psvline += 'filddt{}|'.format(startdate)
				psvline += 'exifdt_{}|'.format(j)
				psvline += 'tempdt_{}|'.format(j)
				psvline += 'desc_{}|'.format(j)
				psvline += '\n'


	psvhdr  = ''
	psvhdr += 'id|status|dttm|code|grp|idx|tlid|'
	psvhdr += 'title|begdt|enddt|headline|tag|'
	psvhdr += 'media|tn|credit|'
	psvhdr += 'eras|e_begdt}e_enddt}e_head}e_tag|'
	psvhdr += 'charts|c_begdt|c_enddt|c_head|c_val|'
	psvhdr += 'filedt|exifdt|tempdt|desc|b64'
	psvhdr += '\n'
	psvdata = ''
	psvdata += psvhdr
	psvdata += psvline

	ofile_psv=ofile
	out_file_psv=open( ofile, "wb" )
	out_file_psv.write(htmline)
	out_file_psv.close()

#	csvdata=psvdata.replace('|', ',')
#	ofile_csv=ofile.replace('.psv', '.csv')

#	out_file_csv=open( ofile_csv, "wb" )
#	out_file_csv.write(csvdata)
#	out_file_csv.close()



	dttm=kodts('')
	print( '{} {} MSG_END: do_tlwl ifile={} ofile={}'.format(progid, dttm, ifile, ofile ))
	return(psvdata)











def day2num(day):
	return{
	        'Sun' : 1,
	        'Mon' : 2,
	        'Tue' : 3,
	        'Wed' : 4,
	        'Thr' : 5,
	        'Fri' : 6,
	        'Sat' : 7
		}[day]

def mth2num(mth):
	return{
	        'Jan' : 1,
	        'Feb' : 2,
	        'Mar' : 3,
	        'Apr' : 4,
	        'May' : 5,
	        'Jun' : 6,
	        'Jul' : 7,
	        'Aug' : 8,
	        'Sep' : 9, 
	        'Oct' : 10,
	        'Nov' : 11,
	        'Dec' : 12
		}[mth]
def ko_do_tl(a0,a1,a2,a3):
	print( '{} {} ko_do_tlpsv: a0={} a1={} a2={} a3={}'.format(progid,dttm, a0,a1,a2,a3))

def ko_do_tlwl(a0,a1,a2,a3):
	dttm=kodts('')
	print( '{} {} ko_do_tlwl: a0={} a1={} a2={} a3={}'.format(progid,dttm, a0,a1,a2,a3))
	json_beg=''
	dttm=kodts('')

	ifile=a2
	ofile=a3
	if ofile == '': 
		ofile=ifile.replace('.wl', '.json')
	print( '{} {} ko_do_tlwl MSG_2300 ifile={} ofile={}'.format(progid, dttm, ifile,ofile))

	if os.path.isfile( ofile ):
		print( '{} {} ko_do_tl ERR_FOUND: ofile={}'.format(progid,dttm, ofile ))
#		exit()
	else:
		print( '{} {} ko_do_tl MSG_NOTFOUND: ofile={}'.format(progid,dttm, ofile ))

	if not os.path.isfile( ifile ):
		print( '{} {} ko_do_tl ERR_NOTFOUND: ifile={}'.format(progid,dttm, ifile ))
		exit()
	else:
		print( '{} {} ko_do_tl MSG_FOUND: ifile={}'.format(progid,dttm, ifile ))

#	if not os.path.isdir( tnpath ):
#		os.system( syscmd )
	

#import os.path, time
#	print("last modified: %s" % time.ctime(os.path.getmtime(ifile)))
#	print("created: %s" % time.ctime(os.path.getctime(ifile)))

# import os, time
	(mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime) = os.stat(ifile)
#	print("last modified: %s" % time.ctime(mtime))
#	print("atime: %s" % time.ctime(atime))
	print("created: %s" % time.ctime(ctime))

	(day, mth, dd, hh_mm_ss, yyyy ) = time.ctime(ctime).split()
	hhmmss=hh_mm_ss.replace( ':', ',' )
	mm=mth2num(mth)
	yyyymmdd='{},{},{}'.format( yyyy,mm,dd )
#	print( '{} {} ko_do_tl MSG_DATE: ifile={} day={}, mth={}, dd={},hh_mm_ss={}, yyyy={} size={}'.format(progid,dttm, ifile, day,mth,dd,hh_mm_ss,yyyy, size ))
	print( '{} {} ko_do_tl MSG_DATE: ifile={} yyyymmdd={}, hhmmss={}, size={}'.format(progid,dttm, ifile, yyyymmdd,hhmmss, size ))
	
# json_defail
	document_root_ko0="/home2/kozerus/public_html"
	document_root_ko2="/home1/kotwous/public_html"
	document_root_ka10="/ht"
	document_root_ka11="/Volumes/ka1tbr1/ht"
	document_root_ka12="/Volumes/ka1tbr2/ht"
	document_root=document_root_ka12



	json_detail=''
	psvline=''
	wlfile=a2
	if( os.path.exists( wlfile )):
		ifmt='wl'
		
		with open(wlfile) as f:
			j=0
			for line in f:
				j += 1

#				m = re.match( '.psv', wlfile )
#				if m:
#				print( 'BUGS_RE re.search={}'.format( re.search( '.psv$', wlfile )))
#				if re.search( '.psv$', wlfile ):

				if ifmt == 'psv':
					pathfile=line.split('|')[13]
					print( '{} {} MSG_PSV: wlfile={} pathfile={}'.format( progid,dttm,wlfile, pathfile))
				else:
					pathfile=line.split()[8]
					print( '{} {} MSG_WL: wlfile={} pathfile={}'.format( progid,dttm,wlfile, pathfile))


				path=os.path.dirname(pathfile)
				base=os.path.basename(pathfile)
				file=os.path.splitext(base)[0]
				ext=os.path.splitext(base)[1]



				path=path.replace(document_root_ko0,'')
				path=path.replace(document_root_ko2,'')
				path=path.replace(document_root_ka10,'')
				path=path.replace(document_root_ka11,'')
				path=path.replace(document_root_ka12,'')

				print( '{} {} do_tl MSG_2500: j={} pathfile={} path={} base={} file={} ext={}'.format( progid, dttm, j, pathfile, path, base, file, ext ))
				ht_pathfile='{}{}{}'.format(path,file,ext)	

				o_pathfile_htm=a2.replace(".txt", ".htm")
				divid=a2.replace(".txt","")
				htmdiv='<div id="{}">\n'.format( divid )

# for filename in os.listdir(DIRECTORY):
#    if (filename.endswith(".mp4"): #or .avi, .mpeg, whatever.
#        os.system("ffmpeg -i {0} -f image2 -vf fps=fps=1 output%d.png".format(filename))
#    else:
#        continue

				i_pathfile='{}{}/{}'.format(document_root,path,base)
				i_pathfile_mp4='{}{}/{}'.format(document_root,path,base)
				o_pathfile_jpg='{}{}/img/{}_%03d.jpg'.format(document_root,path,file)
				i_pathfile_jpg1='{}{}/img/{}_001.jpg'.format(document_root,path,file)
				i_pathfile_jpgs='{}{}/img/{}_*.jpg'.format(document_root,path,file)
				o_pathfile_png='{}{}/tn/tn_{}.png'.format(document_root,path,file)
				o_pathfile_gif='{}{}/tn/tn_{}.gif'.format(document_root,path,file)


				o_pathfile='{}{}/img/{}_%03d.jpg'.format(document_root,path,file)
				o_pathfile_im='{}{}/img/{}_%03d.jpg'.format(document_root,path,file)
				o_pathfile_tn='{}{}/img/{}_%03d.gif'.format(document_root,path,file)

				print( "BUGS_141 i_pathfile={}".format(i_pathfile))
				print( "BUGS_142 ht_pathfile={}".format(ht_pathfile))
				if ext=='.mp4' : print( "BUGS_141 i_pathfile_mp4={}".format(i_pathfile_mp4))
				if ext=='.jpg' : print( "BUGS_142 o_pathfile_jpg={}".format(o_pathfile_jpg))
#				if ext=='.jpg' : print( "BUGS_144 i_pathfile_jpg1={}".format(i_pathfile_jpg1))
#				if ext=='.jpg' : print( "BUGS_145 i_pathfile_jpgs={}".format(i_pathfile_jpgs))
				if ext=='.gif' : print( "BUGS_146 o_pathfile_gif={}".format(o_pathfile_gif))
				if ext=='.png' : print( "BUGS_146 o_pathfile_png={}".format(o_pathfile_png))


				abs_tn_path='{}{}/tn/'.format(document_root, path)
				tn_path='{}/tn/'.format(path)
				tn_base='tn_{}.gif'.format(file)

				abs_tn_pathfile='{}{}{}'.format( document_root, tn_path, tn_base )
				tn_pathfile='{}{}'.format( tn_path, tn_base )

				abs_im_path='{}{}/img/'.format(document_root,path)
				im_path='{}/img/'.format(path)
				im_base='{}.png'.format(file)
				abs_im_pathfile='{}{}{}'.format( document_root, im_path, im_base )
				im_pathfile='{}{}'.format(  im_path, im_base )


				startdate_yyyy='2019'
				startdate_mm='01'
				startdate_dd='01'
				startdate='{},{},{}'.format(startdate_yyyy,startdate_mm,startdate_dd)
				enddate_yyyy='2019'
				enddate_mm='01'
				enddate_dd='31'
				enddate='{},{},{}'.format(enddate_yyyy,enddate_mm,enddate_dd)
				startdate=yyyymmdd
				enddate=yyyymmdd

				headline='headline_end ifile={}'.format(ifile)
				text='text_end ifile={} dttm={} ofile={}'.format(ifile, dttm, ofile )
				tag='tage_end ifile={}'.format( ifile )
				media='/imgs/btn/koeye.png'
				tn=ht_pathfile
				media=ht_pathfile
#				media='<a href="{}" target=_blank><img src="{}" alt="{}" border=0></a>'.format( ht_pathfile, ht_pathfile, tn )
#				thumbnail='/imgs/btn/tn/tn_koeye.png'
				thumbnail='{}'.format( tn )
				credit='credit_end ht_pathfile={} dttm={}'.format( ht_pathfile, dttm )
				caption='caption ht_pathfile={} dttm={}'.format( ht_pathfile, dttm )

	
				psvline += 'id_{}|'.format(j)
				psvline += 'status_{}|'.format(j)
				psvline += 'dttm_{}|'.format(dttm)
				psvline += 'code_{}|'.format(j)
				psvline += 'grp_{}|'.format(j)
				psvline += 'idx_{}|'.format(j)
				psvline += 'tlid_{}|'.format(j)
				psvline += 'title_{}|'.format(j)
				psvline += 'begdt_{}|'.format(startdate)
				psvline += 'enddt_{}|'.format(enddate)
				psvline += 'headline_{}|'.format(ifile)
				psvline += 'tag_{}|'.format(j)
				psvline += 'media_{}|'.format(ifile)
				psvline += 'tn_{}|'.format(ifile)
				psvline += 'credit_{}|'.format(j)
				psvline += 'eras_{}|'.format(j)
				psvline += 'e_begdt_{}|'.format(j)
				psvline += 'e_enddt{}|'.format(j)
				psvline += 'e_head{}|'.format(j)
				psvline += 'etag_{}|'.format(j)
				psvline += 'charts_{}|'.format(j)
				psvline += 'c_begdt{}|'.format(j)
				psvline += 'c_enddt{}|'.format(j)
				psvline += 'c_head{}|'.format(headline)
				psvline += 'c_val{}|'.format(j)
				psvline += 'filddt{}|'.format(startdate)
				psvline += 'exifdt_{}|'.format(j)
				psvline += 'tempdt_{}|'.format(j)
				psvline += 'desc_{}|'.format(j)
				psvline += '\n'


	psvhdr  = ''
	psvhdr += 'id|status|dttm|code|grp|idx|tlid|'
	psvhdr += 'title|begdt|enddt|headline|tag|'
	psvhdr += 'media|tn|credit|'
	psvhdr += 'eras|e_begdt}e_enddt}e_head}e_tag|'
	psvhdr += 'charts|c_begdt|c_enddt|c_head|c_val|'
	psvhdr += 'filedt|exifdt|tempdt|desc|b64'
	psvhdr += '\n'
	psvdata = ''
	psvdata += psvhdr
	psvdata += psvline

	ofile_psv=ofile
	out_file_psv=open( ofile, "wb" )
	out_file_psv.write(psvdata)
	out_file_psv.close()

	csvdata=psvdata.replace('|', ',')
	ofile_csv=ofile.replace('.psv', '.csv')

	out_file_csv=open( ofile_csv, "wb" )
	out_file_csv.write(csvdata)
	out_file_csv.close()



	dttm=kodts('')
	print( '{} {} MSG_END: do_tlwl ifile={} ofile={}'.format(progid, dttm, ifile, ofile ))
	return(psvdata)


def ko_do_tlpsv(a0,a1,a2,a3):
	dttm=kodts('')
	print( '{} {} ko_do_tlpsv: a0={} a1={} a2={} a3={}'.format(progid,dttm, a0,a1,a2,a3))
	json_beg=''
	dttm=kodts('')
	exit()

	ifile=a2
	ofile=a3
	if re.search( '.psv' ):
		delimeter='|'
		if ofile == '': ofile=ifile.replace('.psv', '.json')
	else:
		delimeter=','
		if ofile == '': ofile=ifile.replace('.csv', '.json')

	if os.path.isfile( ofile ):
		print( '{} {} ko_do_tl ERR_FOUND: ofile={}'.format(progid,dttm, ofile ))
		exit()
	else:
		print( '{} {} ko_do_tl MSG_NOTFOUND: ofile={}'.format(progid,dttm, ofile ))

	if not os.path.isfile( ifile ):
		print( '{} {} ko_do_tl ERR_NOTFOUND: ifile={}'.format(progid,dttm, ifile ))
		exit()
	else:
		print( '{} {} ko_do_tl MSG_FOUND: ifile={}'.format(progid,dttm, ifile ))

#	if not os.path.isdir( tnpath ):
#		os.system( syscmd )
	

#import os.path, time
#	print("last modified: %s" % time.ctime(os.path.getmtime(ifile)))
#	print("created: %s" % time.ctime(os.path.getctime(ifile)))

# import os, time
	(mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime) = os.stat(ifile)
#	print("last modified: %s" % time.ctime(mtime))
#	print("atime: %s" % time.ctime(atime))
	print("created: %s" % time.ctime(ctime))

	(day, mth, dd, hh_mm_ss, yyyy ) = time.ctime(ctime).split()
	hhmmss=hh_mm_ss.replace( ':', ',' )
	mm=mth2num(mth)
	yyyymmdd='{},{},{}'.format( yyyy,mm,dd )
#	print( '{} {} ko_do_tlpsv MSG_DATE: ifile={} day={}, mth={}, dd={},hh_mm_ss={}, yyyy={} size={}'.format(progid,dttm, ifile, day,mth,dd,hh_mm_ss,yyyy, size ))
	print( '{} {} ko_do_tlpsv MSG_DATE: ifile={} yyyymmdd={}, hhmmss={}, size={}'.format(progid,dttm, ifile, yyyymmdd,hhmmss, size ))
	exit()
	


# json_beg
	headline='<h1>ofile={} main {} timeline headline: ofile={}</h1>'.format(ifile, dttm, ofile)
# bugs	headline='<a href="{}" target=_blank><img src="{}" border=0></a>'.format( ifile, ifile )
	type='default'
	text='header_text yyyymmdd={} day={} size={}'.format( yyyymmdd, day, size )
	startdate_beg='1900,01,01'
	startdate_beg=yyyymmdd

	json_beg+='{"timeline": { \n'
	json_beg+='"headline":"{}",\n'.format(headline)
	json_beg+='"type":"{}",\n'.format(type)
	json_beg+='"text":"{}",\n'.format(text)
	json_beg+='"startDate":"{}",\n'.format(startdate_beg)
	json_beg+='"date": [\n'

#	print( 'json_beg={}\n'.format(json_beg))





# json_defail
	document_root_ko0="/home2/kozerus/public_html"
	document_root_ko2="/home1/kotwous/public_html"
	document_root_ka10="/ht"
	document_root_ka11="/Volumes/ka1tbr1/ht"
	document_root_ka12="/Volumes/ka1tbr2/ht"
	document_root=document_root_ka12



	json_detail=''
	wlfile=a2
	if( os.path.exists( wlfile )):
		ifmt='wl'
		if re.search( '.psv$', wlfile ): ifmt='psv'
		
		with open(wlfile) as f:
			j=0
			ifmt='psv'
			for line in f:
				j += 1


#				m = re.match( '.psv', wlfile )
#				if m:
#				print( 'BUGS_RE re.search={}'.format( re.search( '.psv$', wlfile )))
#				if re.search( '.psv$', wlfile ):

				if ifmt == 'psv':
					id = line.split('|')[0]
					status = line.split('|')[1]
					dttm = line.split('|')[2]
					code = line.split('|')[3]
					grp = line.split('|')[4]
					idx = line.split('|')[5]
					tlid = line.split('|')[6]
					title = line.split('|')[7]
					begdt = line.split('|')[8]
					enddt = line.split('|')[9]
					headline = line.split('|')[10]
					text = line.split('|')[11]
					tag = line.split('|')[12]
					media = line.split('|')[13]
					tn = line.split('|')[14]
					credit = line.split('|')[15]
					caption = line.split('|')[16]
					eras = line.split('|')[17]
					e_begdt = line.split('|')[18]
					e_enddt = line.split('|')[19]
					e_head = line.split('|')[20]
					e_tag = line.split('|')[21]
					charts = line.split('|')[22]
					c_begdt = line.split('|')[23]
					c_enddt = line.split('|')[24]
					c_head = line.split('|')[25]
					c_val = line.split('|')[26]
					filedt = line.split('|')[27]
					exifdt = line.split('|')[28]
					tempdt = line.split('|')[29]
					desc = line.split('|')[30]
					b64 = line.split('|')[31]
					startdate=begdt
					enddate=enddt
#					media='<a href="{}" target=_blank><img src="{}" alt="{}" border=0></a>'.format( ht_pathfile, ht_pathfile, tn )
#					thumbnail='/imgs/btn/tn/tn_koeye.png'

					pathfile=media
					print( '{} {} MSG_PSV: wlfile={} pathfile={}'.format( progid,dttm,wlfile, pathfile))

				else:
					pathfile=line.split()[8]
					print( '{} {} MSG_WL: wlfile={} pathfile={}'.format( progid,dttm,wlfile, pathfile))


				path=os.path.dirname(pathfile)
				base=os.path.basename(pathfile)
				file=os.path.splitext(base)[0]
				ext=os.path.splitext(base)[1]



				path=path.replace(document_root_ko0,'')
				path=path.replace(document_root_ko2,'')
				path=path.replace(document_root_ka10,'')
				path=path.replace(document_root_ka11,'')
				path=path.replace(document_root_ka12,'')

				print( '{} {} do_tl MSG_2500: j={} pathfile={} path={} base={} file={} ext={}'.format( progid, dttm, j, pathfile, path, base, file, ext ))
				ht_pathfile='{}{}{}'.format(path,file,ext)	

				o_pathfile_htm=a2.replace(".txt", ".htm")
				divid=a2.replace(".txt","")
				htmdiv='<div id="{}">\n'.format( divid )

# for filename in os.listdir(DIRECTORY):
#    if (filename.endswith(".mp4"): #or .avi, .mpeg, whatever.
#        os.system("ffmpeg -i {0} -f image2 -vf fps=fps=1 output%d.png".format(filename))
#    else:
#        continue

				i_pathfile='{}{}/{}'.format(document_root,path,base)
				i_pathfile_mp4='{}{}/{}'.format(document_root,path,base)
				o_pathfile_jpg='{}{}/img/{}_%03d.jpg'.format(document_root,path,file)
				i_pathfile_jpg1='{}{}/img/{}_001.jpg'.format(document_root,path,file)
				i_pathfile_jpgs='{}{}/img/{}_*.jpg'.format(document_root,path,file)
				o_pathfile_png='{}{}/tn/tn_{}.png'.format(document_root,path,file)
				o_pathfile_gif='{}{}/tn/tn_{}.gif'.format(document_root,path,file)


				o_pathfile='{}{}/img/{}_%03d.jpg'.format(document_root,path,file)
				o_pathfile_im='{}{}/img/{}_%03d.jpg'.format(document_root,path,file)
				o_pathfile_tn='{}{}/img/{}_%03d.gif'.format(document_root,path,file)

				print( "BUGS_141 i_pathfile={}".format(i_pathfile))
				print( "BUGS_142 ht_pathfile={}".format(ht_pathfile))
				if ext=='.mp4' : print( "BUGS_141 i_pathfile_mp4={}".format(i_pathfile_mp4))
				if ext=='.jpg' : print( "BUGS_142 o_pathfile_jpg={}".format(o_pathfile_jpg))
#				if ext=='.jpg' : print( "BUGS_144 i_pathfile_jpg1={}".format(i_pathfile_jpg1))
#				if ext=='.jpg' : print( "BUGS_145 i_pathfile_jpgs={}".format(i_pathfile_jpgs))
				if ext=='.gif' : print( "BUGS_146 o_pathfile_gif={}".format(o_pathfile_gif))
				if ext=='.png' : print( "BUGS_146 o_pathfile_png={}".format(o_pathfile_png))


				abs_tn_path='{}{}/tn/'.format(document_root, path)
				tn_path='{}/tn/'.format(path)
				tn_base='tn_{}.gif'.format(file)

				abs_tn_pathfile='{}{}{}'.format( document_root, tn_path, tn_base )
				tn_pathfile='{}{}'.format( tn_path, tn_base )

				abs_im_path='{}{}/img/'.format(document_root,path)
				im_path='{}/img/'.format(path)
				im_base='{}.png'.format(file)
				abs_im_pathfile='{}{}{}'.format( document_root, im_path, im_base )
				im_pathfile='{}{}'.format(  im_path, im_base )


	

				json_detail+='{\n' 
				json_detail+='"startDate":"{}",\n'.format( startdate )
				json_detail+='"endDate":"{}",\n'.format(enddate)
				json_detail+='"headline":"{}",\n'.format(headline)
				json_detail+='"text":"{}",\n'.format(text)
				json_detail+='"tag":"{}",\n'.format(tag)
				json_detail+='"asset": { \n'
				json_detail+='	"media":"{}",\n'.format(media)
				json_detail+='	"thumbnail":"{}",\n'.format(tn)
				json_detail+='	"credit":"{}",\n'.format(credit)
				json_detail+='	"caption":"{}"\n'.format(caption)
				json_detail+='	}},'
#				print( 'json_detail={}'.format(json_detail))





# json_end
	startdate_end='2020,12,01'
	enddate_end='2020,12,30'
	headline_end='headline_end'
	text_end='text_end'
	tag_end='tag_end'
	media_end='media_end'
	thumbnail_end='thumbnail_end'
	credit_end='credit_end'
	caption_end='caption_end'
	text_end='text_end'



	startdate_end=yyyymmdd
	enddate_end=yyyymmdd

	json_end=''
	json_end+='{\n'
	json_end+='"startDate":"{}",\n'.format(startdate_end)
	json_end+='"endDate":"{}",\n'.format(enddate_end)
	json_end+='"headline":"{}",\n'.format(enddate_end)
	json_end+='"text":"{}",\n'.format(enddate_end)
	json_end+='"tag":"{}",\n'.format(enddate_end)
	json_end+='"asset": {\n'
	json_end+='	"media":"{}",\n'.format(media_end)
	json_end+='	"thumbnail":"{}",\n'.format(thumbnail_end)
	json_end+='	"credit":"{}",\n'.format(credit_end)
	json_end+='	"caption":"{}" \n'.format(caption_end)
	json_end+='	}}]}}\n'
#	print( 'json_end={}'.format(json_end))


	json=''
	json+=json_beg
	json+='\n\n'
	json+=json_detail
	json+='\n\n'
	json+=json_end

#	print( 'json={}'.format(json))
	out_file=open( ofile, "wb" )
	out_file.write(json)
	out_file.close()
	dttm=kodts('')
	print( '{} {} MSG_END: do_tl ofile={}'.format(progid, dttm, ofile ))
	return(json)

def htmcss_popover(cssid):
	cssid="ko"
	url="{}.js".format(cssid)
	b64fil = "b64_{}_js.txt".format(cssid)
	b64txt = ""
	
	b64cmd = "base64 {} > b64_{}.txt".format(url,cssid)
#	os.system( b64cmd )
	b64 = open( b64fil, "rb" )
	for line in b64:
		b64txt += line
	b64.close()	
	htmcss_b64 = '<script id="script_{}" src="data:/text/plain;base64,{}"></script>'.format(cssid,b64txt)

	htmcss = ""
	htmcss += '<style id="style_{}" >{}:{}</style>'.format(cssid,cssid,cssid) 
	htmcss += '<!-- <script id="script_{}" src="{}" ></script> -->\n'.format(cssid, url)
	htmcss += htmcss_b64


	return(htmcss)

def main():
	startup()
	commands()


if __name__ == '__main__':
	main()


# konet@ka1 ht % ssh kozerus@ko0.us "uname -a"
# 	Linux box5624.bluehost.com 4.19.150-76.ELK.el6.x86_64 #1 SMP Wed Oct 7 01:34:10 CDT 2020 x86_64 x86_64 x86_64 GNU/Linux
# konet@ka1 ht % ssh kotwous@ko2.us "uname -a"
# 	Linux box5633.bluehost.com 4.19.150-76.ELK.el6.x86_64 #1 SMP Wed Oct 7 01:34:10 CDT 2020 x86_64 x86_64 x86_64 GNU/Linux
# konet@ka1 ht % uname -a
# 	Darwin ka1 20.4.0 Darwin Kernel Version 20.4.0: Thu Apr 22 21:46:47 PDT 2021; root:xnu-7195.101.2~1/RELEASE_
#	(hostname,err)=kosys('uname -a'.split(" ")[1])
#
#	hosts="ka1 ko0 ko1 ko2"
#	$host=$_SERVER['HTTP_HOST']
#	$progid=$_SERVER['PHP_SELF']
//


koh5_pano



Your browser does not support the HTML5 canvas element.


Drag mouse to navigate.

Navigation





17.Aug.2010, Martin Wengenmayer