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

/home/kozerus/public_html/ko

# ko.py 20260514_0700	md vi # jkmed-yyyymmdd-hhmmss-acyclovir h2o heart bitcoin=$ gold=$ silver=$ eth=$
# ko.py 20241230_0122	md vi # yyyymmdd bitcoin=$ gold=$ silver=$ eth=$
# ko.py 20240421_1400	def items
# ko.py 20240323_1630	def imglist2pages
# ko.py 20240321_1100	def md mv psv
# ko.py	20240320_1900 def md vi mv psv dls
# ko.py	20240222_1120 todos
# ko.py	20230809 randomuser kumu beautifulsoup
# ko.py	20220201_0130 housatonic tesseract
# ko.py	20211003_1430
# encoding=utf8


# ko.py	20220201_1212 dt2db3 dt2db3v
# ko.py	20220126_0100 db3s cmds
# ko.py	20180520_1300
# ===========================
# open dominik_plangger_lerchce48_al_werners.mp4  -a vlc3
# convert map_venice.jpg    -page +142+242 push_pin.png \ -flatten  map_push_pin.jpg



# from __future__ import unicode_literals
# 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 glob
import base64
import sqlite3
import csv
import json
from subprocess import PIPE, Popen
import socket

# import bs4 as BeautifulSoup
from bs4 import BeautifulSoup
import requests
import shutil


# from glob2 import glob
# from glob import glob


global hostname;
global goflag; 
goflag=""
global a0; global a1; global a2; global a3; global a4; global a5; global a6; global a7; global a8;

hostname = os.uname()[1]


# a = {}; k = 0
# while k < 10:
# dynamically create key
# key = ...; # calculate value value = ...
#	a[key] = value; k += 1


# 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: 


global progid; global dttm; global j; global k;
global a0; global a1; global a2; global a3; global a4; global a5; global a6; global a7; global a8;
j=0; k=0;

alen = len(sys.argv)
(a0,a1,a2,a3,a4,a5,a6,a7,a8,a9) = ("","","","","","","","","","")
progid="ko"
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 list_globals(args):
# By default, a module has some hidden variables defined
	print({k: v for k, v in globals().items() if not k.startswith("__")})
	for i in range(1, 11):
		globals()[f"my_variable_{i}"] = i
	print()
	print(my_variable_1)
	print(my_variable_2)
	print()
	print({k: v for k, v in globals().items() if not k.startswith("__")})

#	with open(filename) as file:
#		lines = [line.rstrip() for line in file]

#	with open(filename) as file:
#		for line in file:
#			print(line.rstrip())

#	with open(filename) as file:
#		while line := file.readline():
#			print(line.rstrip())

#	with open(filename, 'r', encoding='UTF-8') as file:
#		while line := file.readline():
#			print(line.rstrip())

#	with open('filename') as f:
#		lines = f.readlines()

#	with open("file.txt") as file_in:
#		lines = []
#		for line in file_in:
#        		lines.append(line)

#	lines = open(filename).read().split('\n')

#	with open('file.txt') as f:
#		for line in f:

#	with open('file.txt') as f:
#		lines = f.readlines()

#	f = open('file.txt') # Open file on read mode
#	lines = f.read().splitlines() # List with stripped line-breaks
#	f.close() # Close file

#	with open(fname) as f: items = f.readlines()
#	with open(fname) as f: content = f.read().splitlines()


#	os.makedirs(tdir, exist_ok=True)
#	os.rmdir('directory')
#	import shutil
#	path = /home/User/Documents/abcdef
#	shutil.rmtree('path')

def fs_remove(path):
	""" param <path> could either be relative or absolute. """
	if os.path.isfile(path) or os.path.islink(path):
		os.remove(path)  # remove the file
	elif os.path.isdir(path):
		shutil.rmtree(path)  # remove dir and all contains
	else:
		raise ValueError("file {} is not a file or dir.".format(path))

def fs_remove_endswith(path):
	from os import listdir
	winpath = 'C:\\Python Pool\\Test'
	for file_name in listdir(my_path):
		if file_name.endswith('.txt'):
		        os.remove(my_path + file_name)

def fs_walk(path):
# change the extension from '.mp3' to 
# the one of your choice.
	dir_path = os.path.dirname(os.path.realpath(__file__))
	for root, dirs, files in os.walk(dir_path):
		for file in files: 
			if file.endswith('.mp3'):
				print (root+'/'+str(file))



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)
	if( fmt == "kodt"): return(kodt)
	return(dttm)


def kosys(cmd,opts):
	global progid; global goflag; dttm=kodts(''); j=0; k=0;
#	print( "{} {} -{}- {},{} BUGS_240 kosys cmd={} opts={}".format(progid,dttm,goflag,j,k,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.decode().split("\n"):
		j=j+1
		print( "{}_{} -= kosys =- {}-{} sysout={}".format(koid,kodt, j,k, sysout))

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


def ko_prompt( syscmd, items ):
	print( "{} {} -{}- BUGS_261 ko_prompt {},{} a0={} a1={} a2={} a3={} a4={}\n".format( progid,dttm,goflag,j,k, a0, a1, a2, a3, a4 ))
	print( "{} {} -{}- BUGS_262 ko_prompt {},{} syscmd={} ilen={} items0={}".format(progid,dttm,goflag,j,k, usrcmd, ilen, items[0]))
	syscmd="find /Users/konet/Download -type f -maxdepth 1 -name \"*.mp4\""
	(out,err)=kosys(syscmd,'brief')
	return(out)

def ko_prompts( syscmd, items ):
	global progid; global goflag; global a0; global a1; global a2; global a3; global a4;
#	goflag="go"; 
	j=0; k=0; 
	item="_item_"; out="_out_"; err="_err_";
	ilen=len(items)
	usrcmd="";j=0;k=0;
	print( "{} {} -{}- BUGS_261 ko_prompts {},{} a0={} a1={} a2={} a3={} a4={}\n".format( progid,dttm,goflag,j,k, a0, a1, a2, a3, a4 ))
	print( "{} {} -{}- BUGS_262 ko_prompts {},{} syscmd={} ilen={} items0={}".format(progid,dttm,goflag,j,k, usrcmd, ilen, items[0]))
	syscmd="find /Users/konet/Downloads -type f -maxdepth 1 -name \"*.mp4\""
	(out,err)=kosys(syscmd,'brief')
	items=out.decode().split("\n")
	ilen=len(items)
	wlfile="{}.wl".format(syscmd.replace("-","").replace(" ","_").replace("/","-").replace("|","_").replace("\"","").replace("*","#").replace(".",""))

	print( "{} {} -{}- BUGS_263 ko_prompts {},{} ilen={} wlfile={} usrcmd={} syscmd={} out=>\n{}<=\n err=>{}<==\n".format(progid,dttm,goflag,j,k,ilen,wlfile,usrcmd,syscmd, out, err))

	while True:
		item=items[j]; 
		print( "BUGS j={} item={} =======================items=\n{}\n".format(j,item,items))
		print( "{} {} -{}- BUGS_281 ko_prompts {},{} ilen={} item={} wlfile={} usrcmd={} syscmd={}".format(progid,dttm,goflag,j,k,ilen,item,wlfile, usrcmd,syscmd))
		print( "{} {} -{}- BUGS_282 ko_prompts {},{} ilen={} items=>\n{}<==\n usrcmd={} syscmd={}".format(progid,dttm,goflag,j,k,ilen,item, usrcmd,syscmd))
		if( not re.search("^g",usrcmd)): 
			print("e=exit q=quit s=skip enter=continue o=open g=go +-/?.: ")
# 			usrcmd=raw_input("prompt: " )
#			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
			if( re.search("i", usrcmd)):
				print( "{} {} {},{} {} BUGS_231 ko_prompts GO usrcmd={} syscmd={} items=\n".format(progid,dttm,goflag,j,k,usrcmd, syscmd,items))
				

		if( usrcmd =="q" ): break
		if( usrcmd =="x" ): break

		if( re.match("+", usrcmd )): j=k+1; continue;
		if( re.match("^-", usrcmd )): j=k-1; continue;
		if( re.match("^:", usrcmd )): j=k; continue;
		if( re.search("^+", usrcmd )): j=k+int(usrcmd.replace("+","")); continue;
		if( re.search("^-", usrcmd )): j=k-int(usrcmd.replace("-","")); continue;
		if( re.search("^:", usrcmd )): j=int(usrcmd.replace("-","")); continue;
		if( re.search("^.", usrcmd )): j=k; continue;
		if( re.search("^/", usrcmd )):
			linematch=usrcmd.replace("/","")
	#		for( usrcmd_j=item_j; usrcmd_j<ilen; usrcmd_j=usrcmd_j+1):
			i=item_j
			for item_kludge in items:
				item=items[i]
				if( re.search(linematch,item)): return(i,item)
				i=i+1
				if( i < ilen ): i=0
			continue
		if( re.search("^?", usrcmd )):
			linematch=usrcmd.replace("?","") 
	#		for( usrcmd_j=item_j; usrcmd_j<0; usrcmd_j=usrcmd_j-1):
			i=item_j
			for item_kludge in items:
				item=items[i]
				if( re.search(linematch,item)): return(i,item)
				i=i-1
				if( i < 0 ): i=ilen
			continue
	
		if( re.search("^o", usrcmd )):
			if( os.path.exists(item)):
				syscmd_open="open {}".format(item)
				(out,err)=kosys(syscmd_open,'')
			continue

		if( goflag == "go" ):
			print( "{} {} {},{} {} BUGS_231 ko_prompts GO usrcmd={} syscmd={}".format(progid,dttm,goflag,j,k,usrcmd, syscmd))
#			(out,err)=kosys(syscmd,'')
			print( "{} {} {},{} {} BUGS_232 ko_prompts GO usrcmd={} syscmd={}\nout={}\nerr={}\n".format(progid,dttm,goflag,j,k,usrcmd, syscmd,out,err))

		j=j+1
		if( j < 0 ): j = ilen
		if( j > ilen ): j = 0
		print( "{} {} -{}- {},{} BUGS_330 ko_prompts usrcmd={} item={}\n".format(progid,dttm,goflag,j,k, usrcmd,item))
		continue
	
#	usrcmd_todo=ko_prompts(usrcmd,j,items)
	print( "{} {} -{}- {},{} BUGS_340 ko_prompts usrcmd={} item={}\n".format(progid,dttm,goflag,j,k, usrcmd,item))
	return(items)





def ko_finds(dir,path):
		print( "{}_{} -= ko_finds_180 =- {}-{} syserr={}".format(koid,kodt, j,k, syserr))
		out="_ko_finds_"
		return(out)

def go0(args):
	print( "{}_{} -= MSG_101 =- {}-{} syserr={}".format(koid,kodt, j,k, syserr))
def go1(args):
	print( "{}_{} -= MSG_102 =- {}-{} syserr={}".format(koid,kodt, j,k, syserr))
def go2(args):
	print( "{}_{} -= MSG_103 =- {}-{} syserr={}".format(koid,kodt, j,k, syserr))

def md(datetag):
	global a0; global a1; global a2; global a3; global a4; global a5; global a6; global a7; global a8;
	global progid; global dttm; global goflag; global j; global k;

	dttm=kodts('')
	rootpath="../i"
	rootpath="../ht/kb"
	if( datetag == "" ): datetag=kodts('yyyymmdd')
	print( "{} {} -{}- MSG_371 commands md {},{} ".format(progid,dttm,goflag,j,k,datetag))
#	dirs="snap nasa jtfdcr kb".split(" ")
	dirs="nasa snap kb".split(" ")
	j=0; k=0;
	for dir in dirs:
		j=j+1
		dirnam="{}/{}/{}_{}".format(rootpath,dir,dir,datetag)
		if( os.path.exists(dirnam)):
			print("{} {} -{}- BUGS_381 commands md {},{} ___FOUND dirnam={}\n".format(progid,dttm,goflag,j,k,dirnam))
		else:
			print("{} {} -{}- BUGS_382 commands md {},{} NOTFOUND dirnam={}\n".format(progid,dttm,goflag,j,k,dirnam))
			os.mkdir(dirnam)
#			if( goflag == "go" ): os.mkdir(dirnam)

	return(datetag)	


def apps(id):
	global a0; global a1; global a2; global a3; global a4; global a5; global a6; global a7; global a8;
	global progid; global dttm; global goflag; global j; global k;

	(db3file,tbl,sql) = ("ko.db3", "apps", "select * from apps where id={}".format(id))
	(csvdta,psvdta,jsndta,mydict) = sql3_rows2dicts(db3file,tbl,sql)
	print("{} {} -{}- BUGS_401 commands apps {},{} ___FOUND psvdta={}\n".format(progid,dttm,goflag,j,k,psvdta))
	
#	open -n ./AppName.app --args -AppCommandLineArg
	syscmd_app="open -n {} --args {}".format(appnam, args)
	print("{} {} -{}- BUGS_402 commands apps {},{} ___FOUND syscmd_app={}\n".format(progid,dttm,goflag,j,k,syscmd_app))
	if( goflag == "go" ): 
		print("{} {} -{}- BUGS_403 commands apps {},{} GO syscmd_app={}\n".format(progid,dttm,goflag,j,k,syscmd_app))
		os.system(syscmd_app)
		return(appid)

	(db3file,tbl,sql) = ("ko.db3", "apps", "select * from apps" )
	(csvdta,psvdta,jsndta,mydict) = sql3_rows2dicts(db3file,tbl,sql)
	print("{} {} -{}- BUGS_401 commands apps {},{} ___FOUND psvdta={}\n".format(progid,dttm,goflag,j,k,psvdta))

	return(appid)


def vi(datetag):
	global a0; global a1; global a2; global a3; global a4; global a5; global a6; global a7; global a8;
	global progid; global dttm; global goflag; global j; global k;

	if( datetag == "" ): datetag=kodts('yyyymmdd')
	wlfile="../ht/yt/txt/ytlist_{}.txt".format(datetag)
	syscmd_vi="vi {}".format(wlfile)
	os.system(syscmd_vi)
	(pid,err) = kosys("ps -ef | grep \"{}\"".format(wlfile),'brief')

#	syscmd_vi="vi {}".format(wlfile)
#	syscmd_vi="vi {} </dev/tty >/dev/tty 2>&1".format(wlfile)
#	syscmd_vi="xterm -e vi {}".format(wlfile)
#	print( "{} {} -{}- MSG_431 commands vi {},{} syscmd_vi={} ".format(progid,dttm,goflag,j,k,syscmd_vi))
#	if( goflag == "go" ): 
#		(out,err)=kosys(syscmd_vi,'')
#		print( "{} {} -{}- MSG_432 commands vi {},{} wlfile={} ".format(progid,dttm,goflag,j,k,wlfile))
#	print( "{} {} -{}- MSG_432 commands vi {},{} wlfile={} ".format(progid,dttm,goflag,j,k,wlfile))
#	print( "{} {} -{}- MSG_433 commands vi {},{} pid={} ".format(progid,dttm,goflag,j,k,pid))
#	(out,err) = kosys("kill {}".format(pid),'brief' )
	return(datetag)

def mv(datetag):
	global a0; global a1; global a2; global a3; global a4; global a5; global a6; global a7; global a8;
	global hostname; global progid; global dttm;  global goflag; global j; global k;


	glob_pathfiles="""
fpathfile|tpathfile
# ../o/SnapNDrag Library.snapndraglibrary/*/snap_*.png|../i/snap/snap_
../i/NRB_*_.PNG|../ht/kb/nasa/nasa_
../i/CR0_*.PNG|../ht/kb/nasa/nasa_
../i/FRB_*_.JPG|../ht/kb/nasa/nasa_
../i/NLB_*_.JPG|../ht/kb/nasa/nasa_
../i/NRB_*_.JPG|../ht/kb/nasa/nasa_
../i/CR0_*_.JPG|../ht/kb/nasa/nasa_
../i/*DXXX.jpg|../ht/kb/nasa/nasa_
../i/D000M*.JPG|../ht/kb/nasa/nasa_
../i/Mars_Perseverance*J.png|../ht/kb/nasa/nasa_
../i/*.png|../ht/kb/kb/kb_
../i/*.jpg|../ht/kb/kb/kb_
../i/*.gif|../ht/kb/kb/kb_
../i/*.pdf|../ht/kb/kb/kb_
../i/*.webp|../ht/kb/kb/kb_
../i/*.heic|../ht/kb/kb/kb_
../i/*.mp4|../ht/kb/kb/kb_
/Users/konet/Downloads/*.mp4|../ht/kb/mp4/mp4_
/Users/konet/Downloads/*.*|../ht/kb/dl/dl_
../o/SnapNDrag Library.snapndraglibrary/*/snap_*.png|../ht/kb/snap/snap_
""".split("\n")

#	name="_name_"
#	pattern="../i/*.pdf"
#	globlen=len(glob.glob(pattern))
#	print( "{},{} BUGS_470 name={} pattern={} globlen={}".format(j,k,name,pattern,globlen))
#	for fname in glob.glob(pattern):
#		j=j+1
#		print( "{},{} BUGS_480 fname={} pattern={} glob_len={}".format(j,k,fname,pattern,globlen))

	j=0; k=0; fgloblen_tot=0; tgloblen_tot=0;
#	print( "BUGS_490 glob_pathfiles_len={}".format(len(glob_pathfiles)))
#	exit()

	for glob_pathfile in glob_pathfiles:
		if re.match( '^#', glob_pathfile ): continue
		if( glob_pathfile == "" ): continue
		print( "BUGS_500 {},{} glob_pathfile={}".format(j,k,glob_pathfile))

		dttm=kodts('')
		glob_fpathfile=glob_pathfile.split("|")[0]
		glob_tpathfile=glob_pathfile.split("|")[1]
		glob_tpathfile="{}{}".format(glob_tpathfile,datetag)


		glob_fpath=os.path.dirname(glob_fpathfile).replace("*","")
		if( not os.path.exists(glob_fpath)): 
			print( "{} {} {} -{}- MSG_501 mv {},{} datetag={} NOTFOUND glob_fpath={} fpathfile={} tpathfile={} ".format(hostname,progid,dttm,goflag,j,k,datetag,glob_fpath,glob_fpathfile,glob_tpathfile))
			continue

		glob_ffile=os.path.basename(glob_fpathfile)
		glob_fbase=glob_ffile.split(".")[0]
		glob_fext=""
		if( len(glob_ffile.split(".")) > 1 ): 
			glob_fext=glob_ffile.split(".")[1]
		j=j+1


#		print( "{} {} {} -{}- MSG_451 mv {},{} datetag={} fpathfile={} tpathfile={} ".format(hostname,progid,dttm,goflag,j,k,datetag,glob_fpathfile,glob_tpathfile))
#		print( "{} {} {} -{}- MSG_452 mv {},{} datetag={} fdir={} fnam={} fext={} ".format(hostname,progid,dttm,goflag,j,k,datetag,glob_fdir,glob_fnam,glob_fext))

		fgloblen=len(glob.glob(glob_fpathfile))
		tgloblen=len(glob.glob(glob_tpathfile))
		fgloblen_tot=fgloblen_tot+fgloblen	
		tgloblen_tot=tgloblen_tot+tgloblen	

#		print( "{} {} {} -{}- MSG_520 mv {:>3d},{:>3d} {:<30s} {:>4d} {:<30s} {:>4d}".format(hostname,progid,dttm,goflag,j,k, glob_fpathfile,fgloblen,glob_tpathfile,tgloblen))
		print( "{} {} {} -{}- MSG_520 mv {:>2d},{:>2d} {:>4d} {:>4d}  {:<30s} {:<30s}".format(hostname,progid,dttm,goflag,j,k, fgloblen, tgloblen, glob_fpathfile, glob_tpathfile))

		if( goflag == "go" ):
			k=0
#			for fpathfile in glob.glob(glob_fpathfile):
			for fpathfile in glob.glob(glob_fpathfile):
				name=fpathfile
				if( not os.path.exists(fpathfile)): continue
				fpath=os.path.dirname(fpathfile)
				ffile=os.path.basename(fpathfile)
				fext=""
				fbase=ffile.split(".")[0]
				if( len(ffile.split(".")) > 1 ): fext=ffile.split(".")[1]

				k=k+1
				tpath=os.path.dirname(glob_tpathfile)
				tfile=os.path.basename(glob_tpathfile)

				tbase=re.sub('\W+','_', fbase ).lower()[0:80].replace("_$","")

				text=fext.lower()
				if( datetag == "" ): datetag=kodt('yyyymmdd')
				if( datetag == "go" ): datetag=kodt('yyyymmdd')

#				tpathfile="{}/{}{}.{}".format(tpath,datetag,tbase,text)
				tpathfile="{}/{}.{}".format(glob_tpathfile,tbase,text)

				glob_fpath=os.path.dirname(glob_fpathfile)
				glob_ffile=os.path.basename(glob_fpathfile)
				glob_tpath=glob_tpathfile
				glob_tfile="{}.{}".format(tbase,text)
				glob_tpathfile="{}/{}".format(tpath,tfile)
#				glob_tfile=os.path.basename(glob_tpathfile)
				
				fpath=os.path.dirname(fpathfile); ffile=os.path.basename(fpathfile)
				tpath=os.path.dirname(tpathfile); tfile=os.path.basename(tpathfile)

				print( "pqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpq" )
				print( "{} {} {} -{}- MSG_551 mv {},{} datetag={}\n GLOB_FROM glob_fpathfile={} glob_fpath={} glob_ffile={}\n".format(hostname,progid,dttm,goflag,j,k,datetag,glob_fpathfile,glob_fpath, glob_ffile))
				print( "{} {} {} -{}- MSG_552 mv {},{} datetag={}\n FROM           fpathfile={} fpath={} ffile={}\n".format(hostname,progid,dttm,goflag,j,k,datetag,fpathfile, fpath, ffile))
				print( "=================================================" )
				print( "{} {} {} -{}- MSG_561 mv {},{} datetag={}\n GLOB_TO__ glob_tpathfile={} glob_tpath={} glob_tfile={}\n".format(hostname,progid,dttm,goflag,j,k,datetag,glob_tpathfile,glob_tpath, glob_tfile))
				print( "{} {} {} -{}- MSG_562 mv {},{} datetag={}\n TO             tpathfile={} tpath={} tfile={}\n".format(hostname,progid,dttm,goflag,j,k,datetag,tpathfile, tpath, tfile))
				print( "bdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbd" )

				if( re.match('/Users/konet/Downloads',fpath,re.IGNORECASE )):
					print( "BUGS_570 tpath={} tfile={} fpath={} ffile={} len={} glob_tpathfile={}\n".format(tpath,tfile,fpath,ffile,len(glob_tpathfile),glob_tpathfile))
					if( not os.path.exists(fpathfile)): 
						print( "BUGS_570 NOTFOUND fpathfile={} fpath={} ffile={} len={} glob_tpathfile={}\n".format(fpathfile, fpath,ffile,len(glob_tpathfile),glob_tpathfile))
						continue

					if( re.match('../ht/kb/mp4/mp4_',tpath,re.IGNORECASE )):
						print( "BUGS_572 tpathfile={} tpath={} ffile={} len={} glob_tpathfile={}\n".format(tpathfile, tpath,tfile,len(glob_tpathfile),glob_tpathfile))
						if( not os.path.exists(tpath)): 
							print( "BUGS_573 tpathfile={} tpath={} fpath={} len={} glob_tpathfile={}\n".format(tpathfile, tpath,fpath,len(glob_tpathfile),glob_tpathfile))
							os.mkdir(tpath)
						if( not os.path.exists(tpath)): continue
						print( "{} {} {} -{}- MSG_574 mv {},{} cp {} {}".format(hostname,progid,dttm,goflag,j,k,fpathfile,tpathfile))
						if ( os.path.isfile(fpathfile)):
							shutil.copy(fpathfile,tpathfile)
							if ( os.path.isfile(tpathfile)):
								print( "{} {} {} -{}- MSG_575 mv {},{} RM fpathfile={}".format(hostname,progid,dttm,goflag,j,k,fpathfile))
								os.remove(fpathfile)
						print( "BUGS_576 tpathfile={} tpath={} fpath={} len={} glob_tpathfile={}\n".format(tpathfile, tpath,fpath,len(glob_tpathfile),glob_tpathfile))
						continue

					if( re.match('../ht/kb/dl/dl_',tpath,re.IGNORECASE )):
						print( "BUGS_582 tpathfile={} tpath={} ffile={} len={} glob_tpathfile={}\n".format(tpathfile, tpath,tfile,len(glob_tpathfile),glob_tpathfile))
						if( not os.path.exists(tpath)): 
							print( "BUGS_583 tpathfile={} tpath={} fpath={} len={} glob_tpathfile={}\n".format(tpathfile, tpath,fpath,len(glob_tpathfile),glob_tpathfile))
							os.mkdir(tpath)
						if( not os.path.exists(tpath)): continue
						print( "{} {} {} -{}- MSG_584 mv {},{} cp {} {}".format(hostname,progid,dttm,goflag,j,k,fpathfile,tpathfile))
						if ( os.path.isfile(fpathfile)):
							shutil.copy(fpathfile,tpathfile)
							if ( os.path.isfile(tpathfile)):
								print( "{} {} {} -{}- MSG_585 mv {},{} RM fpathfile={}".format(hostname,progid,dttm,goflag,j,k,fpathfile))
								os.remove(fpathfile)
						print( "BUGS_576 tpathfile={} tpath={} fpath={} len={} glob_tpathfile={}\n".format(tpathfile, tpath,fpath,len(glob_tpathfile),glob_tpathfile))
						continue




				if( re.match('.heic$',fext,re.IGNORECASE)):
					text="png"
					tpathfile="{}/{}.{}".format(tpath,tbase.text)
					if( os.path.isfile(fpathfile)):
						syscmd_heic2png = "convert {} -quality 100% {}".format(fpathfile,tpathfile)
						print( "{} {} {} -{}- MSG_551 mv {},{} HEIC CONVERT syscmd_heic2png".format(hostname,progid,dttm, goflag,j,k,fpathfile,tpathfile))
						(out,err)=kosys(syscmd_heic2png,'brief')
						if( os.path.isfile(tpathfile)):
							print( "{} {} {} -{}- MSG_552 mv {},{} HEIC RM {}".format(hostname,progid,dttm, goflag,j,k,fpathfile,tpathfile))
							os.remove(fpathfile)
					continue

				if( re.match('.webp$',fext,re.IGNORECASE)):
					text="png"
					tpathfile="{}/{}.{}".format(tpath,tbase.text)
					if( os.path.isfile(fpathfile)):
						syscmd_webp2png = "convert {} {}".format(fpathfile,tpathfile)
						print( "{} {} {} -{}- MSG_551 mv {},{} WEBP CONVERT syscmd_webp2png".format(hostname,progid,dttm, goflag,j,k,fpathfile,tpathfile))
						(out,err)=kosys(syscmd_webp2png,'brief')
						if( os.path.isfile(tpathfile)):
							print( "{} {} {} -{}- MSG_552 mv {},{} WEBP RM {}".format(hostname,progid,dttm, goflag,j,k,fpathfile,tpathfile))
							os.remove(fpathfile)
					continue



				if( os.path.isfile(fpathfile)):
					print( "{} {} {} -{}- MSG_550 mv {},{} cp {} {}".format(hostname,progid,dttm,goflag,j,k,fpathfile,tpathfile))
					shutil.copy(fpathfile,tpathfile)
					if ( os.path.isfile(tpathfile)):
						print( "{} {} {} -{}- MSG_560 mv {},{} RM fpathfile={}".format(hostname,progid,dttm,goflag,j,k,fpathfile))
						os.remove(fpathfile)
					continue

#			if( j > 1 ): exit
	
	print( "{} {} {} -{}- MSG_600 mv {:>3d},{:>3d} {:<30s} {:>4d} {:<30s} {:>4d}".format(hostname,progid,dttm,goflag,j,k, "fpathfiles",fgloblen_tot,"tpathfile",tgloblen_tot))
#	print( "{} {} -{}- MSG_601 mv {},{} ".format(progid,dttm,goflag,j,k,datetag))
	return(datetag)

def psv(datetag):
	global a0; global a1; global a2; global a3; global a4; global a5; global a6; global a7; global a8;
	global progid; global dttm; global goflag; global j; global k;

	db3="../ht/kb/db3/urls.db3"; tbl="urls";
	if( not os.path.exists(db3)):
		print( "BUGS_660 NOTFOUND db3={}".format(db3))
		exit();


	j=0; k=0; fgloblen_tot=0; tgloblen_tot=0;
	glob_fpathfile="../ht/yt/txt/ytlist_{}.txt".format(datetag)
	glob_fpath = os.path.dirname(glob_fpathfile)
	glob_ffile = os.path.basename(glob_fpathfile)

	fgloblen=len(glob.glob(glob_fpathfile))

	print( "BUGS_670 fgloblen={} glob_fpathfile={} glob_fpath={} glob_ffile={}".format(fgloblen, glob_fpathfile, glob_fpath, glob_ffile))

	j=0; k=0;
	for fpathfile in glob.glob(glob_fpathfile):
		dttm=kodts('')
		j=j+1
		if( not os.path.exists(fpathfile)): 
			print( "{} {} {} -{}- MSG_671 psv {},{} datetag={} NOTFOUND fpathfile={} ".format(hostname,progid,dttm,goflag,j,k,datetag, fpathfile))
			continue;

		fpath=os.path.dirname(fpathfile)
		ffile=os.path.basename(fpathfile)

#		sql3 = sqlite3.connect(":memory:")
		sql3 = sqlite3.connect(db3, isolation_level=None)
		rows = sql3.cursor()
		dttm=kodts('')

		j=0; k=0;
		with open(fpathfile) as file:
			while line := file.readline():
				j=j+1
#				if( re.match( '^#', line )): continue
				if( not re.match( 'http', line )): continue
				k=k+1	
				line=line.rstrip().replace("\n","")
				print("{},{} line={}".format(j,k,line))

				cols=line.split("|")
				collen=len(cols)

				item="_item_"
				grp="_grp_"
				type="_type_"
				label="_label_";
				desc="_desc_";
				ytid="_ytid_"
				url="_url"
				href="_href_"
				eff_dt=kodts('')
				dttm=kodts('')

				for col in line.split("|"):
					if( re.match("http",col)):
						url=col; href=url; item=url;
						if( re.match('dailymail',url)): type="dm"
						if( re.match('zerohedge',url)): type="zh"
						if( re.match('gatewaypundit',url)): type="gp"
						if( re.match('whatsitmean',url)): type="wim"
						if( re.match('youtube',url)): 
							type="yt"
							ytid=url.split("=")[1]
						if( re.match('bitchute',url)): 
							type="bc"
							ytid=url.split("=")[1]
						if( re.match('rumble',url)): 
							type="rb"
					else:
						desc=col
						label=desc

#				grp="_grp_"
#				type="_type_"
#				label="_label_";
#				ytid="_ytid_"
#				desc="_desc_";
#				href="_href_"
				effdt=kodts('')
				dttm=kodts('')

				flds="item,grp,type,label,desc,ytid,url,href,dttm,effdt"
				vals="'{}','{}','{}','{}','{}','{}','{}','{}','{}','{}'".format(item,grp,type,label,desc,ytid,url,href,dttm,effdt)
				sql="insert or replace into {} ( {} ) values ( {} )".format(tbl,flds,vals)
				print( "BUGS_700 db3={} tbl={} sql={}".format(db3,tbl,sql))
				rows.execute(sql)

		sql3.close()




		print( "{} {} {} -{}- MSG_672 psv {},{} datetag={} ___FOUND fpathfile={} fpath={} ffile={} ".format(hostname,progid,dttm,goflag,j,k,datetag, fpathfile, fpath, ffile))
	exit()



	for glob_pathfile in glob_pathfiles:
		if re.match( '^#', glob_pathfile ): continue
		if( glob_pathfile == "" ): continue
		print( "BUGS_500 {},{} glob_pathfile={}".format(j,k,glob_pathfile))

		dttm=kodts('')
		glob_fpathfile=glob_pathfile.split("|")[0]
		glob_tpathfile=glob_pathfile.split("|")[1]
		glob_tpathfile="{}{}".format(glob_tpathfile,datetag)


		glob_fpath=os.path.dirname(glob_fpathfile).replace("*","")
		if( not os.path.exists(glob_fpath)): 
			print( "{} {} {} -{}- MSG_501 mv {},{} datetag={} NOTFOUND glob_fpath={} fpathfile={} tpathfile={} ".format(hostname,progid,dttm,goflag,j,k,datetag,glob_fpath,glob_fpathfile,glob_tpathfile))
			continue

		glob_ffile=os.path.basename(glob_fpathfile)
		glob_fbase=glob_ffile.split(".")[0]
		glob_fext=""
		if( len(glob_ffile.split(".")) > 1 ): 
			glob_fext=glob_ffile.split(".")[1]
		j=j+1


#		print( "{} {} {} -{}- MSG_451 mv {},{} datetag={} fpathfile={} tpathfile={} ".format(hostname,progid,dttm,goflag,j,k,datetag,glob_fpathfile,glob_tpathfile))
#		print( "{} {} {} -{}- MSG_452 mv {},{} datetag={} fdir={} fnam={} fext={} ".format(hostname,progid,dttm,goflag,j,k,datetag,glob_fdir,glob_fnam,glob_fext))

		fgloblen=len(glob.glob(glob_fpathfile))
		tgloblen=len(glob.glob(glob_tpathfile))
		fgloblen_tot=fgloblen_tot+fgloblen	
		tgloblen_tot=tgloblen_tot+tgloblen	

#		print( "{} {} {} -{}- MSG_520 mv {:>3d},{:>3d} {:<30s} {:>4d} {:<30s} {:>4d}".format(hostname,progid,dttm,goflag,j,k, glob_fpathfile,fgloblen,glob_tpathfile,tgloblen))
		print( "{} {} {} -{}- MSG_520 mv {:>2d},{:>2d} {:>4d} {:>4d}  {:<30s} {:<30s}".format(hostname,progid,dttm,goflag,j,k, fgloblen, tgloblen, glob_fpathfile, glob_tpathfile))

		if( goflag == "go" ):
			k=0
#			for fpathfile in glob.glob(glob_fpathfile):
			for fpathfile in glob.glob(glob_fpathfile):
				name=fpathfile
				if( not os.path.exists(fpathfile)): continue
				fpath=os.path.dirname(fpathfile)
				ffile=os.path.basename(fpathfile)
				fext=""
				fbase=ffile.split(".")[0]
				if( len(ffile.split(".")) > 1 ): fext=ffile.split(".")[1]

				k=k+1
				tpath=os.path.dirname(glob_tpathfile)
				tfile=os.path.basename(glob_tpathfile)

				tbase=re.sub('\W+','_', fbase ).lower()[0:80].replace("_$","")

				text=fext.lower()
				if( datetag == "" ): datetag=kodt('yyyymmdd')
				if( datetag == "go" ): datetag=kodt('yyyymmdd')

#				tpathfile="{}/{}{}.{}".format(tpath,datetag,tbase,text)
				tpathfile="{}/{}.{}".format(glob_tpathfile,tbase,text)

				glob_fpath=os.path.dirname(glob_fpathfile)
				glob_ffile=os.path.basename(glob_fpathfile)
				glob_tpath=glob_tpathfile
				glob_tfile="{}.{}".format(tbase,text)
				glob_tpathfile="{}/{}".format(tpath,tfile)
#				glob_tfile=os.path.basename(glob_tpathfile)
				
				fpath=os.path.dirname(fpathfile); ffile=os.path.basename(fpathfile)
				tpath=os.path.dirname(tpathfile); tfile=os.path.basename(tpathfile)

				print( "pqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpq" )
				print( "{} {} {} -{}- MSG_551 psv {},{} datetag={}\n GLOB_FROM glob_fpathfile={} glob_fpath={} glob_ffile={}\n".format(hostname,progid,dttm,goflag,j,k,datetag,glob_fpathfile,glob_fpath, glob_ffile))
				print( "{} {} {} -{}- MSG_552 psv {},{} datetag={}\n FROM           fpathfile={} fpath={} ffile={}\n".format(hostname,progid,dttm,goflag,j,k,datetag,fpathfile, fpath, ffile))
				print( "=================================================" )
				print( "{} {} {} -{}- MSG_561 psv {},{} datetag={}\n GLOB_TO__ glob_tpathfile={} glob_tpath={} glob_tfile={}\n".format(hostname,progid,dttm,goflag,j,k,datetag,glob_tpathfile,glob_tpath, glob_tfile))
				print( "{} {} {} -{}- MSG_562 psv {},{} datetag={}\n TO             tpathfile={} tpath={} tfile={}\n".format(hostname,progid,dttm,goflag,j,k,datetag,tpathfile, tpath, tfile))
				print( "bdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbd" )

#				if( re.match('http',line,re.IGNORECASE )):





	print( "{} {} -{}- MSG_710 psv {},{} datetag={} ".format(progid,dttm,goflag,j,k,datetag))
	return(datetag)

def items(datetag):
#	if( datetag == "" ): datetag=kodts("yyyymmdd")
	if( datetag == "" ): datetag="20240418"
	datetag="20240418"
	db3fil="items.db3"
	fpathfile="find_{}.txt".format(datetag)
#	fpath=os.path.dirname(glob_fpathfile)
#	ffile=os.path.basename(glob_fpathfile)
	if( not os.path.exists(fpathfile)):
		print( "BUGS_851 NOTFIND fpathfile={}".format(fpathfile))
		exit()


#	db3="items.db3"
#	tbl="items"
#	flds="id,fsrc,tsrc,txt,kludge"
#	
#	sql3 = sqlite3.connect(db3)
#	sql3.row_factory = sqlite3.Row
#	rows = sql3.cursor()
#	
#	vals="'{}','{}','{}','{}'".format(id,fsrc,tsrc,txt,kludge)
#	sql_ins="insert or replace into {} ({}) values ({})".format(tbl,flds,vals)
#	rows.exec(sql_ins)
#	
#	sql3.close()
#	
#	# sql=sql_ins
#	# sqlcmd="sqlite3 {} \"{}\"".format(db3,sql)

#	sql3 = sqlite3.connect(db3, isolation_level=None)
#	rows = sql3.cursor()
#	rows.execute(sql_ins)
#	rows.close()
#	
#	flds="pathfile,path,file,ext,size,ctime,status,grp,src"

	count=0
	ifile=open(fpathfile,"r")

	j=0; k=0;
	for rawline in ifile:
		if( len(rawline.split(" ")) < 8 ): continue
		infoline=rawline.split(' ..')[0]
		fpathfile="..{}".format(rawline.split(' ..')[1]).strip()
		path=os.path.dirname(fpathfile)
		file=os.path.basename(fpathfile)
		ext="ext"
		if( len(file.split(".")) > 1 ): ext=file.split(".")[1]

		line=' '.join(infoline.split())
#		line=infoline.split(" ")
		nf=len(line.split(" "))

#		j=j+1
#		print( "BUGS_850 {},{} nf={} fpathfile={}<==\n".format(j,k,nf,fpathfile))
#		print( "BUGS_851 {},{} nf={} infoline={}\n".format(j,k,nf,infoline))
#		print( "BUGS_852 {},{} nf={} line={}\n".format(j,k,nf,line))
#		print( "--------------------------------------\n" )
#		continue

		user=line.split(" ")[2]
		size=line.split(" ")[4]
		mth=line.split(" ")[5]
		dd=line.split(" ")[6]
		yyyy=line.split(" ")[7]

		j=j+1
#		print( "BUGS_860 {},{} line={}\n".format(j,k,line))

		print( "BUGS_860 {},{} nf={} path={} file={} ext={} user={} size={} mth={} dd={} yyyy={}\n".  format(j,k,nf,path,file,ext,user,size,mth,dd,yyyy))



	ifile.close()




def mov2mp4(datetag):
	if( datetag == "" ): datetag=kodts("yyyymmdd")
	tpath="../ht/kb/jtfdc/jtfdc_{}".format(datetag)
	glob_fpathfile="../i/*.mov"
	fpath=os.path.dirname(glob_fpathfile)
	ffile=os.path.basename(glob_fpathfile)
	if( not os.path.exists(fpath)):
		print( "BUGS_851 NOTFIND fpath={}".format(fpath))
		exit()
	
	fgloblen=len(glob.glob(glob_fpathfile))
	if( fgloblen < 1 ):
		print( "BUGS_852 NOTFIND ffile={}".format(ffile))
		exit()

	j=0; k=0;
	for fpathfile in glob.glob(glob_fpathfile):
		j=j+1
		print( "{} {} {} -{}- MSG_853 mov2mp4 {:>3d},{:>3d} fpath={} {:<30s} {:>4d} tpath={}".format(hostname,progid,dttm,goflag,j,k,fpathfile, glob_fpathfile,fgloblen, tpath))
		


	print( "{} {} {} -{}- MSG_854 mov2mp4 {:>3d},{:>3d} {:<30s} {:>4d} tpath={}".format(hostname,progid,dttm,goflag,j,k, glob_fpathfile,fgloblen,tpath))


	j=0; k=0; 
	if( goflag == "go" ):
		print( "BUGS_855 goflag={} tpath={}".format(goflag,tpath))
		if( not os.path.exists(tpath)): 
			print( "BUGS_852 NOTFIND tpath={}".format(tpath))
#			print( "{} {} {} -{}- MSG_901 mov2mp4 MKDIR NOTFOUND tpath={} datetag={} {:>3d},{:>3d} {:<30s} { :<30s}".format(hostname,progid,dttm,goflag,tpath,datetag,j,k, glob_fpathfile,tpath))
			os.mkdir(tpath)
		if( not os.path.exists(tpath)): 
			print( "BUGS_856 tpath={}".format(tpath))
#			print( "{} {} {} -{}- MSG_902 mov2mp4 mkdir NOTFOUND tpath={} datetag={} {:>3d},{:>3d} {:<30s} { :<30s}".format(hostname,progid,dttm,goflag,tpath,datetag,j,k, glob_fpathfile,tpath))
			exit()

		j=0; k=0;
		for fpathfile in glob.glob(glob_fpathfile):
			name=fpathfile
			if( not os.path.exists(fpathfile)): continue
			fpath=os.path.dirname(fpathfile)
			ffile=os.path.basename(fpathfile)
			fext=""
			fbase=ffile.split(".")[0]
			if( len(ffile.split(".")) > 1 ): fext=ffile.split(".")[1]

			j=j+1
#			tpath=os.path.dirname(tpathfile)
#			tfile=os.path.basename(tpathfile)

			tbase=re.sub('\W+','_', fbase ).lower()[0:80].replace("_$","")

			text="mp4"
			tfile="{}.{}".format(tbase,text)
#			tpathfile="{}/{}{}.{}".format(tpath,datetag,tbase,text)
			tpathfile="{}/{}.{}".format(tpath,tbase,text)

			fpath=os.path.dirname(fpathfile); ffile=os.path.basename(fpathfile)

#			print( "pqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpq" )
#			print( "{} {} {} -{}- MSG_921 mov2mp4 {},{} \n GLOB_FROM glob_fpathfile={} glob_fpath={} glob_ffile={}\n".format(hostname,progid,dttm,goflag,j,k,glob_fpathfile,glob_fpath, glob_ffile))
#			print( "{} {} {} -{}- MSG_922 mov2mp4 {},{} datetag={}\n FROM           fpathfile={} fpath={} ffile={}\n".format(hostname,progid,dttm,goflag,j,k,"datetag",fpathfile, fpath, ffile))
#			print( "=================================================" )
#			print( "{} {} {} -{}- MSG_931 mov2mp4 {},{} datetag={}\n GLOB_TO__ tpathfile={} glob_tpath={} glob_tfile={}\n".format(hostname,progid,dttm,goflag,j,k,"datetag",tpathfile,"glob_tpath", "glob_tfile"))
#			print( "{} {} {} -{}- MSG_932 mov2mp4 {},{} datetag={}\n TO             tpathfile={} tpath={} tfile={}\n".format(hostname,progid,dttm,goflag,j,k,"datetag",tpathfile, tpath, tfile))
#			print( "bdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbd" )
#			print( "BUGS_856 tpath={} tfile={} fpath={} ffile={} len={} tpathfile={}\n".format(tpath,tfile,fpath,ffile,len(tpathfile),tpathfile))

			if( not os.path.exists(tpathfile)): 
#				syscmd_mov2mp4="ffmpeg -i \"{}\" -vcodec copy -acodec cop {}".format(fpathfile,tpathfile)
				syscmd_mov2mp4="ffmpeg -i \"{}\" -qscale 0 {}".format(fpathfile,tpathfile)
				print( "{} {} {} -{}- MSG_857 mov2mp4 {},{} syscmd_mov2mp4={}\n".format(hostname,progid,dttm,goflag,j,k,syscmd_mov2mp4))
				(out,err)=kosys(syscmd_mov2mp4,'')

			if( os.path.exists(fpathfile)): 
				print( "{} {} {} -{}- MSG_858 mov2mp4 {},{} FOUND={}\n".format(hostname,progid,dttm,goflag,j,k,tpathfile))
				os.remove(fpathfile)

	tgloblen=0;
	if( os.path.exists(tpath)):
		glob_tpathfile="{}/*.mp4".format(tpath)	
		tgloblen=len(glob.glob(glob_tpathfile))
	print( "{} {} {} -{}- MSG_859 mov2mp4 {:>3d},{:>3d} {:<30s} {:>4d} {:>4d} tpath={}".format(hostname,progid,dttm,goflag,j,k, glob_fpathfile,fgloblen,tgloblen,tpath))



def wl2pages(wl):
	j=0; k=0;
	if( not os.path.exists(wl)):
		print( "BUGS_620 NOTFOUND wl={}".format(wl))
		exit()
	tpath=os.path.dirname(wl)
	tfile=os.path.basename(wl)
	tbase=tfile.split(".")[0]
	text=tfile.split(".")[1]
	path_pg="{}/pages".format(tpath)	
	path_zn="{}/pages/zn".format(tpath)	
	path_tn="{}/pages/tn".format(tpath)	
	path_js="{}/pages/js".format(tpath)	

	if( goflag == "go" ):
		if( not os.path.exists(path_pg)): os.mkdir(path_pg)
		if( not os.path.exists(path_zn)): os.mkdir(path_zn)
		if( not os.path.exists(path_tn)): os.mkdir(path_tn)
		if( not os.path.exists(path_js)): os.mkdir(path_js)

	ifp=open(wl,"r")
	lines=ifp.readlines()
	ifp.close()

	bg="../ht/imgs/bg/zn_ko_colorado_mocha.jpg"
	if( not os.path.exists(bg)):
		print( "BUGS_620 NOTFOUND bg={}".format(bg))
		exit()

	j=0; k=0;
	for line in lines.split("\n"):

		if( not os.path.exists(img)): 
			print( "BUGS_621 NOTFOUND {} img={}\n".format(j,img))
			continue;

		j=j+1
		zn0="{}/zn/zn0.jpg".format(path_zn)
		zn="{}/zn/zn_{}.jpg".format(path_zn,j)
		tn="{}/tn_{}.png".format(path_tn,j)
		pg="{}/{}.jpg".format(path_pg, j)
		js="{}/{}.js".format(path_js, j)

		if( goflag == "go" ):
			syscmd_zn0="convert {} -resize 1000x {}".format(img,zn0)
			syscmd_zn="convert {} {} -gravity Center -composite -resize 1100x {}".format(bg,zn0, zn)	
			syscmd_pg="convert {} -resize 650x {}".format(zn, pg )
			syscmd_tn="convert {} -resize 400x {}".format(zn, tn )

			(out,err)=kosys(syscmd_zn0,'')
			(out,err)=kosys(syscmd_zn,'')
			(out,err)=kosys(syscmd_pg,'')
			(out,err)=kosys(syscmd_tn,'')

	if( goflag == "go" ):
		if( not os.path.exists("{}/index.html".format(tpath))):
			shutil.copy("../ht/fb/index.html", tpath)
			shutil.copy("../ht/fb/index.htm", tpath)
		if( not os.path.exists("{}/fb.html".format(tpath))):
			shutil.copy("../ht/fb.html", tpath)
			shutil.copy("../ht/fb.htm", tpath)
	return(wl)



def ifiles(url):
	global a0; global a1; global a2; global a3; global a4; global a5; global a6; global a7; global a8;
	global progid; global dttm; global goflag; global j; global k;

	print( "{} {} -{}- MSG_620 ifiles {},{} url={} ".format(progid,dttm,goflag,j,k,url))

	from selenium import webdriver
	import time
	from selenium.webdriver.common.keys import Keys
	from selenium.webdriver.common.by import By
	from selenium.webdriver.support.ui import WebDriverWait
	from selenium.webdriver.support import expected_conditions as EC
	import random
	import select

	dttm=kodts('')

#	driver = webdriver.Chrome('ChromeDriver')
	browser = webdriver.Firefox()
#	System.setProperty("Web Driver.chrome.driver", "D:\\New folder\\exe\\chromedriver.exe");
#	browser.manage().window().maximize();
	browser.get(url)
	title="ifiles_{}".format(dttm)

#	assert title in browser.title
#	element=browser.find_element(By.TAGNAME("img")
#	Assert.assertEquals(true, element.isDisplayed());
#	Assert.assertEquals(true, element.isSelected());
#	Assert.assertEquals(true, element.isEnabled());
#	String ExpectedText = "download=yes";
#	Assert.assertEquals(ExpectedText, element.getText());
#	String Expected_Title ="KSRTC Official Website for Online Bus Ticket Booking - KSRTC.in";
#	String Actual_Title = driver.getTitle();
#	Assert.assertEquals(Expected_Title, Actual_Title);
#	Verify Text or the element "Home" "PNR Enquiry" "Cancel Tickets" "KSTDC Package Tours" "About Us" 
#	"Contact US" is present of the Site
#	List&lt;WebElement&gt; Tab = browser.findElements(By.xpath("//div[@class='menu']//a"));
#	for(int i=1;i&lt;=Tab.size();i++){;
#	l =browser.findElement(By.XPATH("//img[@title='Tutorialspoint']"));
#	src=l.getAttribute("src");
#	//tag_name[@attribute="value"]
#	//tagName[contains(@attribute_name,"partial_value")]

#	XPath contains a function for the id attribute
#	//*[contains(@id,'some_id')]
#	XPath contains a function for the name attribute
#	//*[contains(@name,'some_name')]
#	XPath contains function for href attribute
#	//a[contains(@href,'some/link.html')]
#	XPath contains function for image src attribute
#	//img[contains(@src,'some/path/logo.png')]
#	XPath contains function for name attribute
#	//div[contains(@name,'some_name')]
#	XPath contains a function for the type attribute
#	//button[contains(@type,'sub')]
#	//tagName[text() ="text_value"]
#	//button/div[text()='Continue']
#	//tagName[contains(text(),'partial_text')]
#	//p[contains(text(),'Welcome to testsigma')]

#	options = Options()
#	options.set_preference("browser.download.folderList", 2)
#	options.set_preference("browser.download.manager.showWhenStarting", False)
#	options.set_preference("browser.download.dir", "./downloads")
#	options.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/x-gzip")
#	driver = webdriver.Firefox(options=options)
# set download options
#	download_path = DOWNLOADS_PATH
# 0 means to download to the desktop, 1 means to download to the default "Downloads" directory, 2 means to use the directory
#	firefox_options.set_preference("browser.download.folderList", 2)
#	firefox_options.set_preference("browser.download.dir", download_path)

#	options = webdriver.ChromeOptions() ;
#	prefs = {"download.default_directory" : "<directory_path>;
#	example: prefs = {"download.default_directory" : "C:\Tutorial\down"};
#	options.add_experimental_option("prefs",prefs);

#	profile = webdriver.FirefoxProfile()
#	profile.set_preference("browser.download.folderList", 2)
#	profile.set_preference("browser.download.manager.showWhenStarting", False)
#	profile.set_preference("browser.download.dir", "<path_to_downlaod_directory>")
# 	Example:profile.set_preference("browser.download.dir", "C:\Tutorial\down")
#	profile.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/octet-stream")







	time.sleep(2)

	elements_imgs = browser.find_elements(By.TAG_NAME, 'img' )
	j=0; k=0;
	for element_img in elements_imgs:
		src=element_img.get_attribute("src");
		id=element_img.get_attribute("id");
		name=element_img.get_attribute("name");
		alt=element_img.get_attribute("alt");
		onclick=element_img.get_attribute("onclick");
		myclass=element_img.get_attribute("class");
		print( "BUGS_110 {},{} src={} onclick={} myclass={} id={} name={} alt={}".format(j,k,src,onclick,myclass,id,name,alt))
		j=j+1
	
	elements_a = browser.find_elements(By.TAG_NAME,'a')	
	j=0; k=0;
	for element_a in elements_a:
		href=element_a.get_attribute("href")
#		txt=element_a.get_attribute("text")
		txt=element_a.text
		print( "BUGS_120 {},{} href={} txt={}\n".format(j,k,href,txt))
		j=j+1
#		browser.switchTo().alert().dismiss();
#		browser.switchTo().alert().accept();
#		browser.switchTo().alert().getText();
#		browser.switchTo().alert().sendKeys("_text_");
#		Alert alert = browser.switchTo().alert(); // switch to alert
#		String alertMessage= browser.switchTo().alert().getText(); // capture alert message



	
#	for(WebElement ele:links){System.out.println(ele.getAttribute("src"));}
	time.sleep(5);
	exit()

# err	driver.find_element("class name", THE_CLASS_NAME )
#	webdriver.find_element("class name", "deleteIcon" )
#	driver.find_element(By.CLASS_NAME, THE_CLASS_NAME)

#	ID = "id"
#	NAME = "name"
#	XPATH = "xpath"
#	LINK_TEXT = "link text"
#	PARTIAL_LINK_TEXT = "partial link text"
#	TAG_NAME = "tag name"
#	CLASS_NAME = "class name"
#	CSS_SELECTOR = "css selector"

#	find_element(By.ID, "id")
#	find_element(By.NAME, "name")
#	find_element(By.XPATH, "xpath")
#	find_element(By.LINK_TEXT, "link text")
#	find_element(By.PARTIAL_LINK_TEXT, "partial link text")
#	find_element(By.TAG_NAME, "tag name")
#	find_element(By.CLASS_NAME, "class name")
#	find_element(By.CSS_SELECTOR, "css selector")
	formflag=""
	if( formflag != "" ):
		username = browser.find_element(By.NAME, 'username').send_keys("_username_")
		password = browser.find_element(By.NAME, 'password').send_keys("_password_")
		submit = browser.find_element(By.NAME, 'continue').click()
		login_form = browser.find_element(By.ID, 'form_login').click()

		print( "BUGS_51 login_form={}\n".format(login_form))
		print( "BUGS_52 username={}\n".format(username))
		print( "BUGS_53 password={}\n".format(password))
		print( "BUGS_54 submit={}\n".format(submit))

#		username.send_keys("_username1_");
#		password.send_keys("_password1_");
#		login_form.click()
#		continue.click()

#		browser.find_element(By.ID("username")).sendkeys("_username_");
#		browser.find_element(By.ID("password")).sendkeys("_password_");
#		browser.find_element(By.XPATH("//*[@id=form_login']//button")).click();
#		WebElement username = browser.findElement(By.id("username"));
#		WebElement password = browser.findElement(By.id("password"));
#		WebElement login = browser.findElement(By.id("form_login"));



	
#	login_form = browser.find_element(By.XPATH, "/html/body/form[1]")
#	login_form = browser.find_element(By.XPATH, "//form[1]")
#	login_form = browser.find_element(By.XPATH, "//form[@id='form_login']")
	
#	username = browser.find_element(By.XPATH, "//form[input/@name='username']")
#	username = browser.find_element(By.XPATH, "//form[@id='form_login']/input[1]")
#	username = browser.find_element(By.XPATH, "//input[@name='username']")
	
#	clear_button = browser.find_element(By.XPATH, "//input[@name='continue'][@type='button']")
#	clear_button = browser.find_element(By.XPATH, "//form[@id='form_login']/input[4]")

#	continue_link = browser.find_element(By.LINK_TEXT, 'Delete this file')
#	continue_link = browser.find_element(By.PARTIAL_LINK_TEXT, 'Delete')

#	heading1 = driver.find_element(By.TAG_NAME, 'h1')

#	content_downloads = browser.find_elements(By.CLASS_NAME, 'classdownloadIcon')
#	content_downloads_len=len(content_downloads)
#	print( "BUGS_10 content_downloads_len={}\n".format(content_downloads_len))

#	content_deletes = browser.find_elements(By.CLASS_NAME, 'deleteIcon')
#	content_deletes_len=len(content_deletes)
#	print( "BUGS_20 content_deletes={}\n".format(content_deletes_len))

	
	classname_download="downloadIcon"
	elements_download = browser.find_elements(By.CLASS_NAME, 'downloadIcon' )
	elements_download_len=len(elements_download)
	print( "BUGS_30 elements_download_len={}".format(elements_download_len))
	j=0; k=0;
	for element_download in elements_download:
		print( "BUGS_31 {},{} element_download={}\n".format(j,k,element_download))
		element_download.click()

#		browser.execute_script("arguments[0].click();", element_download );
#		elements_download[j].click()
#		element_download.scrollIntoView() 
#		elements_download[j].click()
#		#Schedule appointment

#		ele1=WebDriverWait(browser,40).until(expected_conditions.element_to_be_clickable((By.XPATH,'(//button[@class="jquiButton ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only"]/span[contains(.,"Schedule")])[1]')))
#		browser.execute_script("arguments[0].click();",ele1)
# click on continue button
#		WebDriverWait(browser,40).until(expected_conditions.element_to_be_clickable((By.XPATH,'//button[@class="twoButton continueButton ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only"]/span[contains(.,"Continue")]'))).click()
# click on second continue button
#		WebDriverWait(browser,40).until(expected_conditions.element_to_be_clickable((By.XPATH,'//button[@class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only"]/span[contains(.,"Continue")]'))).click()
		time.sleep(1)
		j=j+1


	classname_delete="deleteIcon"
	elements_delete = browser.find_elements(By.CLASS_NAME, classname_delete )
	elements_delete_len=len(elements_delete)
	print( "BUGS_40 elements_delete_len={}".format(elements_delete_len))
	
	j=0; k=0;	
	for element_delete in elements_delete:
		print( "BUGS_41 {},{} element_delete={}\n".format(j,k,element_delete))
#		elements_delete[j].click()
		element_delete.click()
		time.sleep(1)
		j=j+1
		
#	selenium.getAttribute("//img/@src");
#	 2

#	browser.findElement(By.cssSelector("img")).getAttribute("src")




#	random_element_download = random.choice(elements_download)
#	driver.execute_script("arguments[0].click();", random_element_download)
#	random_element_download.click()
#	print("element_download=", random_element_download)

#	random_element_delete = random.choice(elements_delete)
#	driver.execute_script("arguments[0].click();", random_element_delete)
#	random_element_delete.click()
#	print("element_delete=", random_element_delete)


#	elements_tagname=driver.find_element(By.Tag_NAME,"body")
#	elements_tagname_len=len(elements_tagname)
#	print( "BUGS_51 elements_tagname_len={}\n".format(elements_tagname_len))

#	elements_deletethisfile=driver.find_element(By.XPATH,'//[@value="Delete this file"]').click()
#	elements_deletethisfile_len=len(elements_deletethisfile)
#	print( "BUGS_52 elements_deletethisfile_len={}\n".format(elements_deletethisfile_len))


#	element = findElement()
#	assert element, "{}, element does not exist ".format(element)
#	if element.is_displayed() is False:
#		waitForElement(element)
#		element.click()


	browser.close()

#	classname_download="classdownloadIcon"
#	classname_delete="deleteIcon"
#	elements = driver.find_elements(By.CLASS_NAME,'custom-control-input')
#	elements_download = driver.find_elements(By.CLASS_NAME, 'classdownloadIcon' )
# Select a random element from the list
#	random_element = random.choice(elements)
#	driver.execute_script("arguments[0].click();", random_element)
# Click on the selected element
#	random_element.click()
#	print("Element selected: ", random_element)
#	time.sleep(5)
#	driver.find_element(By.XPATH, '//button[text()="Delete this file"]')
# err	webdriver.find_element(By.XPATH, '//a')
#	driver.find_element(By.XPATH, '//a')
#	driver.find_element(By.XPATH, '//img')
#	webdriver.find_element(By.CLASS_NAME, classname)
#	driver.find_element("class name", classname )
#	webdriver.find_element("class name", classname )
#	browser.close()

	print( "BUGS_20 ifiles TAIL url="+url );


	return(url)


def ff(urls):

	urls="""
https://zerohedge.com
https://thegatewaypundit.com
https://youtube.com
https://bitchute.com
https://whatdoesitmean.com
https://gab.com
https://mars.nasa.gov/mars2020/multimedia/raw-images/
https://mars.nasa.gov/msl/multimedia/raw-images/?order=sol+desc%2Cinstrument_sort+asc%2Csample_type_sort+asc%2C+date_taken+desc&per_page=50&page=0&mission=msl
http://101.99.91.131/330.html
"""
	from selenium import webdriver
	browser = webdriver.Firefox()

	for url in urls.split("\n"):
		if( re.search("^#", url )): continue
		if( url == "" ): continue
		script="window.open('{}');return false;".format(url)
		browser.execute_script(script)

	browser.quit()









def todos( db3,tbl,sql ):
	koid=sys.argv[0].split(".")[0]
	kodt=kodts('')
	print( "MSG_201 $progid $dttm $j,$k TODOS a1=$1 a2=$2 a3=$3 a4=$a4\n" )
	db3="ko.db3"; tbl="kolists"; htmout=""; i=0; j=0; k=0; sysout=""; syserr="";
	fsrc="fsrc.txt"; tsrc="tsrc.txt";
	src=""; dir=""; nam=""; txt=""; lin=""; suf=""; pre="";
	fsrc="fsrc.txt"; fdir=""; fnam=""; ftxt=""; ftbl=""; flin=""; fsuf=""; fpre=""
	tsrc="tsrc.txt"; tdir=""; tnam=""; ttxt=""; ttbl=""; tlin=""; tsuf=""; tpre=""
	id=""; kludge="";
#	kodt=ko_dttm()
	koid=progid; 
	print( "{}_{} -= MSG_201 TODOS =- {}-{} syserr={}".format(koid,kodt, j,k, syserr))
	if( not os.path.exists(db3)):
		print( "ERR_201 {} {} {},{} TODOS NOTFOUND db3={}\n" .format(progid,dttm,j,k,db3));
		exit(); 
	if( not os.path.exists(fsrc)):
		print( "ERR_202 {} {} {},{} TODOS NOTFOUND fsrc={}\n" .format(progid,dttm,j,k,fsrc)); 
		exit();
	if( not os.path.exists(tsrc)):
		print( "ERR_203 {} {} {},{} TODOS NOTFOUND tsrc={}\n" .format(progid,dttm,j,k,tsrc)); 
		exit();

#	(err,tbl_status)=kosys("sqlite3 db3 \".tables\" | awk '/tbl/ { print 1 }'",'')
#	if( not tbl_status ):
#		print( "ERR_101 progid dttm j,k TODOS db3=db3 NOTFOUND_TBL tbl=tbl\n"); 
#		exit(); 

	flds_psv="id|fsrc|tsrc|txt|kludge"
	items_psv="""
	id|fsrc|tsrc|txt
	id1|fsrc1|tsrc1|txt
	id2|fsrc2|tsrc2|txt
	id3|fsrc3|tsrc3|txt
"""
	flds="id,fsrc,tsrc,txt,kludge"
	vals="'{}','{}','{}','{}','{}'".format(id,fsrc,tsrc,txt,kludge)
	
	id="ID"; fsrc="fsrc.txt"; tsrc="tsrc.txt"; txt="_TEXT_"; kludge="_KLUDGE_"; rowid=0
	syscmd_ls="ls -lat {}".format(fdir); 
	syscmd_find="find {} -type f -name '{}'".format(fdir,fnam)
	syscmd=syscmd_find
	sql_sel="select from {}".format(tbl)
	sql_ins="insert or replace into $tbl ({}) values ({})".format(tbl,flds,vals)
	sql_upd="update {} set id='{}' where rowid='{}'".format(tbl,id,rowid)
	sql_del="delete from {} where rowid='{}'".format(tbl,rowid)
	sql=sql_sel
	sqlcmd="sqlite3 {} \"{}\"".format(db3,sql)

	options="itemstx"
	options="itemsfs"
	options="itemsdb"; 
	options="itemsfs"
	tmpfil="ko.tmp";
	items=""; items_len=""
	itemsdb="_itemsdb_"; itemsfs="_itemsfs_"; itemstx="_itemstx_";
	options="itemsfs"
	options="itemsdb"
	if ( options == "itemsdb" ):
		sql="select * from {}".format(tbl)
		sqlcmd="sqlite3 {} -header \"{}\"".format(db3,sql)
#		sqlite3 {} "{}".format(db3,sql) > $tmpfil
#		itemsdb=`cat {}`.format(tmpfil)

		itemsdb="sqlite3 {} {}".format(db3,sql)
		print( "BUGS_241 sqlcmd=sqlite3 {} \"{}\" itemsdb={}\n".format(db3,sql,itemsdb))
		itemsdb_len=0;
		if ( itemsdb_len != "" ): itemsdb_len=len(itemsdb)
		items=itemsdb.split("\n"); items_len=itemsdb_len;
		print( "BUGS_241 {} {} {},{} TODOS ITEMSDB db3={} tbl={} itemdb_len={} itemdb={}\n".format(progid,dttm,j,k,db3,tbl,itemsdb_len,itemsdb))
		flds_psv="rownum|id|status|type|sort|lin|linbeg|lincnt|linend|linlim|label|headmark|tailmark|x|y|z|h|w|dx|dy|dz|dh|dw|xmin|ymin|zmin|hmin|wmin|xmax|ymax|zmax|hmax|wmax|color|fsrc|tsrc|descr|txt|b64|kludge"
		linehdr="rownum|id|status|type|sort|lin|linbeg|lincnt|linend|linlim|label|headmark|tailmark|x|y|z|h|w|dx|dy|dz|dh|dw|xmin|ymin|zmin|hmin|wmin|xmax|ymax|zmax|hmax|wmax|color|fsrc|tsrc|descr|txt|b64|kludge"
		lines=linehdr

		db3="ko.db3"; tbl="kolists"
		sql3 = sqlite3.connect(db3)
		sql3.row_factory = sqlite3.Row
		rows = sql3.cursor()
		sql_select="select * from {}".format(tbl)
		rows.execute(sql_select)
		psvs=""; j=0;
		lines =""
		for row in rows:
			j=j+1
			id=row['id']
			if( id == "" ): 
				print( "SKIP {},{} \n".format(j,id))
				next
			rownum=row['rownum']
			id=row['id']
			status=row['status']
			type=row['type']
			sort=row['sort']
			lin=row['lin']
			linbeg=row['linbeg']
			lincnt=row['lincnt']
			linend=row['linend']
			linlim=row['linlim']
			label=row['label']
			headmark=row['headmark']
			tailmark=row['tailmark']
			x=row['x']
			y=row['y']
			z=row['z']
			h=row['h']
			w=row['w']
			dx=row['dx']
			dy=row['dy']
			dz=row['z']
			dh=row['dh']
			dw=row['dw']
			xmin=row['xmin']
			ymin=row['ymin']
			zmin=row['zmin']
			hmin=row['hmin']
			wmin=row['wmin']
			xmax=row['xmax']
			ymax=row['ymax']
			zmax=row['zmax']
			hmax=row['hmax']
			wmax=row['wmax']
			color=row['color']
			fsrc=row['fsrc']
			tsrc=row['tsrc']
			descr=row['descr']
			txt=row['txt']
			b64=row['b64']
			kludge=row['kludge']


			lines+="{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|\n".format(rownum,id,status,type,sort,lin,linbeg,lincnt,linend,linlim,label,headmark,tailmark,x,y,z,h,w,dx,dy,dz,dh,dw,xmin,ymin,zmin,hmin,wmin,xmax,ymax,zmax,hmax,wmax,color,fsrc,tsrc,descr,txt,b64,kludge)


#			lines+="{}|{}\n".format(j,id)
#			lines+="{}\n".format(linevals)
			llen=len(lines)	

		llen=len(lines.split("\n"))
		sql3.close()		

	if ( options == "itemsfs" ):
#		itemsfs=`find {} -type f -maxdepth 1 -name "{}".format(dir,nam)`
#		(syserr,itemsfs)=('find {} -type -f maxdepth 1 -name "{}"'.format(dir,nam),'')

		dir="./htm"; nam="*.htm";
		syscmd_find="find {} -type f -maxdepth 1 -name \"{}\"".format(dir,nam)
		print( "BUGS_310 ITEMSFS dir={} nam={} syscmd_find\n".format(dir,nam,syscmd_find))
#		(out,err)=kosys('find ../i -name="webb*.*"','brief')	
		out=""; err="";
		(out,err)=kosys(syscmd_find,'brief')	
		itemsfs=out.decode().split("\n")
#		print( "BUGS_330 out={} err={} itemsfs={} syscmd_find={}\n".format(out,err,itemsfs,syscmd_find))
		itemsfs_len=len(itemsfs)
		items=itemsfs; items_len=itemsfs_len;
		print( "BUGS_331 progid {} {},{}| TODOS ITEMSDB dir={} nam={} itemsfs_len={} itemsfs={}\n".format(progid,dttm,j,k,dir,nam,itemsfs_len,items))


	usrcmd=""
#	items=items_psv.split("\n")
#	(err,ilen)=kosys("cat {} | awk '{ print NR }'".format(items),'')

	items=lines.split("\n")
	ilen=len(items)
#	print( "BUGS_340 items={} ilen={}\n".format(items,ilen))

	for item in items: 
		j=j+1
# ./htm/confirm.htm
#		id=item.split("/")[1].split(".")[0]
#		id=item.replace(".htm","").replace("./htm/","")
		id=item.split("|")[1]
		plen=len(item.split("|"))
		ilen=len(items)
		print( "BUGS_350 j={} ID={} ilen={} plen={} item=\n".format(j,id,ilen,plen))
#		print( "BUGS_350 j={} ID={} ilen={} plen={} item={}\n".format(j,id,ilen,plen, item))
#		if( j > 10 ): exit()

# 		./htm/wz_dhtml.htm
#		./b64/b64_wx_dhtml.txt
		fsrc=item
		id=item.replace("./htm/","").replace(".htm","")
		if( options == "itemsfs" ):
			b64fil=fsrc.replace("./htm/","./b64/b64_").replace(".htm",".txt")
			syscmd_b64fil="base64 {} > {}".format(fsrc,b64fil)
			(err1,out)=kosys(syscmd_b64fil,'')
#			syscmd_b64="base64 {}\n".format('./htm/confirm.htm')
			syscmd_b64="base64 {}\n".format(item)
#			(err,out)=(syscmd_b64,'')
#			(err,out)=('base64 ./htm/confirm.htm','')
			syscmd_b64cat="cat {}".format(b64fil)
			syscmd_b64cat="base64 {} > {}; cat {}".format(fsrc,b64fil,b64fil)
			(err,out)=(syscmd_b64cat,'')
			b64=out
			print( "BUGS_360 {},{} ID={} fsrc={} b64={} err={} syscmd_b64cat={}".format(j,k,id,fsrc,b64,err, syscmd_b64cat))
			print( "BUGS_361 {},{} ID={} fsrc={} b64={} err={} syscmd_b64={}".format(j,k,id,fsrc,b64,err, syscmd_b64))
			sql="insert into {} (id,b64) values('{}','{}')".format(tbl,id,b64);
			print( "BUGS_362 {},{} ID={} fsrc={} b64fil={}\n".format(j,k,id,fsrc,b64fil))
			print( "BUGS_363 {},{} ID={} syscmd_b64fil={} syscmd_b64={}\n".format(j,k,id,syscmd_b64fil,syscmd_b64))
			print( "BUGS_364 {},{} ID={} sql={}\n".format(j,k,id,sql))
			print( "BUGS_365 {},{} ID={} err1={} err={}\n".format(j,k,id,err1,err))
		

		id=item.split("|")[1]
		status=item.split("|")[2]
#		(err,id)=kosys("printf {} | awk -F\"|\" '{ print $1 }'".format(item),'')
#		(err,fsrc)=kosys("printf {} | awk -F\"|\" '{ print $2 }'".format(item),'')
#		(err,tsrc)=kosys("printf {} | awk -F\"|\" '{ print $3 }'".format(item),'')
#		(err,txt)=kosys("printf {} | awk -F\"|\" '{ print $4 }'".format(item),'')
#		(err, kludge)=kosys("printf {} | awk -F\"|\" '{ print $5 }'".format(item),'')
		print( "{} {} {},{} MSG_381 TODOS id={} ilen={} pqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpq\n".format(progid,dttm,j,k,id,ilen))
		print( "{} {} {},{} MSG_382 TODOS ilen={} ITEM={} ========================================\n".format(progid,dttm,j,k,ilen,item))
		print( "{} {} {},{} MSG_383 TODOS ilen={} ITEM={} ----------------------------------------\n".format(progid,dttm,j,k,ilen,item))
		print( "{} {} {},{} MSG_384 TODOS ilen={} ITEM={} ========================================\n".format(progid,dttm,j,k,ilen,item))
		print( "{} {} {},{} MSG_385 TODOS ilen={} ID={} FSRC={} TSRC={} TXT={} kludge={}\n".format(progid,dttm,j,k,ilen,id,fsrc,tsrc,txt,kludge))
		print( "{} {} {},{} MSG_386 TODOS ilen={} flds_psv={}\n".format(progid,dttm, j,k, ilen, flds_psv))
		print( "{} {} {},{} MSG_387 TODOS ilen={} src={} dir={} nam={} txt={}\n".format(progid,dttm,j,k,ilen,src,dir,nam,txt))
		print( "{} {} {},{} MSG_388 TODOS ilen={} fsrc={} fdir={} fnam={} ftxt={}\n".format(progid,dttm,j,k,ilen,fsrc,fdir,fnam,ftxt))
		print( "{} {} {},{} MSG_389 TODOS ilen={} tsrc={} tdir={} tnam={} ttxt={}\n".format(progid,dttm,j,k,ilen,tsrc,tdir,tnam,ttxt))
		print( "{} {} {},{} MSG_390 TODOS syscmd={}\n".format(progid,dttm,j,k,syscmd))
		print( "{} {} {},{} MSG_391 TODOS sqlcmd={}\n".format(progid,dttm,j,k,sqlcmd))
		print( "{} {} {},{} MSG_392 TODOS ID={} ITEM={} ilen={} bdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbd\n".format(progid,dttm,j,k,id,item,ilen))

		if( not re.search("^g",usrcmd)): 
			print("e=exit q=quit s=skip enter=continue g=go")
# 			usrcmd=raw_input("prompt: " )
#			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_220 ko_selects usrcmd={}".format(usrcmd))
			if( a2 == "go" ) or ( a3 == "go" ) or ( a4 == "go" ):
				print( "BUGS_230 ko_selects GO usrcmd={}".format(usrcmd))


# rownum|id|status|type|sort|lin|linbeg|lincnt|linend|linlim|label|headmark|tailmark|x|y|z|h|w|dx|dy|dz|dh|dw|xmin|ymin|zmin|hmin|wmin|xmax|ymax|zmax|hmax|wmax|color|fsrc|tsrc|descr|txt|b64|kludge
# oline="rownum|{}|{}||{}||{}||{}|{}|||||||||||||||||||||||||{}|{}||||".format(id,status,sort,linbeg,linend,linlim,headmark,fsrc,tsrc,txt)

# (err,out)=kosys(syscmd,'br')

# ofp=open(tsrc,"w")
# ifp=open(fsrc,"r")
# lines=ifp.readlines()
# for line in lines:
#	j=j+1;id="id_{}".format(j)
# 	print("BUGS_610 j={} ID={} line={}\n".format(j,id,line))
#	ofp.write("{}\n".format(tline))
# ofp.close()
# ifp.close()

#	db3file="./kolists/kolists.db3"; tbl="kolists"
#	sql3 = sqlite3.connect(db3file)
#	sql3.row_factory = sqlite3.Row
#	rows = sql3.cursor()
#	sql_select="select * from {}".format(tbl)
#	rows.execute(sql_select)
#	psvs=""; j=0;
#	lines =""
#	for row in rows:
#		j=j+1
#		id=row['id']
#		if( id == "" ): continue
#		lines+="{}|{}\n".format(j,id)
#		j=j+1
#	sql3.close()		
	print( "{}_{} -= MSG_209 TODOS =- {}-{} kludge={}".format(koid,kodt, j,k, kludge))


def todo(args):
	print( "{}_{} -= MSG_202 TODO =- {}-{} syserr={}".format(koid,kodt, j,k, syserr))
def tododb(args):
	print( "{}_{} -= MSG_203 TODODB =- {}-{} syserr={}".format(koid,kodt, j,k, syserr))
def todofs(args):
	print( "{}_{} -= MSG_204 TODOFS =- {}-{} syserr={}".format(koid,kodt, j,k, syserr))
def todotx(args):
	print( "{}_{} -= MSG_205 TODOTX =- {}-{} syserr={}".format(koid,kodt, j,k, syserr))



def fors(args):
	print( "{}_{} -= MSG_207 FORS =- {}-{} syserr={}".format(koid,kodt, j,k, syserr))


def awks(db3,tbl,id):
	db3="../ht/kb/db3/bs4s.db3"; 

	awks="""
ffile|tbl|tfile|headmatch|tailmatch|
../ht/index.html|index_ht|../ht/bs4/index_ht_style.txt|<style|</style
../ht/index.html|index_ht|../ht/bs4/index_ht_script.txt|<script|</script
../ht/index.html|index_ht|../ht/bs4/index_ht_div.txt|<div|</div
../ht/ko/ko.html|ko_ht|../ht/bs4/ko_ht_style.txt|<style|</style
../ht/ko/ko.html|ko_ht|../ht/bs4/ko_ht_script.txt|<script|</script
../ht/ko/ko.html|ko_ht|../ht/bs4/ko_ht_div.txt|<div|</div
../ht/kd/kd.html|kd_ht|../ht/bs4/kd_ht_style.txt|<style|</style
../ht/kd/kd.html|kd_ht|../ht/bs4/kd_ht_script.txt|<script|</script
../ht/kd/kd.html|kd_ht|../ht/bs4/kd_ht_div.txt|<div|</div
../ht/ko/wz.html|wz_ht|../ht/bs4/wz_ht_style.txt|<style|</style
../ht/ko/wz.html|wz_ht|../ht/bs4/wz_ht_script.txt|<script|</script
../ht/ko/wz.html|wz_ht|../ht/bs4/wz_ht_div.txt|<div|</div
./ko.py|ko_py|../ht/bs4/ko_py.txt|^def |^def 
./ko.sh|ko_sh|../ht/bs4/ko_sh.txt|if [ "$0" == "|fi #
../ht/ko.php|ko_ph|../ht/bs4/ko_ph.txt|^function|^function
"""

	j=0;k=0;linbeg=0; linend=9999; 
	for awk in awks.split("\n"):
		j=j+1
		fpathfile=awk.split("|")[0]

		fpath=os.path.dirname(fpathfile)
		ffile=os.path.basename(fpathfile)

		if( not os.path.exists(fpathfile)):
			print( "BUGS_1511 {},{} NOTFOUND fpathfile={} fpath={} ffile={}".format(j,k,fpathfile,fpath,ffile))
			continue;
		splitlen=len(awk.split("|"))
		if( splitlen < 5 ):
			print( "BUGS_1512 {},{} splitlen<5 splitlen={} awk={}".format(j,k,splitlen, awk))
			continue;

		tbl=awk.split("|")[1]
		tpathfile=awk.split("|")[2]

		headmatch=awk.split("|")[3]
		tailmatch=awk.split("|")[4]


		tpath=os.path.dirname(tpathfile)
		tfile=os.path.basename(tpathfile)

		print( "BUGS_1510 {},{} tpathfile={} tpath={} tfile={} tbl={} headmatch={} tailmatch={}".format(j,k,tpathfile,tpath,tfile,tbl,headmatch,tailmatch))
#		syscmd_awk ='awk -v linbeg={} -v linend={} \'/{}/ { print FILENAME"|"NR"|"\$0 }\' {} > {}'.format(linbeg,linend,headmatch,ffile,tfile)
		syscmd_awk ='awk  \'/{}/ {{ print FILENAME"|"NR"|"$0 }}\' {} > {}'.format(headmatch,fpathfile,tpathfile)
		print( "BUGS_1511 {},{} HEADMATCH syscmd_awk={}".format(j,k,syscmd_awk))
		(out,err)=kosys(syscmd_awk,'')

#		syscmd_awk ='awk -v linbeg={} -v linend={} \'/{}/ {{ print FILENAME"|"NR"|"$0 }\' {} >> {}'.format(linbeg,linend,tailmatch,ffile,tfile)
		syscmd_awk ='awk  \'/{}/ {{ print FILENAME"|"NR"|"$0 }}\' {} >> {}'.format(tailmatch,fpathfile,tpathfile)
#		print( "BUGS_1512 {},{} TAILMATCH syscmd_awk={}".format(j,k,syscmd_awk))
		(out,err)=kosys(syscmd_awk,'')



	print( "{} {} {} -{}-  MSG_1480 AWKS {},{} db3={} tbl={} id={}".format(hostname,progid,dttm,goflag, j,k, db3,tbl,id))
# 	awkcmd='awk -v linbeg=0 -v lenend=9999 -v find="<div" \'/find/ { print FILENAME"|"NR"|"$0 }\' {} > {}'.format(linbeg,lenend,find,ifile,ofile)



def bs4s(db3,tbl,id):
	print( "BUGS_1555 bs4s db3={} tbl={}i id={}".format(db3,tbl,id))
#	db3="../ht/kb/db3/bs4s.db3"; 
	db3="../ht/bs4/bs4.db3"

	todos="""
ffile|tbl|tfile|headmatch|tailmatch|
../ht/index.html|index_ht|../ht/bs4/index_ht_style.txt|<style id=|<\/style|
../ht/index.html|index_ht|../ht/bs4/index_ht_script.txt|<script id=|<\/script|
../ht/index.html|index_ht|../ht/bs4/index_ht_div.txt|<div id=|<\/div|
../ht/ko/ko.html|ko_ht|../ht/bs4/ko_ht_style.txt|<style id=|<\/style|
../ht/ko/ko.html|ko_ht|../ht/bs4/ko_ht_script.txt|<scripti id=|<\/script|
../ht/ko/ko.html|ko_ht|../ht/bs4/ko_ht_div.txt|<div|<\/div|
../ht/kd/kd.html|kd_ht|../ht/bs4/kd_ht_style.txt|<style id=|<\/style|
../ht/kd/kd.html|kd_ht|../ht/bs4/kd_ht_script.txt|<script id=|<\/script|
../ht/kd/kd.html|kd_ht|../ht/bs4/kd_ht_div.txt|<div id=|<\/div|
../ht/ko/wz.html|wz_ht|../ht/bs4/wz_ht_style.txt|<style id=|<\/style|
../ht/ko/wz.html|wz_ht|../ht/bs4/wz_ht_script.txt|<script id=|<\/script|
../ht/ko/wz.html|wz_ht|../ht/bs4/wz_ht_div.txt|<div|<\/div|
./ko.py|ko_py|../ht/bs4/ko_py.txt|^def |^def |
../ht/ko.php|ko_php|../ht/bs4/ko_php.txt|^function|^function|
./ko.sh|ko_sh|../ht/bs4/ko_sh.txt|if . .... == .|fi #|
"""
	dttm=kodts('')
	tbls="index_ht ko_ht kd_ht wz_ht ko_py ko_sh ko_php"
#	tbls="ko_sh"
	sql3 = sqlite3.connect(db3, isolation_level=None)
	rows = sql3.cursor()
	for tbl in tbls.split(" "):
		sql_delete="delete from {}".format(tbl)
		rows.execute(sql_delete);
	rows.close()

	j=0;k=0;linbeg=0; linend=9999; lincnt=0;linlim=0; type="_type_"; label="_label_"; txt="_txt_";
	for todo in todos.split("\n"):
#		print( "BUGS_1580 {},{} todo={}".format(j,k,todo))
		if( re.search( '^#', todo )): 
			print( "BUGS_1581 SKIP# {},{} bs4={}\n".format(j,k, todo))
			continue
#		if( re.search( '', todo )): 
		if( len(todo) < 2 ):
			print( "BUGS_1582 SKIP_SPACE {},{} todo={}\n".format(j,k,todo))
			continue
		j=j+1
#		print( "BUGS_1583 TODO {},{} todo={}\n".format(j,k,todo))
#		continue

		fpathfile=todo.split("|")[0]
		fsrc=fpathfile

		fpath=os.path.dirname(fpathfile)
		ffile=os.path.basename(fpathfile)

		if( not os.path.exists(fpathfile)):
			print( "BUGS_1610 {},{} NOTFOUND fpathfile={} fpath={} ffile={}".format(j,k,fpathfile,fpath,ffile))
			continue;
		splitlen=len(todo.split("|"))
		if( splitlen < 5 ):
			print( "BUGS_1620 {},{} SPLITLEM splitlen<5 splitlen={} todo={}".format(j,k,splitlen, todo))
			continue;

		tbl=todo.split("|")[1]
		tpathfile=todo.split("|")[2]
		tsrc=tpathfile

		headmatch=todo.split("|")[3]
		tailmatch=todo.split("|")[4]


		tpath=os.path.dirname(tpathfile)
		tfile=os.path.basename(tpathfile)
		fext=tfile.split(".")[1]
		type=fext

		print( "BUGS_1621 {},{} fpathfile={} fpath={} ffile={} tbl={} headmatch={} tailmatch={}".format(j,k,fpathfile,fpath,ffile,tbl,headmatch,tailmatch))
		print( "BUGS_1622 {},{} tpathfile={} tpath={} tfile={} tbl={} headmatch={} tailmatch={}".format(j,k,tpathfile,tpath,tfile,tbl,headmatch,tailmatch))
#		exit()

#		syscmd_awk ='awk -v linbeg={} -v linend={} \'/{}/ { print FILENAME"|"NR"|"\$0 }\' {} > {}'.format(linbeg,linend,headmatch,ffile,tfile)
#		syscmd_awk ='awk  \'/{}/ {{ print FILENAME"|"NR"|"$0 }}\' {} > {}'.format(headmatch,fpathfile,tpathfile)
#		print( "BUGS_1511 {},{} HEADMATCH syscmd_awk={}".format(j,k,syscmd_awk))
#		(out,err)=kosys(syscmd_awk,'')

#		syscmd_awk ='awk -v linbeg={} -v linend={} \'/{}/ {{ print FILENAME"|"NR"|"$0 }\' {} >> {}'.format(linbeg,linend,tailmatch,ffile,tfile)
#		syscmd_awk ='awk  \'/{}/ {{ print FILENAME"|"NR"|"$0 }}\' {} >> {}'.format(tailmatch,fpathfile,tpathfile)
#		print( "BUGS_1512 {},{} TAILMATCH syscmd_awk={}".format(j,k,syscmd_awk))
#		(out,err)=kosys(syscmd_awk,'')

		k=0;
		
		flds="id,linbeg,lincnt,linend,headmark,tailmark,fsrc,tsrc,type,label,txt,status"
#		sql3 = sqlite3.connect(":memory:")
		sql3 = sqlite3.connect(db3, isolation_level=None)
		db = sql3.cursor()

		dttm=kodts('')
		ofile=open(tpathfile,"w")
		with open(fpathfile) as ifile:
			while line := ifile.readline():
				k=k+1
				if( re.search( '^#', line )): continue
				if( re.search( '\+=', line )): continue
				if( len(line) > 80 ): continue;

#				print( "BUGS_1630 _________ {},{} headmatch={} tailmatch={} line={} fpathfile={} tpathfile={}\n".format(j,k,headmatch,tailmatch,line,fpathfile,tpathfile))
#				if( re.match(headmatch,line)):
				if( re.search(headmatch,line,re.IGNORECASE)):
					status="head";
					txt=line.replace("'","").replace("\n","");
					linbeg=k; type="{}".format(headmatch);
					lincnt=0; linend=0;
					id=line.replace(headmatch,"").split(" ")[0].replace("'","")
					if( re.search("sh",fext, re.IGNORECASE )): id="if_{}".format(line.split("\"")[8])
					if( re.search("php",fext, re.IGNORECASE )): id="function_{}".format(line.split(" ")[2].split("\(")[0])
					if( re.search("py",fext, re.IGNORECASE )): id="def_{}".format(line.split(" ")[1])
					if( re.search("ht",fext, re.IGNORECASE)):
						if( re.search("script",headmatch, re.IGNORECASE )): 
							id="script_{}".format(line.split("=")[1].replace("\"",""))
						if( re.search("style",headmatch, re.IGNORECASE )): 
							id="style_{}".format(line.split("=")[1].replace("\"",""))
						if( re.search("div",headmatch, re.IGNORECASE )): 
							id="div_{}".format(line.split("=")[1].replace("\"",""))



					print( "BUGS_1631 HEADMATCH {}|{}|{}|{}|{}|{}|{}|{}\n".format(j,k,linbeg,linend,lincnt,fpathfile,tpathfile,headmatch,line))
					ofile.write("HEADMATCH|{}|{}|{}|{}|{}|{}\n".format(j,k,fpathfile,tpathfile,headmatch,line))
					vals="'{}','{}','{}','{}','{}','{}','{}','{}','{}','{}','{}','{}'".format(id,linbeg,lincnt,linend,headmatch,tailmatch,fsrc,tsrc,type,label,txt,status)
					sql_insert="insert or replace into {} ( {} ) values ( {} )".format(tbl,flds,vals)
					print( "BUGS_1632 db3={} tbl={} sql_insert={}".format(db3,tbl,sql_insert))
					db.execute(sql_insert)

#				if( re.match(tailmatch,line)):
				if( re.search(tailmatch,line, re.IGNORECASE)):
					status="tail"
#					id="_tailmatch_"
					linend=k; lincnt=linend-linbeg; 
					fsrc=fpathfile; tsrc=tpathfile; txt=line; 
					type=ffile.split(".")[1]
					print( "BUGS_1641 TAILMATCH {}|{}|{}|{}|{}|{}|{}|{}\n".format(j,k,linbeg,linend,lincnt,fpathfile,tpathfile,tailmatch,line))
					ofile.write("TAILMATCH|{}|{}|{}|{}|{}|{}\n".format(j,k,fpathfile,tpathfile,tailmatch,line))
					txt=line.replace("'","").replace("\n","")
					vals="'{}','{}','{}','{}','{}','{}','{}','{}','{}','{}','{}','{}'".format(id,linbeg,lincnt,linend,headmatch,tailmatch,fsrc,tsrc,type,label,txt,status)
					sql_insert="insert or replace into {} ( {} ) values ( {} )".format(tbl,flds,vals)
					db.execute(sql_insert)
#					print( "BUGS_1642 db3={} tbl={} sql_insert={}".format(db3,tbl,sql_insert))
#					linbeg=0; linend=0; lincnt=0;txt="_txt_";
					status="";
		ofile.close()
		db.close();

	print( "{} {} {} -{}-  MSG_1680 bs4s {},{} db3={} tbl={} ".format(hostname,progid,dttm,goflag, j,k, db3,tbl))
# 	awkcmd='awk -v linbeg=0 -v lenend=9999 -v find="<div" \'/find/ { print FILENAME"|"NR"|"$0 }\' {} > {}'.format(linbeg,lenend,find,ifile,ofile)


def csv2jsn(csvfil,jsnfil):
	"cat {} | python -c 'import csv, json, sys; print(json.dumps([dict(r) for r in csv.DictReader(sys.stdin)]))' > {}".format(csvfil,jsnfil)
	print( "{}_{} -= MSG_209 B642 =- {}-{} csvfil={} jsnfil={} syserr={}".format(koid,kodt, j,k, csvfil,jsnfil,syserr))

def jsn2csv(jsnfil,csvfil):
	print( "{}_{} -= MSG_209 B642 =- {}-{} jsnfil={} csvfil={} syserr={}".format(koid,kodt, j,k,csvfil,jsnfil,syserr))


	
def ko_dicts(args):
	print("BUGS_1000 ko_dicts args={}\n".format(args))

	my_dict = {'name': 'John', 'age': 25, 'city': 'New York'}
	print(my_dict['name'])  # Output: John
	
	
	print(my_dict.get('name'))  # Output: John
	print(my_dict.get('gender'))  # Output: None
	print(my_dict.get('gender', 'Unknown'))  # Output: Unknown
	
	for key, value in my_dict.items(): print(key, value)
	for key in my_dict.keys(): print(key, my_dict[key])
	
	for value in my_dict.values(): print(value)
	
# Define a dictionary
	student = {'name': 'John', 'age': 20, 'grade': 'A'}
	print(student['name'])  # Output: John
	print(student['age'])   # Output: 20
	print(student.get('city'))  # Output: None

# Accessing a non-existent key with a default value
	print(student.get('city', 'Unknown'))  # Output: Unknown
	student['grade'] = 'B'
	print(student['grade'])  # Output: B


# Adding a new key-value pair
	student['city'] = 'New York'
	print(student['city'])  # Output: New York
	
# Creating a dictionary
	fruits = {"apple": 1, "banana": 2, "orange": 3}

# Looping through keys using a for loop
	for key in fruits: print(key)
	
	fruits = {"apple": 1, "banana": 2, "orange": 3}
# Looping through keys using the keys() method
	for key in fruits.keys():
	    print(key)
	
	fruits = {"apple": 1, "banana": 2, "orange": 3}
# Checking if a key exists in the dictionary
	if "apple" in fruits.keys(): print("The key 'apple' exists in the dictionary.")

	fruits = {'apple': 'red', 'banana': 'yellow', 'orange': 'orange'}
	for color in fruits.values(): print(color)
	
	fruits = {'apple': 'red', 'banana': 'yellow', 'orange': 'orange'}
	for fruit, color in fruits.items(): print(color)
	
	fruits = {'apple': 'red', 'banana': 'yellow', 'orange': 'orange'}
	values = [color for color in fruits.values()]
	print(values)

	fruits = {"apple": "red", "banana": "yellow", "orange": "orange"}
	for fruit in fruits: print(fruit)  # prints the keys
	
	for fruit in fruits: print(fruits[fruit])  # prints the values
	
	for fruit, color in fruits.items(): print(fruit, "is", color)
	
	fruits = {"apple": "red", "banana": "yellow", "orange": "orange"}
	keys = list(fruits.keys())  # convert dictionary keys to a list
	i = 0
	while i < len(keys):
	    fruit = keys[i]
	    print(fruit, "is", fruits[fruit])
	    i += 1


	fruits = {"apple": "red", "banana": "yellow", "orange": "orange"}
	modified_fruits = {fruit: color.upper() for fruit, color in fruits.items()}
	print(modified_fruits)
	
	person = {
	    "name": "John Doe",
	    "age": 30,
	    "address": {
	        "street": "123 Main St",
	        "city": "New York",
	        "state": "NY"
	    }
	}
	
	print(person["address"]["city"])  # Output: New York
	
	for key1, value1 in person.items():
	    if isinstance(value1, dict):
	        for key2, value2 in value1.items():
	            print(key2, ":", value2)
	    else:
	        print(key1, ":", value1)
	
	person["address"]["city"] = "San Francisco"

# Filtering dictionary data using dictionary comprehension
	original_dict = {'apple': 2, 'banana': 3, 'orange': 4, 'grape': 1}
	filtered_dict = {key: value for key, value in original_dict.items() if value > 2}
	print(filtered_dict)

# Output: {'banana': 3, 'orange': 4}
# Filtering dictionary data using the filter() function
	original_dict = {'apple': 2, 'banana': 3, 'orange': 4, 'grape': 1}
	filtered_dict = dict(filter(lambda item: item[1] > 2, original_dict.items()))
	print(filtered_dict)

# Output: {'banana': 3, 'orange': 4}
# Transforming dictionary data using dictionary comprehension
	original_dict = {'apple': 2, 'banana': 3, 'orange': 4, 'grape': 1}
	transformed_dict = {key: value * 2 for key, value in original_dict.items()}
	print(transformed_dict)

# Output: {'apple': 4, 'banana': 6, 'orange': 8, 'grape': 2}
# Transforming dictionary data using the map() function
	original_dict = {'apple': 2, 'banana': 3, 'orange': 4, 'grape': 1}
	transformed_dict = {key: value for key, value in map(lambda item: (item[0], item[1] * 2), original_dict.items())}
	print(transformed_dict)
# Output: {'apple': 4, 'banana': 6, 'orange': 8, 'grape': 2}


	dict1 = {'a': 1, 'b': 2}
	dict2 = {'c': 3, 'd': 4}
	dict1.update(dict2)
	print(dict1)  # Output: {'a': 1, 'b': 2, 'c': 3, 'd': 4}


	dict1 = {'a': 1, 'b': 2}
	dict2 = {'c': 3, 'd': 4}
	merged_dict = {**dict1, **dict2}
	print(merged_dict)  # Output: {'a': 1, 'b': 2, 'c': 3, 'd': 4}
	
	dict1 = {'a': 1, 'b': 2}
	dict2 = {'b': 3, 'c': 4}
	dict1.update(dict2)
	print(dict1)  # Output: {'a': 1, 'b': 3, 'c': 4}


	dict1 = {'a': 1, 'b': 2}
	dict1['b'] = 3
	print(dict1)  # Output: {'a': 1, 'b': 3}
	sales = {
	    'apple': 10,
	    'banana': 5,
	    'orange': 7,
	    'grape': 3
	}
	total_sales = 0
	for product, quantity in sales.items():
	    total_sales += quantity
	print(f'Total sales: {total_sales}')

	max_sales = 0
	best_selling_product = ''
	for product, quantity in sales.items():
	    if quantity > max_sales:
	        max_sales = quantity
	        best_selling_product = product
	print(f'Best selling product: {best_selling_product}')
	
	sales = {
	    'apple': {
	        'north': 5,
	        'south': 3,
	        'east': 2,
	        'west': 4
	    },
	    'banana': {
	        'north': 2,
	        'south': 1,
	        'east': 3,
	        'west': 3
	    },
	    'orange': {
	        'north': 3,
	        'south': 2,
	        'east': 4,
	        'west': 1
	    }
	}
	
	for product, region_data in sales.items():
	    print(f'Sales of {product}:')
	    for region, quantity in region_data.items():
	        print(f'- {region.capitalize()}: {quantity}')
	    print()
	
# Create a dictionary
# Access a key with a default value
	my_dict = {'apple': 1, 'banana': 2, 'orange': 3}
	value = my_dict.get('pear', 0)
	print(value)  # Output: 0

# Create a dictionary
# Access a key with a default value
	my_dict = {'apple': 1, 'banana': 2, 'orange': 3}
	value = my_dict['pear'] if 'pear' in my_dict else 0
	print(value)  # Output: 0

# Create a dictionary
# Access a key using the 'get' method
	my_dict = {'apple': 1, 'banana': 2, 'orange': 3}
	value = my_dict.get('apple')
	print(value)  # Output: 1
	
# Access a missing key using the 'get' method
	value = my_dict.get('pear')
	print(value)  # Output: None
	my_dict = {'name': 'John', 'age': 25, 'city': 'New York'}
	if 'name' in my_dict:
	    print('The key "name" exists in the dictionary.')
	else:
	    print('The key "name" does not exist in the dictionary.')
	my_dict = {'name': 'John', 'age': 25, 'city': 'New York'}
	name = my_dict.get('name', 'Default Name')
	print(f'The value associated with the key "name" is: {name}')
	address = my_dict.get('address', 'Default Address')
	print(f'The value associated with the key "address" is: {address}')
	
	data = {'a': 50, 'b': 150, 'c': 200, 'd': 75}
	filtered_data = {key: value for key, value in data.items() if value > 100}
	for key, value in filtered_data.items():
	    print(key, value)
	
	data = {'a': 1, 'b': 2, 'c': 3, 'd': 4}
	for key, value in data.items():
	    print(key, value)
	fruits = {'apple': 'red', 'banana': 'yellow', 'orange': 'orange'}
	
# Iterate over the keys
	for key in fruits.keys():
	    print(key)
	
# Check if a key exists
	if 'apple' in fruits.keys():
	    print('Apple is present in the dictionary')
	fruits = {'apple': 'red', 'banana': 'yellow', 'orange': 'orange'}
	
# Iterate over the values
	for value in fruits.values():
	    print(value)
	
# Check if a value exists
	if 'red' in fruits.values():
	    print('A fruit with red color is present in the dictionary')
	
	fruits = {'apple': 'red', 'banana': 'yellow', 'orange': 'orange'}
	
# Iterate over the key-value pairs
	for key, value in fruits.items():
	    print(key, value)
	
# Check if a key-value pair exists
	if ('apple', 'red') in fruits.items():
	    print('An apple with red color is present in the dictionary')
	
#	{key_expression: value_expression for item in iterable }
	numbers = [1, 2, 3, 4, 5]
	squared_dict = {num: num**2 for num in numbers}
	print(squared_dict)
	people = {'Alice': 25, 'Bob': 30, 'Charlie': 35}
	age_dict = {age: [name for name, age in people.items() if age == age] for name, age in people.items()}
	print(age_dict)






def ko_dict(db3, sql):
#      """Returns data from an SQL query as a list of dicts."""
	j=0; k=0; item="_item_"

	print( "{} {} -{}- MSG_660 ko_dicts {},{} db3={} sql={}".format(progid,dttm,goflag, j,k,db3,sql))
	if( not os.path.exists(db3)):
		print( "{} {} -{}- MSG_665 sql_dicts {},{} NOTFOUND db3={} sql={{".format(progid,dttm,goflag,j,k,db3,sql))
		return("db3")
		
	try:
		con = sqlite3.connect(db3)
		con.row_factory = sqlite3.Row
		things = con.execute(sql).fetchall()
		results = [{k: item[k] for k in item.keys()} for item in things]
		ilen=len(items)
#		print( "{} {} -{}- MSG_660 sql_dicts {},{} ilen={} items={}".format(progid,dttm,goflag,j,k,ilen,items))
#		for key, val in results.items():
#			j=j+1
#			print("{} {} -{}- BUGS_670 sql_dicts {},{} key={} val={}\n".format(progid,dttm,goflag,j,k,key, val))

#		for item in items:
#			j=j+1
#			print( "{} {} -{}- MSG_680 sql_dicts {},{} ilen={} item={}".format(progid,dttm,goflag,j,k,ilen,item))
		
		return(results)

	except Exception as e:
#		print(f"Failed to execute. Query: {select_query}\n with error:\n{e}")
		print( "{} {} -{}- ERR_690 sql_dict {},{} sql={} e={}".format(progid,dttm,goflag,j,k,sql,e))
		return []
	finally:
		con.close()


def ko_sels(db3file,tbl,sql):
	koid=sys.argv[0].split(".")[0]
	kodt=kodts('')
	j=0; k=0; usrcmd=""; syscmd="";
	id=""; linbeg=""; linend=""; status=""; headmark=""
	items=""; ilim=0; syserr=""; dtamode=""

	if( db3file == "" ): db3file="/Volumes/ka1tbr2/ht/ko/kolists/kolists.db3"
	if( db3file == "" ): db3file="./kolists/kolists.db3"
	db3file="./kolists/kolists.db3"
	fsrc="./kolists/kolists.htm"
	if( tbl == "" ):  tbl="kolists"
	sql_select="select * from {}".format(tbl);
	print( "{}_{} -= ko_finds_180 =- {}-{} syserr={}".format(koid,kodt, j,k, syserr))
	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 {} {} ko_sels NOTFOUND db3file={}".format(progid,dttm,db3file))
		exit()
	if( not os.path.exists(fsrc)):
		print("BUGS_231 {} {} ko_sels NOTFOUND fsrc={}".format(progid,dttm,fsrc))
		exit()
	if( sql_select == "" ):
		print("BUGS_232 {} {} ko_sels NOTFOUND sql_select={}".format(progid,dttm,sql_select))
		exit()
	j=0; k=0; htmout=""	

	htmfil="./kolists/kolists_{}.htm".format(kodt)
	htmfil="./kolists/kolists_{}.htm".format('new')
	print( "BUGS_210 ko_sels htmfil={}\n".format(htmfil))
	id="head"
	ofp_htmfil=open(htmfil,"w")
	ofp_htmfil.write("<script id=script_kolists>\n")
	ofp_htmfil.write("<-- script_kolists_{}_{} -->\n".format(koid,kodt))



	db3file="./kolists/kolists.db3"; tbl="kolists"
	sql3 = sqlite3.connect(db3file)
	sql3.row_factory = sqlite3.Row
	rows = sql3.cursor()
	sql_select="select * from {}".format(tbl)
	rows.execute(sql_select)
	psvs=""; j=0;
	lines =""
	for row in rows:
		id=row['id']
		if( id == "" ): continue
		linbeg=row['linbeg']
		linend=row['linend']
		lines+="{}|{}|{}|{}\n".format(j,id,linbeg,linend)
		j=j+1
	sql3.close()		



	print( "BUGS_100 j={} lines={}".format(j,lines))
	print( "BUGS_100 j={} lines_2={}".format(j,lines[2]))
	for line in lines.split("\n"):
		j=j+1
		print( "BUGS_101 j={} line={}".format(j,line))
		

	sql3 = sqlite3.connect(db3file)
	sql3.row_factory = sqlite3.Row
	rows = sql3.cursor()
	rows.execute(sql_select)

	for row in rows:
		j=j+1
		id=row['id']
		if( id == "" ): continue
		linbeg=row['linbeg']
		linend=row['linend']
		kolists_psv="./kolists/kolists_{}.psv"
		kolist_psv="./kolists/kolist_{}.psv"
		kolist_htm="./kolist/kolist_{}.htm"
		syscmd_kolists_psv=""; syscmd_kolist_psv=""; syscmd_kolist_htm=""
#		syscmd_kolists_psv='cat {} | awk -v id={} -v linbeg={} -v linend={} \' NR> linbeg NR<linend { print 1 }\' >> {}'.format(fsrc,id,linbeg,linend,kolist_psv)
#		test="cat {} {} {} {} {}".format(fsrc,id,linbeg,linend,kolist_psv)
#		syscmd_kolists_psv="BUGS_221 cat {} | awk -v id={} -v linbeg={} -v linend={} '{ print $1 }' \n".format(fsrc,id, linbeg, linend )
#		syscmd_kolist_psv="BUGS_222 cat {} | awk -v id={} -v linbeg={} -v linend={} '{ print $1 }'\n".format(fsrc,id, linbeg, linend, kolist_psv )
#		syscmd_kolist_htm="BUGS_223 cat {} | awk -v id={} -v linbeg={} v- linend={} '{ print $1 }'\n".format(fsrc,id, linbeg, linend, kolist_psv )

#		syscmd_kolists_psv="cat {} | awk -v id={} -v linbeg={} -v linend={} ' NR > linbeg && NR < linend { print $1 }' >> {}".format(id,linbeg,linend,kolists_psv)
#		syscmd_htm="cat {} | awk -v id={} -v linbeg={} -v linend={} ' NR > linbeg && NR < linend { print $1 }'  >> {}".format(id,linbeg,linend,kolist_htm)
#		syscmd_kolist_psv="cat {} | awk -v id={} -v linbeg={} -v linend={} ' NR > linbeg && NR < linend { print \"|||||||||\"id\"||\"$0\"|||\" } >> {}".format(id,linbeg,linend,kolist_psv)



		print("BUGS_501 {} {}  {},{} ko_sels ID={} LINBEG={} LINEND={} pqpqpqpqpqpqpqpqpqpqpqpqpqpqpqp".format(progid,dttm,j,k,id,linbeg,linend))
		print("BUGS_502 {} {}  {},{} ko_sels id={} syscmd_htm={}".format(progid,dttm,j,k,id,linbeg,linend,syscmd))
		print("BUGS_503 {} {}  {},{} ko_sels id={} linbeg={} lenend={} syscmd_kolist_psv={}".format(progid,dttm,j,k,id,linbeg,linend,syscmd_kolist_psv))
		print("BUGS_504 {} {}  {},{} ko_sels id={} linbeg={} lenend={} syscmd_kolists_psv={}".format(progid,dttm,j,k,id,linbeg,linend,syscmd_kolists_psv))
		print("BUGS_505 {} {}  {},{} ko_sels id={} linbeg={} lenend={} syscmd_kolist_htm={}".format(progid,dttm,j,k,id,linbeg,linend,syscmd_kolist_htm))
		print("BUGS_506 {} {}  {}<{} ko_sels id={} bdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbd\n" )

		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_220 ko_selects usrcmd={}".format(usrcmd))
			if( a2 == "go" ) or ( a3 == "go" ) or ( a4 == "go" ):
				print( "BUGS_230 ko_selects GO usrcmd={}".format(usrcmd))
#				(err,out)=kosys(syscmd,'br')
				impfil="./kolists/kolists_{}.psv".format(id)
				psvfil="./kolists/kolist_{}.psv".format(id)
				ofile=fsrc
				ofp_impfil=open(impfil,"w")
				ofp_psvfil=open(psvfil,"w")
#				ofp_htmfil.write("kolists['{}'] = {}\n".format(id,'`'))

#				data=open(ifile,"r").readlines()
				ifp=open(fsrc)
				lines=ifp.readlines()
				k=0
				for line in lines:
					print("BUGS_810 j={} ID={} linbeg={} linend={}  line={} ===================\n".format(j,id,linbeg,linend,line))
					j=j+1; k=k+1
					if( j < int(linbeg) ): continue
					if( j > int(linend) ): continue

					print("line{}|{}".format(j,line.strip()))
					status="keep"; sort=k;
					linlim=int(linend)-int(linbeg);
					headmark="kolists["; 
					tsrc=impfil;
					txt=line;
# rownum|id|status|type|sort|lin|linbeg|lincnt|linend|linlim|label|headmark|tailmark|x|y|z|h|w|dx|dy|dz|dh|dw|xmin|ymin|zmin|hmin|wmin|xmax|ymax|zmax|hmax|wmax|color|fsrc|tsrc|descr|txt|b64|kludge


					oline="rownum|{}|{}||{}||{}||{}|{}|||||||||||||||||||||||||{}|{}||||".format(id,status,sort,linbeg,linend,linlim,headmark,fsrc,tsrc,txt)


					ofp_impfil.write("{}\n".format(oline))
					ofp_psvfil.write("{}\n".format(line))
					ofp_htmfil.write("{}\n".format(line))
				ofp_htmfil.write("{} # {}_end\n".format(id,'`'))

				ofp_impfil.close()
				ofp_psvfil.close()

				print("BUGS_281 {} {}  {}<{} ko_sels id={} linbeg={} linend={} pqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpq\n" .format(koid,kodt,j,k,id,linbeg,linend))
				print("BUGS_282 {} {}  {}<{} ko_sels id={} psvfil={} psvfils={} htmfil={} bdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbd\n" .format(koid,kodt,j,k,id,psvfil,psvfils,htmfil))
		
	sql3.close()		

	ofp_htmfil.write("{}; \n".format('`'))
	ofp_htmfil.write("	</script id=script_kolists_end_{}_{}>\n".format(koid,kodt))
	ofp_htmfil.close()

#	data += row['pathfile']
#	datalen=len(data)
	out=""
	return(htmfil)



def ascii(linematch):
	if( linematch == "." ): linematch=""
	print( "BUGS_660 ascii linematch={}\n".format(linematch))
#	ascii="'\024 &\027"
	ascii_psv="""
type|dec|oct|hex|bin|symbol|htmnum|number|htmnam|name|descr|kludge
control|0|000|00|00000000|NUL|&#00;||Null character|kludge
control|1|001|01|00000001|SOH|&#01;||Start of Heading|kludge
control|2002|02|00000010|STX|&#02;||Start of Text|kludge
control|3003|03|00000011|ETX|&#03;||End of Text|kludge
control|4004|04|00000100|EOT|&#04;||End of Transmission|kludge
control|5005|05|00000101|ENQ|&#05;||Enquiry|kludge
control|6006|06|00000110|ACK|&#06;||Acknowledge|kludge
control|7007|07|00000111|BEL|&#07;||Bell, Alert|kludge
control|8010|08|00001000|BS|&#08;||Backspace|kludge
control|9011|09|00001001|HT|&#09;||Horizontal Tab|kludge
control|10012|0A|00001010|LF|&#10;||Line Feed|kludge
control|11013|0B|00001011|VT|&#11;||Vertical Tabulation|kludge
control|12014|0C|00001100|FF|&#12;||Form Feed|kludge
control|13015|0D|00001101|CR|&#13;||Carriage Return|kludge
control|14016|0E|00001110|SO|&#14;||Shift Out|kludge
control|15017|0F|00001111|SI|&#15;||Shift In|kludge
control|16020|10|00010000|DLE|&#16;||Data Link Escape|kludge
control|17021|11|00010001|DC1|&#17;||Device Control One (XON)|kludge
control|18022|12|00010010|DC2|&#18;||Device Control Two|kludge
control|19023|13|00010011|DC3|&#19;||Device Control Three (XOFF)|kludge
control|20024|14|00010100|DC4|&#20;||Device Control Four|kludge
control|21025|15|00010101|NAK|&#21;||Negative Acknowledge|kludge
control|22026|16|00010110|SYN|&#22;||Synchronous Idle|kludge
control|23027|17|00010111|ETB|&#23;||End of Transmission Block|kludge
control|24030|18|00011000|CAN|&#24;||Cancel|kludge
control|25031|19|00011001|EM|&#25;||End of medium|kludge
control|26032|1A|00011010|SUB|&#26;||Substitute|kludge
control|27033|1B|00011011|ESC|&#27;||Escape|kludge
control|28034|1C|00011100|FS|&#28;||File Separator|kludge
control|29035|1D|00011101|GS|&#29;||Group Separator|kludge
control|30036|1E|00011110|RS|&#30;||Record Separator|kludge
control|31037|1F|00011111|US|&#31;||Unit Separator|kludge
printable|32040|20|00100000|SP|&#32;||Space|kludge
printable|33041|21|00100001|!|&#33;|&excl;|Exclamation mark|kludge
printable|34042|22|00100010|"|&#34;|&quot;|Double quotes (or speech marks)|kludge
printable|35043|23|00100011|#|&#35;|&num;|Number sign|kludge
printable|36044|24|00100100|$|&#36;|&dollar;|Dollar|kludge
printable|37045|25|00100101||kludge|&#37;|&percnt;|Per cent sign|kludge
printable|38046|26|00100110|&|&#38;|&amp;|Ampersand|kludge
printable|39047|27|00100111|'|&#39;|&apos;|Single quote|kludge
printable|40050|28|00101000|(|&#40;|&lparen;|Open parenthesis (or open bracket)|kludge
printable|41051|29|00101001|)|&#41;|&rparen;|Close parenthesis (or close bracket)|kludge
printable|42052|2A|00101010|*|&#42;|&ast;|Asterisk|kludge
printable|43053|2B|00101011|+|&#43;|&plus;|Plus|kludge
printable|44054|2C|00101100|,|&#44;|&comma;|Comma|kludge
printable|45055|2D|00101101|-|&#45;||Hyphen-minus|kludge
printable|46056|2E|00101110|.|&#46;|&period;|Period, dot or full stop|kludge
printable|47057|2F|00101111|/|&#47;|&sol;|Slash or divide|kludge
printable|48060|30|00110000|0|&#48;||Zero|kludge
printable|49061|31|00110001|1|&#49;||One|kludge
printable|50062|32|00110010|2|&#50;||Two|kludge
printable|51063|33|00110011|3|&#51;||Three|kludge
printable|52064|34|00110100|4|&#52;||Four|kludge
printable|53065|35|00110101|5|&#53;||Five|kludge
printable|54066|36|00110110|6|&#54;||Six|kludge
printable|55067|37|00110111|7|&#55;||Seven|kludge
printable|56070|38|00111000|8|&#56;||Eight|kludge
printable|57071|39|00111001|9|&#57;||Nine|kludge
printable|58072|3A|00111010|:|&#58;|&colon;|Colon|kludge
printable|59073|3B|00111011|;|&#59;|&semi;|Semicolon|kludge
printable|60074|3C|00111100|<|&#60;|&lt;|Less than (or open angled bracket)|kludge
printable|61075|3D|00111101|=|&#61;|&equals;|Equals|kludge
printable|62076|3E|00111110|>|&#62;|&gt;|Greater than (or close angled bracket)|kludge
printable|63077|3F|00111111|?|&#63;|&quest;|Question mark|kludge
printable|64100|40|01000000|@|&#64;|&commat;|At sign|kludge
printable|65101|41|01000001|A|&#65;||Uppercase A|kludge
printable|66102|42|01000010|B|&#66;||Uppercase B|kludge
printable|67103|43|01000011|C|&#67;||Uppercase C|kludge
printable|68104|44|01000100|D|&#68;||Uppercase D|kludge
printable|69105|45|01000101|E|&#69;||Uppercase E|kludge
printable|70106|46|01000110|F|&#70;||Uppercase F|kludge
printable|71107|47|01000111|G|&#71;||Uppercase G|kludge
printable|72110|48|01001000|H|&#72;||Uppercase H|kludge
printable|73111|49|01001001|I|&#73;||Uppercase I|kludge
printable|74112|4A|01001010|J|&#74;||Uppercase J|kludge
printable|75113|4B|01001011|K|&#75;||Uppercase K|kludge
printable|76114|4C|01001100|L|&#76;||Uppercase L|kludge
printable|77115|4D|01001101|M|&#77;||Uppercase M|kludge
printable|78116|4E|01001110|N|&#78;||Uppercase N|kludge
printable|79117|4F|01001111|O|&#79;||Uppercase O|kludge
printable|80120|50|01010000|P|&#80;||Uppercase P|kludge
printable|81121|51|01010001|Q|&#81;||Uppercase Q|kludge
printable|82122|52|01010010|R|&#82;||Uppercase R|kludge
printable|83123|53|01010011|S|&#83;||Uppercase S|kludge
printable|84124|54|01010100|T|&#84;||Uppercase T|kludge
printable|85125|55|01010101|U|&#85;||Uppercase U|kludge
printable|86126|56|01010110|V|&#86;||Uppercase V|kludge
printable|87127|57|01010111|W|&#87;||Uppercase W|kludge
printable|88130|58|01011000|X|&#88;||Uppercase X|kludge
printable|89131|59|01011001|Y|&#89;||Uppercase Y|kludge
printable|90132|5A|01011010|Z|&#90;||Uppercase Z|kludge
printable|91133|5B|01011011|[|&#91;|&lsqb;|Opening bracket|kludge
printable|92134|5C|01011100|\|&#92;|&bsol;|Backslash|kludge
printable|93135|5D|01011101|]|&#93;|&rsqb;|Closing bracket|kludge
printable|94136|5E|01011110|^|&#94;|&Hat;|Caret - circumflex|kludge
printable|95137|5F|01011111|_|&#95;|&lowbar;|Underscore|kludge
printable|96140|60|01100000|`|&#96;|&grave;|Grave accent|kludge
printable|97141|61|01100001|a|&#97;||Lowercase a|kludge
printable|98142|62|01100010|b|&#98;||Lowercase b|kludge
printable|99143|63|01100011|c|&#99;||Lowercase c|kludge
printable|100144|64|01100100|d|&#100;||Lowercase d|kludge
printable|101145|65|01100101|e|&#101;||Lowercase e|kludge
printable|102146|66|01100110|f|&#102;||Lowercase f|kludge
printable|103147|67|01100111|g|&#103;||Lowercase g|kludge
printable|104150|68|01101000|h|&#104;||Lowercase h|kludge
printable|105151|69|01101001|i|&#105;||Lowercase i|kludge
printable|106152|6A|01101010|j|&#106;||Lowercase j|kludge
printable|107153|6B|01101011|k|&#107;||Lowercase k|kludge
printable|108154|6C|01101100|l|&#108;||Lowercase l|kludge
printable|109155|6D|01101101|m|&#109;||Lowercase m|kludge
printable|110156|6E|01101110|n|&#110;||Lowercase n|kludge
printable|111157|6F|01101111|o|&#111;||Lowercase o|kludge
printable|112160|70|01110000|p|&#112;||Lowercase p|kludge
printable|113161|71|01110001|q|&#113;||Lowercase q|kludge
printable|114162|72|01110010|r|&#114;||Lowercase r|kludge
printable|115163|73|01110011|s|&#115;||Lowercase s|kludge
printable|116164|74|01110100|t|&#116;||Lowercase t|kludge
printable|117165|75|01110101|u|&#117;||Lowercase u|kludge
printable|118166|76|01110110|v|&#118;||Lowercase v|kludge
printable|119167|77|01110111|w|&#119;||Lowercase w|kludge
printable|120170|78|01111000|x|&#120;||Lowercase x|kludge
printable|121171|79|01111001|y|&#121;||Lowercase y|kludge
printable|122172|7A|01111010|z|&#122;||Lowercase z|kludge
printable|123173|7B|01111011|{|&#123;|&lcub;|Opening brace|kludge
printable|124174|7C|01111100|||&#124;|&verbar;|Vertical bar|kludge
printable|125175|7D|01111101|}|&#125;|&rcub;|Closing brace|kludge
printable|126176|7E|01111110|~|&#126;|&tilde;|Equivalency sign - tilde|kludge
printable|127177|7F|01111111|DEL|&#127;||Delete|kludge
"""

	j=0;k=0;i=0;
	items=ascii_psv.split("\n")
	ilen=len(items)
		
	print( "BUGS_920 ascii {},{} ilen={} linematch={}\n".format(j,k, ilen,linematch ))
	j=0; k=0; i=0; item="_item_";
	if( linematch == "" ):
		while( True ):
#			if( items[i] ): item=items[i]
			print( "BUGS_930 {},{} i={} linematch={} item={}\n".format(j,k, i,linematch,item))	
			i=i+1	
			if( i > ilen):break
			print( "BUGS_930 ascii {},{} ilen={} linematch={}\n".format(j,k, ilen,linematch ))

	if( linematch != "" ):
		while( True ):
			item=items[0]
			item=items[i]
			if( re.match(linematch,item)): 
				print( "BUGS_940 {},{} i={} linematch={} item={}\n".format(j,k, i,linematch,item))	
				return(items[i])
			i=i+1
			if( j>ilen):break
	print( "{}".format(ascii_psv))
	print( "BUGS_940 ascii {},{} ilen={} linematch={}\n".format(j,k, ilen,linematch ))
#	d = dict(); d['xyz'] = 123; d['abc'] = 345;
#	for i in d: print("% s % d" % (i, d[i])) 
#	s = "Geeks"; for i in s: print(i)
#	for i in range(0, 10, 2): print(i) 
#	for j in range(1, 4): 
#		for k in range(1, 4): print(j, k) 

#	fruits = ["apple", "banana", "cherry"]; colors = ["red", "yellow", "green"];
#	for fruit, color in zip(fruits, colors): print(fruit, "is", color) 

#	t = ((1,2), (3, 4), (5, 6)); for a, b in t: print(a, b)
#	for letter in 'geeksforgeeks': 
#		if letter == 'e' or letter == 's': continue
#		print('letter=:', letter) 	

#	for letter in 'geeksforgeeks': pass
#	print('lastletter :', letter) 

#	sum = 0; for i in range(1, 10): sum = sum + i 
#	print("sum first 10 numbers=", sum)

#	for i in range(1, 4):	print(i) 
#	else:			print("nobreak\n")

#	do{
# // statement or 
# // set of statements
#		} while(condition)

#	print("Printing list items using while loop") 
#	size = len(items) 
#	while(i < size): print(list1[i]) ; i = i+1;

#	j=0; k=0; i=0; ilen=len(items)
#	while(True): 
#		item=items[i]
#		print( "BUGS_970 i={} ilen={} item={} items={}\n".format(i,ilen,item,items))
#		if(i < ilen and ilen) < 10): continue
#		else: break
#		i=i+1
#		if( i > ilen ): break

#	print( "BUGS_980 ascii {},{} ilen={} linematch={}\n".format(j,k, ilen,linematch ))
#
#	print( "{} {} {},{} BUGS_990 ascii item={} linematch={}\n".format(progid,dttm,j,k,item,linematch))
#	return(ascii_psv)
	
def urls(datetag):
	j=0; k=0; tnams_mp4="*.mp4"; tnams_mp3="*.mp3";
	if( datetag == "" ): datetag=kodt('').split("_")[0]
	fdir="../ht/yt/txt"; fnams="ytlist_*.psv";
	ffil="yt_{}.psv".format(datetag);
	pathfile="{}/{}".format(fdir,ffil)

	print( "{} {} {},{} BUGS_981 commands dls fdir={} fnams={}\n".format(progid,dttm,j,k,fdir, fnams))
	return(pathfile)



def dls(fdir,fnams,tdir_mp4,tdir_mp3,psvdir,datetag):
	j=0; k=0; tnams_mp4="*.mp4"; tnams_mp3="*.mp3";
	if( datetag == "" ): datetag=kodt('').split("_")[0]
	psvdir="../ht/yt/txt"; 
	psvnam="yt_{}.psv".format(datetag)
	print( "{} {} {},{} BUGS_971 commands dls fdir={} fnams={}\n".format(progid,dttm,j,k,fdir, fnams))
	print( "{} {} {},{} BUGS_971 commands dls tdir_mp4={} tdir_mp4={} tnams_mp4={}\n".format(progid,dttm,j,k, tdir_mp4,tnams_mp4))
	print( "{} {} {},{} BUGS_971 commands dls tdir_mp3={} tdir_mp3={} tnams_mp3={}\n".format(progid,dttm,j,k, tdir_mp3,tnams_mp3))
	print( "{} {} {},{} BUGS_971 commands dls datetag={}\n".format(progid,dttm,j,k, datetag))

#	import fnmatch
#	matches = []
#	for root, dirnames, filenames in os.walk('src'):
#		for filename in fnmatch.filter(filenames, '*.c'):
#			matches.append(os.path.join(root, filename))
# https://vimhelp.org/matchit.txt.html

#	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


	if( not os.exists.path(fdir)): print( "{} {} {},{} BUGS_7691 dls NOTFOUND fdir={}".format(progid,dttm,j,k,fdir)); exit();
	if( not os.exists.path(psvdir)): print( "{} {} {},{} BUGS_7692 dls NOTFOUND psvdir={}".format(progid,dttm,j,k,psvdir)); exit();
	if( not os.exists.path(tdir_mp4)):
		print( "{} {} {},{} BUGS_7693 dls NOTFOUND tdir_mp4={}".format(progid,dttm,j,k,tdir_mp4)); 
		if( goflag == "go" ):
			print( "{} {} {},{} BUGS_7694 dls MKDIR tdir_mp4={}".format(progid,dttm,j,k,tdir_mp4)); 
			os.mkdir(tdir_mp4)
			
	if( not os.exists.path(tdir_mp3)):
		print( "{} {} {},{} BUGS_7693 dls NOTFOUND tdir_mp3={}".format(progid,dttm,j,k,tdir_mp3)); 
		if( goflag == "go" ):
			print( "{} {} {},{} BUGS_7694 dls MKDIR tdir_mp3={}".format(progid,dttm,j,k,tdir_mp3)); 
			os.mkdir(tdir_mp3)

	wlfile="{}/ytlist_{}.psv".format(psvdir,datetag)
	if( not os.exists.path(wlfile)):
		print( "{} {} {},{} BUGS_7694 dls NOTFOUND wlfile={}".format(progid,dttm,j,k,wlfile)); 
		exit()

	ifp=open(wlfile,"r")
	items=ifp.readlines()
	ifp.close()
#
	for item in items:
		j=j+1
		url=""; desc=""; kludge=""
		url=item.split("|")[0]
		if( len(item.split("|")) > 0): desc=item.split("|")[1]
		if( len(item.split("|")) > 0): kludge=item.split("|")[2]

		syscmd_dls="media-downloader -l \"{}\"".format(url)
#		print( "{} {} {},{} BUGS_7710 dls ITEM={} wlfile={}".format(progid,dttm,j,k,item, wlfile)); 
		print( "{} {} {},{} BUGS_7711 dls ITEM={} syscmd_dls={}".format(progid,dttm,j,k,item, syscmd_dls)); 

		if( not re.search("^g",usrcmd)): 
			print("e=exit q=quit s=skip enter=continue g=go")
# 			usrcmd=raw_input("prompt: " )
#			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_220 ko_selects usrcmd={}".format(usrcmd))
#			if( a2 == "go" ) or ( a3 == "go" ) or ( a4 == "go" ):
			if( goflag == "go" ):
				print( "{} {} {},{} BUGS_1000 dls GO syscmd_dls={} usrcmd={}".format(suscmd_dls,usrcmd))
				(out,err)=kosys(syscmd_dls,'')


	tnams_mp4="*.mp4"; 
	syscmd_find_mp4s="find {} -type f -maxdepth 1 -name \"{}\"".format(tdir_mp4,tnams_mp4)
	(mp4s,err) = kosys(syscmd_find_mp4s,'')
	print( "{} {} {},{} BUGS_1001 dls GO syscmd_find_mp4s={} mp4s={}".format(syscmd_find_mp4s,mp4s))

#	tnams_mp4="*.mp4"
	syscmd_find_mp3s="find {} -type f -maxdepth 1 -name \"{}\"".format(tdir_mp3,tnams_mp3)
	(mp3s,err) = kosys(syscmd_find_mp3s,'')
	print( "{} {} {},{} BUGS_1002 dls GO syscmd_find_mp3s={} mp3s={}".format(suscmd_find_mp3s,mp3s))
	results="_results_dls"
	return(results)

def dlscps(fdir,datetag):
	j=0; k=0; item="_item_"
	fdir="/Users/konet/Downloads"; filematch="*.mp4";
	print( "{} {} {},{} BUGS_1041 commands dlscps fdir={} filematch={}\n".format(progid,dttm,j,k,fdir, filematch))
	syscmd_find="find {} -type f -name \"{}\"".format(fdir,filematch)
	(items,err) = kosys(syscmd_find,'')

	tnam=re.sub('[^A-Za-z0-9]+', '', fnam)
#	ilen=len(items.decode().split("\n"))
	ilen=len(items)
	print( "{} {} {},{} BUGS_1042 dlscps ilen={} item={}\n".format( progid,dttm, j,k, ilen, items))
#	for item in items.decode().split("\n"):
	for item in items:
		j=j+1
		print( "{} {} {},{} BUGS_930 dlscps ilen={} item={}\n\n".format( progid,dttm, j,k,ilen, item))

	print( "{} {} {},{} BUGS_1043 dlscps ilen={} item={}\n".format( progid,dttm, j,k, ilen, items))

#	cleanString = re.sub('\W+','', string )
	items=glob.glob("/Users/konet/Downloads/*.mp4")
	print( "BUGS_950 items={}".format(items))
	results="_results_dlscps"
	return(results)

def dlsrms(fdir,filematch):
	j=0; k=0;
	print( "{} {} {},{} BUGS_1060 dlsrms fdir={} filematch={}\n".format(progid,dttm,j,k,fdir, filematch))
	results="_results_dlsrms"
	syscmd_find_mp4s="find {} -type f -maxdepth 1 -name \"*.mp4\"".format(fdir)
	(items,err)=kosys(syscmd_find_mp4s,'')
	if( a2 == "go" ) or ( a3 == "go" ) or ( a4 == "go" ) or ( a5 == "go" ): goflag="go"
	for item in items:
		j=j+1
		print( "{} {} {},{} BUGS_1070 dlsrms fdir={} item={}\n".format(progid,dttm,j,k,fdir, item))
		if( goflag == "go" ):
			print( "{} {} {},{} BUGS_1071 dlsrms GO fdir={} item={}\n".format(progid,dttm,j,k,fdir, item))
#			os.remove(item)
	return(results)
	
	
def dict_factory(cursor, row):
    d = {}
    for idx, col in enumerate(cursor.description):
        d[col[0]] = row[idx]
    return d

def ko_types(args):
	L = [
"Hello World",
20,
20.5,
1j,
["apple", "banana", "cherry"],
("apple", "banana", "cherry"),
range(6),
{"name" : "John", "age" : 36},
{"apple", "banana", "cherry"},
frozenset({"apple", "banana", "cherry"}),
True,
b"Hello",
bytearray(5),
memoryview(bytes(5)),
None
]

	filesuffixes="txt png jpg gif csv psv db3 json wl pdf mp4 mp3".split(" ")
	for _ in range(len(L)):
		print(type(L[_]))
		if( type(L[_])) is dict: print( "BUGS_100 l={} DICT".format( L[_])); return('dict')
		if( type(L[_])) is list: print( "BUGS_100 l={} LIST".format( L[_])); return('list')
		if( type(L[_])) is str: 
			if( os.exists.path(L[_])):
				print( "BUGS_100 l={} FILE".format( L[_])); return('file')
			for filesuffix in filesuffixes:
				if( len(L[_].split(".") > 1 )):
					suffix=L[_].split(".")[1]
					if( suffix == filesuffix ):
						print( "BUGS_100 l={} FILE".format( L[_])); return('filename')
			print( "BUGS_100 l={} STR".format( L[_])); return('str')
		if( type(L[_])) is int: print( "BUGS_100 l={} INT".format( L[_])); return('int')
		if( type(L[_])) is tuple: print( "BUGS_100 l={} TUPLE".format( L[_])); return('tuple')
		if( type(L[_])) is float: print( "BUGS_100 l={} FLOAT".format( L[_])); return('float')

	return("")
	
	

def sql3_row2dict(row):
	return(dict(zip(row.keys(), row)))

def sql3_data2dicts(db3file,sql):
	"""Returns data from an SQL query as a list of dicts."""
	try:
		sql3 = sqlite3.connect(db3file)
		sql3.row_factory = sqlite3.Row
		rows = sql3.execute(sql).fetchall()
		unpacked = [{k: item[k] for k in item.keys()} for item in rows]
		return unpacked
	except Exception as e:
		print(f"BUGS_1500 sql3_data2dicts sql={sql}\n error=\n{e}")
#		return []
		return('')
	finally:
		sql3.close()



def csvfil2dict(csvfil):
# read csv file to a list of dictionaries
	with open(csvfil, 'r') as file:
		csv_reader = csv.DictReader(file)
		mydict = [row for row in csv_reader]
		print(mydict)

	data = pd.read_csv(csvfil)
	mydict = data.to_dict(orient='records')
	print(mydict)
	return(mydict)

def csvtxt2dict(csv):
	mydict=[]

	if( os.exists.path(csv)):
		csvnew=csvfil.replace(".csv","_new.csv")
		with open(csvfil, mode='r') as infile:
			reader = csv.reader(infile)
		with open(csvnew, mode='w') as outfile:
			writer = csv.writer(outfile)
			mydict = {rows[0]:rows[1] for rows in reader}
	else:
		mydict = { rows[0]:rows[1] for rows in csv }	

	return(mydict)



def sql3_rows2dicts(db3file,tbl,sql):

	if( not os.path.exists(db3file)):
		print( "BUGS_1500 sql3_rows2dicts NOTFOUND DB3FILE={} tbl={} sql={}" .format(db3file,tbl,sql))
		return('','','','')
	if( sql == "" ):
		if( tbl == "" ):
			print( "BUGS_1500 sql3_rows2dicts db3file={} tbl={} NOTFOUND SQL={}" .format(db3file,tbl,sql))
			return('')
		sql="select * from {}".format(tbl)


#	sql3 = sqlite3.connect(":memory:")
	sql3 = sqlite3.connect(db3file)
	sql3.row_factory = sqlite3.Row

	rows = sql3.cursor()
#	rows.execute("""\
#		create table if not exists User(
#		id integer primary key, 
#		name text);
#		""")

# insert records
# data1 = {"name": "john jones"}
# data2 = {"name": "jane doe"}

#	rows.execute("insert into User (name) values (:name);", data1)
#	rows.execute("insert into User (name) values (:name);", data2)
#	rows.execute("select * from User;")


# query all records
	rows.execute(sql)
	print( "BUGS_1530 rows.description={}\n".format(rows.description))

# get result from query
	res = rows.fetchall()
	print( "BUGS_1530 rows.description={}\n".format(rows.description[0][0]))
#	print( "BUGS_1531 rows.description={}\n".format(rows.description[1][0]))
#	print( "BUGS_1532 rows.description={}\n".format(rows.description[2][0]))
#	for i, element in enumerate(my_list): print(f"Index {i}: {element}")
#	myres=res.copy()

#	print( "BUGS_1532 res.description={}\n".format(res.description))
	sql3.close()


	rlen=len(res)
	if( rlen == 0 ):
		print( "BUGS_1541 NOTFOUND  rlen={} db3file={} tbl={} sql={}\n".format(rlen,db3file,tbl,sql))
		return('')
	if( not res[0] ):
		print( "BUGS_1542 NOTFOUND rlen={} db3file={} tbl={} sql={}\n".format(rlen,db3file,tbl,sql))
		return('')
	print( "BUGS_1543 sql3_rows2dicts rlen={} db3file={} tbl={} sql={}\n".format(rlen,db3file,tbl,sql))

# res is a list of sqlite3.Row and can be converted to dict using `dict`
	j=0; k=0;
#	for( j=0; j< len(res); j++ ):
	for rs in res:
		print("BUGS_1545 {},{} rlen={} keys={}\n".format(j,k,rlen, res[0].keys()))
		j=j+1

# optional, sqlite3.Row is indexable by a key
	
	print([dict(r) for r in res])
	mydict=[dict(r) for r in res];

	print( "BUGS_1570 mydict={}\n".format(mydict))
#	print( "BUGS_1571 mydict.description={}\n".format(mydict.description[0][0]))
#	print( "BUGS_1572 mydict.description={}\n".format(mydict.description[1][0]))
#	print( "BUGS_1573 mydict.description={}\n".format(mydict.description[2][0]))

	(csvdta,psvdta,jsndta) = dict2csv(mydict)
	print( "BUGS_1581 csvdta={}\n".format(csvdta))
	print( "BUGS_1582 psvdta={}\n".format(psvdta))
	print( "BUGS_1581 jsndta={}\n".format(jsndta))
	
	return(csvdta,psvdta,jsndta,mydict)

def dict2csv(mydict):
	csvfil="ko_dict.csv"
	psvfil="ko_dict.psv"
	jsnfil="ko_dict.json"

#	with open(csvfil,"w") as csvfil_ptr:
#		writer = csv.DictWriter(csvfil_ptr, fieldnames=field_names)
#		writer.writerheader()
#		writer.writerows(dict)
#	writer.close()

#	print( "BUGS_1591 mydict={}\n".format(mydict))
#	print( "BUGS_1592 mydict.keys()={}\n".format(dict.keys()))
#	print( "BUGS_1593 mydict0.keys()={}\n".format(mydict[0].keys()))
#	print( "BUGS_1594 mydict1.keys()={}\n".format(mydict[1].keys()))
#	print( "BUGS_1595 mydict2.keys()={}\n".format(mydict[2].keys()))
#	print( "BUGS_1596 mydict3.keys()={}\n".format(mydict[3].keys()))
#	print( "BUGS_1597 mydict0={}\n".format(mydict[0]))
#	print( "BUGS_1598 mydict1={}\n".format(mydict[1]))
#	print( "BUGS_1599 mydict2={}\n".format(mydict[2]))
#	print( "BUGS_1600 mydict3={}\n".format(mydict[3]))
##	print( "BUGS_1601 mydict0.keys={}".format(csv.DictWriter(dict[0].keys())))

#	with open(csvfil, 'wb') as f:  
#		w = csv.DictWriter(f, mydict[0].keys())
#		w.writerow(dict((fn,fn) for fn in mydict[0].keys()))
#		w.writerows(mydict)
#	f.close()

	
	with open(csvfil,"w") as ofp:
		w = csv.DictWriter(ofp, mydict[0].keys())
		w.writeheader()
#		w.writerow(mydict)
		w.writerows(mydict)
	ofp.close()

#	if( not os.path.exists(csvfil)):
#		print( "BUGS_1610 NOTFOUND csvfil={}".format(csvfil))
#		exit()

	import pandas as pd
	pd.DataFrame(mydict).to_csv(csvfil, index=False)
	pd.DataFrame(mydict).to_csv(psvfil, index=False, sep="|")
	pd.DataFrame(mydict).to_json(jsnfil, orient='records', lines=True)

#	with open(jsnfil, 'w') as f:
#		f.write(df.to_json(orient='records', lines=True))

	csvdta=pd.DataFrame(mydict).to_csv( index=False)
	psvdta=pd.DataFrame(mydict).to_csv( index=False, sep="|")
	jsndta=pd.DataFrame(mydict).to_json(orient='records', lines=True)


	j=0; k=0; val=""; key=""
#	for key, val in mydict[0].items():
#		j=j+1
#		print( "BUGS_1631 {},{} key={} val={}\n".format(j,k,key, val))	
#
#	j=0; k=0;
#	for key in mydict[0].keys():
#		j=j+1
#		print( "BUGS_1632 {},{} key={} val={}\n".format(j,k,key, val))	
#
#	j=0; k=0;
#	for val in mydict[0].values():
#		j=j+1
#		print( "BUGS_1633 {},{} key={} val={}\n".format(j,k,key, val))

#	with open(jsnfil, 'w') as f:
#		f.write(df.to_json(orient='records', lines=True))

#	json_list = json.loads(json.dumps(list(DataFrame.T.to_dict().values())))




	print( "BUGS_1651 psvdta={}\n".format(psvdta))
	print( "BUGS_1662 jsndta={}\n".format(jsndta))

	return(psvdta,csvdta,jsndta)

	



def bs4s_find(links):
# I'm trying to find content between <dd class='title'> and </dd>
# and what i want is the 2nd content of those
# and I add that to a newlist

	soup = BeautifulSoup(links)
#	dlist = soup.findAll('dd', 'title')
	dlist = soup.findAll('div')
	dlist = soup.findAll('script')
	gotdata = dlist[1]
	newlist.append(gotdata)
#	gotdata = dlist[1] if len(dlist) > 1 else 'null'

	for i in range (1, len(dlist)):
		try:
			print (dlist[i])
		except ValueError: 
			print("Error Value.")
		except indexError: 
			print("Error index")
		except:
			print('error ')

	return(newlist)



def sql3_fldval(self,sql,parameter=()):

#	sql3 = sqlite3.connect(db3file)
#	c = sql3.cursor()
#	print(sql3_fldval(c, 'SELECT * FROM things WHERE id=?', (id,)))

#	mycursor = self.memconn.cursor()
#	mycursor.execute('''SELECT * FROM maintbl;''')
#	first get the names, because they will be lost after retrieval of rows
#	names = list(map(lambda x: x[0], mycursor.description))
#	manyrows = mycursor.fetchall()
#	return manyrows, names



	execute = self.execute(sql, parameters)
	fetch = execute.fetchone()
	if fetch is None: return {}
	return {k[0]: v for k, v in list(zip(execute.description, fetch))}


def sql3_factory(a1,a2,a3):
	db3file="ko.db3"; tbl="cfg"; sql_cnt="select * from {}".format(tbl)
	if( not os.path.exists(db3file)):
		print( "{} {} -{}- BUGS_1480 sql3_factory {},{} NOTFOUND db3file={} tbl={} sql={}\n" .format(progid,dttm,goflag,j,k, db3file,tbl,sql ))
	print( "{} {} -{}- BUGS_1481 sql3_factory {},{} db3file={} tbl={} sql={}\n" .format(progid,dttm,goflag,j,k, db3file,tbl,sql ))

	items=[]; items_psv=""; items_arr=[];

	sql3 = sqlite3.connect(db3fil)
	rows = sql3.cursor()
	res = rows.execute(sql).fetchall()
	data = dict(zip([c[0] for c in rows.description], res[0]))

	print( "{} {} -{}- BUGS_1481 sql3_factory {},{} db3file={} tbl={} sql={} data={} rows={} res={}\n".format(progid,dttm,goflag,j,k, db3file,tbl,sql,data,rows,res ))
	print(data)
	sql3.close()
	return(data);





#	sql="select 1 as a"
#	sql3 = sqlite3.connect(":memory:")
#	sql3.row_factory = dict_factory

	sql3 = sqlite3.connect(":memory:")
#	sql3 = sqlite3.connect(db3file)
	sql3.row_factory = sqlite3.Row
	rows = sql3.cursor()
	rows.execute(sql)
	print( rows.fetchone()["a"] )
	items=rows;
	results=rows.fetchall()
	sql3.close()

	rlen=len(result)
	print( "{} {} -{}- BUGS_1481 sql3_factory {},{} rlen={} results={} db3file={} tbl={} sql={}\n" .format(progid,dttm,goflag,j,k, rlen, results, db3file,tbl,sql ))
	ilen=len(items)
	print( "{} {} -{}- BUGS_1482 sql3_factory {},{} ilen={} items={} db3file={} tbl={} sql={}\n" .format(progid,dttm,goflag,j,k, ilen, items, db3file,tbl,sql ))

	j=0;
	for item in items:
		print( "{} {} -{}- BUGS_1483 sql3_factory {},{} ilen={} item={} db3file={} tbl={} sql={}\n" .format(progid,dttm,goflag,j,k, ilen, item, db3file,tbl,sql ))

#		tblcnt=row['cnt']
#		tblcnt=row[i]
		print( "{} {} -{}- BUGS_9161 {},{} item={} items={}\n".format(progid,dttm,goflag,j,k,item,items))
		j=j+1
	print( "{} {} -{}- BUGS_1490 {},{} ilen={} items={}\n".format(progid,dttm,goflag,j,k,ilen,items))

#	fldpsv=' '.join(flds)
	j=0; k=0;
	for item in items:
		print( "{} {} -{}- BUGS_1500 {},{} ilen={} items={}\n".format(progid,dttm,goflag,j,k,ilen,items))
		j=j+1
		
	fldnams = [tuple[0] for tuple in items.description]
	print( "{} {} -{}- BUGS_1501 {},{} ilen={} fldnams={} db3file={} tbl={} sql={}\n".format(progid,dttm,goflag,j,k,ilen,fldnams, db3file,tbl,sql))

	sql3 = sqlite3.connect(":memory:")
	sql3.execute('create table t (a text, b text, c text)')
	sql3.execute('insert into t values ("aaa", "bbb", "ccc")')
	sql3.execute('insert into t values ("AAA", "BBB", "CCC")')
	sql3.row_factory = sqlite3.Row
	rows = conn.cursor()
	rows.execute('select * from t')
	rlen=len(rows)
	j=0; k=0;
	for row in rows.fetchall():
		j=j+1
		print("{} {} -{}- BUGS_1540 sql3_factory {},{} rlen={} rows.description={} dict_row={} row={}" .format(progid,dttm,goflag,j,k, rlen, rows.description, dict(row), row))
	sql3.close()

# 	{'a': 'aaa', 'b': 'bbb', 'c': 'ccc'}
# 	{'a': 'AAA', 'b': 'BBB', 'c': 'CCC'}

#	sql3 = sqlite3.connect(":memory:")
	sql3 = sqlite3.connect(db3file)
	sql="select * from cfg"
#	sql3.execute(sql)
	sql3.row_factory = sqlite3.Row
	rows = sql3.cursor()
	rows.execute(sql)
	rlen=len(rows)
	sql3.row_factory = lambda c, r: dict([(col[0], r[idx]) for idx, col in enumerate(c.description)])


	return(items)



def db3s(fdir,filematch):
	j=0; k=0; i=0;
	print( "{} {} -{}- BUGS_1480 db3s {},{} db3={} tbl={} id={}\n".format(progid,dttm,goflag,j,k,db3,tbl,id,filematch))

	wlfile="ko_db3s.wl"; fdir="../ht"; type="f"; maxdepth="4"; fnam="*.db3";
	syscmd_db3s="find {} -type {} -maxdepth {} -name \"{}\" > {}".format(fdir,type,maxdepth,fnam,wlfile)
	(out,err)=kosys(syscmd_db3s,'');
	items=out.split("\n")
	ilen=len(items)
	for item in items:
		j=j+1
		print( "{} {} -{}- BUGS_1490 db3s {},{} ilen={} ITEM={} db3={} tbl={} id={}\n".format(progid,dttm,goflag,j,k,ilen,item,db3,tbl,id,filematch))

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

		if( goflag == "go" ):
			print( "{} {} -{}- BUGS_1490 db3s GO {},{} ilen={} ITEM={} db3={} tbl={} id={}\n".format(progid,dttm,goflag,j,k,ilen,item,db3,tbl,id,filematch))

	results="_results_db3s"
	return(results)


def wz(id,results,fmt,usrcmd):
	# wz.sh		20240215_2000
	dttm=kodts('')
	ofile="../ht/ko/wz.html"
	divids="new1 new2 new2 funtime kids kd_jenna kd_skwii kd_jkwii kd_usa kd_snowday kd_fans kd_players kd_stables kd_horses kd_cards kd_dice kd_trackline kd_tracoval kd_bugs kd_controls kd_toggles kd_tracker".split(" ")
	dhtml_divids_core="div_sailboat div_leds div_ledsover div_display div_bugs div_toggles div_controls"
	if( results != "" ): ofile=results
	if( id != "" ): divids=id.split(" ")
	print( "BUGS_185 wz id={} results={} fmt={} usrcmd={}\n" )
	
	
	# divids="kd_jkwii".split(" ")
	htmout=""; j=0; k=0;
	# ofile="wz_py.html"
	ofile="wz.html"
	
	gifs_psv="""
	/imgs/gif/orbs/balls3.gif
	/imgs/gif/orbs/balls4.gif
	/imgs/gif/orbs/ballsrainbow.gif
	/imgs/gif/orbs/cub1.gif
	/imgs/gif/orbs/dia3.gif
	/imgs/gif/orbs/diam1.gif
	/imgs/gif/orbs/godots.gif
	/imgs/gif/orbs/godotss.gif
	/imgs/gif/orbs/goripple.gif
	/imgs/gif/orbs/helix1.gif
	/imgs/gif/orbs/jellyfish.gif
	/imgs/gif/orbs/kali11.gif
	/imgs/gif/orbs/kali15.gif
	/imgs/gif/orbs/kali20.gif
	/imgs/gif/orbs/laki21.gif
	/imgs/gif/orbs/orb1.gif
	/imgs/gif/orbs/orb10.gif
	/imgs/gif/orbs/orb11.gif
	/imgs/gif/orbs/orb3.gif
	/imgs/gif/orbs/orb43.gif
	/imgs/gif/orbs/orb6.gif
	/imgs/gif/orbs/orb8.gif
	/imgs/gif/orbs/orbcryst_alpulse.gif
	/imgs/gif/orbs/orbdrip.gif
	/imgs/gif/orbs/orbrainbow.gif
	/imgs/gif/orbs/orbring.gif
	/imgs/gif/orbs/orbspiral.gif
	/imgs/gif/orbs/ringcube.gif
	/imgs/gif/orbs/rings.gif
	/imgs/gif/orbs/rings2.gif
	/imgs/gif/orbs/ringworm.gif
	/imgs/gif/orbs/rubix.gif
	/imgs/gif/orbs/soccorball.gif
	/imgs/gif/orbs/sprayfountain.gif
	/imgs/gif/orbs/sssfg.gif
	/imgs/gif/spacers/giphy_handkither.gif
	/imgs/gif/spacers/giphy_jkwii_head.gif
	/imgs/gif/spacers/giphy_jkwii_head2.gif
	/imgs/gif/spacers/giphy_spacer_01.gif
	/imgs/gif/spacers/giphy_spacer_02.gif
	/imgs/gif/spacers/giphy_spacer_03.gif
	/imgs/gif/spacers/giphy_spacer_04.gif
	/imgs/gif/spacers/giphy_spacer_05.gif
	/imgs/gif/spacers/giphy_spacer_07.gif
	/imgs/gif/spacers/giphy_spacer_08.gif
	/imgs/gif/spacers/giphy_spacer_09.gif
	/imgs/gif/spacers/giphy_spacer_10.gif
	/imgs/gif/spacers/giphy_spacer_11.gif
	/imgs/gif/spacers/giphy_spacer_12.gif
	/imgs/gif/spacers/giphy_spacer_13.gif
	/imgs/gif/spacers/giphy_spacer_15.gif
	/imgs/gif/spacers/giphy_spacer_17.gif
	/imgs/gif/spacers/giphy_spacer_19.gif
	/imgs/gif/spacers/giphy_spacer_20.gif
	/imgs/gif/spacers/giphy_spacer_21.gif
	/imgs/gif/spacers/giphy_spacer_22.gif
	/imgs/gif/spacers/tn/tn_giphy_handkither.gif
	/imgs/gif/spacers/tn/tn_giphy_jkwii_head.gif
	/imgs/gif/spacers/tn/tn_giphy_jkwii_head2.gif
	/imgs/gif/spacers/tn/tn_giphy_spacer_01.gif
	/imgs/gif/spacers/tn/tn_giphy_spacer_02.gif
	/imgs/gif/spacers/tn/tn_giphy_spacer_03.gif
	/imgs/gif/spacers/tn/tn_giphy_spacer_04.gif
	/imgs/gif/spacers/tn/tn_giphy_spacer_05.gif
	/imgs/gif/spacers/tn/tn_giphy_spacer_07.gif
	/imgs/gif/spacers/tn/tn_giphy_spacer_08.gif
	/imgs/gif/spacers/tn/tn_giphy_spacer_09.gif
	/imgs/gif/spacers/tn/tn_giphy_spacer_10.gif
	/imgs/gif/spacers/tn/tn_giphy_spacer_11.gif
	/imgs/gif/spacers/tn/tn_giphy_spacer_12.gif
	/imgs/gif/spacers/tn/tn_giphy_spacer_13.gif
	/imgs/gif/spacers/tn/tn_giphy_spacer_15.gif
	/imgs/gif/spacers/tn/tn_giphy_spacer_17.gif
	/imgs/gif/spacers/tn/tn_giphy_spacer_19.gif
	/imgs/gif/spacers/tn/tn_giphy_spacer_20.gif
	/imgs/gif/spacers/tn/tn_giphy_spacer_21.gif
	/imgs/gif/spacers/tn/tn_giphy_spacer_22.gif
	"""
	gifs=gifs_psv.split("\n")
	
	j=0;
	htmout+="<html><head><title>wx.html {}</title><head>\n".format(dttm)
	htmout+="<body bgcolor=linen>\n"
	htmout+="<script id=script_wz src=/js/wz/wz_dragdrop.js ></script>\n"
	
	for divid in divids:
		j=j+1 
		left=600; top=600; width=1100; height=800;
		x=left; y=top; w=width; h=height;
		dx=10*j; dy=1000*j; 
		x=x+dx; y=y+dy;
		src=gifs[j]
	
	
	#	htmout+="\n"
	#	htmout+="\n"
	#	htmout+="<!-- {}  {}  ================= HEAD ===================== {} END -->\n".format(divid,j,divid)
	#	htmout+="       <style id=\"style_div_{}\" > \n".format(divid)
	#	htmout+="                #div_{} {{ \n".format(divid)
	#	htmout+="                        position:absolute; \n"
	#	htmout+="                        left:{}px; top:{}px; width:{}px; height={}px; \n".format(x,y,w,h)
	#	htmout+="                        border:1px solid #000099; \n"
	#	htmout+="                        background:#eeeeee; \n"
	#	htmout+="                        layer-background-color:#eeeeee; \n"
	#	htmout+="                        overflow:hidden; \n"
	#	htmout+="//                      visibility:hidden; \n"
	#	htmout+="                        } \n"
	#	htmout+="                </style id=\"style_div_{}_end\" > \n".format(divid)
	#	htmout+="\n"
	#	htmout+="\n"	
	#	htmout+="\n"	
	
	
		x=100; y=50; h=50; w=100;
		dx=100; dy=100; dh=100; dw=100;
		x=x+dx*j; y=y+dy*j; h=h+dh*j; w=w+dw*j;
		htmout+= "<!-- {}  {} ================= HEAD ===================== {} END -->\n".format(divid,j,divid)
		htmout+= "       <style id=\"style_div_{}\" > \n".format(divid)
		htmout+= "                #div_{} {{ \n".format(divid)
	#	htmout+= "                        position:absolute; \n"
		htmout+= "                        position:relative; \n"
		htmout+= "                        left:{}px; top:{}px; width:{}px; height={}px; \n".format(x,y,w,h)
		htmout+= "                        border:1px solid #000099; \n"
		htmout+= "                        background:#eeeeee; \n"
		htmout+= "                        layer-background-color:#eeeeee; \n"
		htmout+= "                        overflow:hidden; \n"
		htmout+= "//                      visibility:hidden; \n"
		htmout+= "                        } \n"
		htmout+= "                </style id=\"style_div_{}_end\" > \n".format(divid)
	#	htmout+="	<div id=\"layer_{}\" >\n".format(divid)
	#	htmout+="		<h1>layer_{}</h1>\n".format(divid)
		htmout+="		<div id=\"div_{}\" >\n".format(divid)
		htmout+="			<h2>div_{}</h2>\n".format(divid)
		htmout+="			<div id=\"div_{}_body\" >\n".format(divid)
		src2="/imgs/btn/koeye.png"; w=100; h=20;
		htmout+="<img src={} title=\"          {}\" height={}px width={}px border=0>{}\n".format(src2,divid,h,w,divid)
	#	htmout+="<img src={} title=\"          {}  {}\"".format(src,divid,src)
	#	htmout+="  onclick=\"{}('{}'); return false;\" ".format(divid,divid)
	#	htmout+=" height={}px width={}px border=0>{}\n".format(h,w,divid)
		htmout+="				<h3>div_$divid</h3>\n".format(divid)
		htmout+="<img id=img_{} src={} title=\"          {}\"".format(divid,src,divid)
		htmout+=" onclick=\"{}('{}'); return false;\" ".format(divid,divid)
		htmout+=" height={}px width={}px border=0>{}\n".format(h,w,divid)
		htmout+="				</div id=\"div_{}_body_end\" >\n".format(divid)
		htmout+="			</div id=\"div_{}_end\" >\n".format(divid)
	#	htmout+="		</div id=\"layer_ko_{}_end\" >\n".format(divid)
		htmout+="<script id=script_{}>\n".format(divid)
		htmout+="	function {}(args) {{\n".format(divid)
		htmout+="		alert( \"BUGS_{} {} args=\"+args )\n".format(j,divid)
		htmout+="		return(args); \n"
		htmout+="		}\n"
		htmout+="	</script id=script_{}_end>\n".format(divid)
		htmout+="<!-- {}  {} ----------------- TAIL --------------------- {} END -->\n".format(divid,j,divid)
	htmout+="<script id=script_set_dhtml>\n"
	htmout+="SET_DHTML(\n"
	
	dhtml_divids_core="div_sailboat div_leds div_ledsover div_display div_bugs div_toggles div_controls"
	for dhtml_divid in dhtml_divids_core.split(" "):
		htmout+="\"div_{}\"+RESIZABLE+TRANSPARENT,\n".format(dhtml_divid)
	
	for divid in divids:
		htmout+="\"div_{}\"+RESIZABLE+TRANSPARENT,\n".format(divid)
	htmout+="\"div_kludge\"+RESIZABLE+TRANSPARENT\n"
	htmout+="	);\n"
	htmout+="	</script id=script_set_dhtml_end>\n"
	htmout+="	</body></html>\n"
						
	ofile="wz.html"
	ofp=open(ofile,"w")
	ofp.write(htmout)
	ofp.close()
	print( "{} {} vi {}".format(progid,dttm,ofile))
	print( "BUGS ofile={}".format(ofile))
	return(htmout)


def rx(db3,tbl,fsrcs,marks):
	results="_results_"; j=0; k=0; n=0; usrcmd=""; jj=0; kk=0;
	print( "BUGS_800 rx db3={} tbl={} fsrcs={} marks={}\n".format(db3,tbl,fsrcs,marks))
	if( not os.path.exists(db3)):
		print( "{} {} {},{} BUGS_810 rx NOTFOUND db3={} tbl={} fsrcs={} types={}\n".format(progid,dttm,j,k, db3))
		exit()

	sql_drop="drop table if exists {}".format(tbl)
	(tbl,cnt,schema) = sql3_executes(db3,sql_drop)

	sql_cr="create table if not exists {} as select * from items limit 0".format(tbl)
	(tbl,cnt,schema) = sql3_executes(db3,sql_cr)

	awkout="rx_awkout.psv"
	awkflds="nr|id|fsrc|linbeg|linend|mark|item|kludge"
	ofp=open(awkout,"w")
	ofp.write("{}\n".format(awkflds))
	ofp.close()
	linbeg=0; linend=99999; mark="_mark_"; headmark="_headmark_"; tailmark="_tailmark_"; linnum=0;

	for fsrc in fsrcs.split(" "):
		j=j+1; k=0;
		for mark in marks.split("\n"):
			k=k+1
			id=marks.split("|")[0].replace("\n","")
			headmark=marks.split("|")[1]
			tailmark=marks.split("|")[2]
			kludge=marks.split("|")[3]
			linbeg=0
			item="_item_"
			kludge="kludge_{}".format(j)
			print( "BUGS_830 id={} headmark={} tailmark={} kludge={}\n".format(id, headmark,tailmark,kludge))


			syscmd_awkout="awk '{{ print NR\"|\"$0 }}' {}".format(fsrc)
# syscmd_awkout="awk -v id=\"{}\" -v mark=\"{}\" '/mark/ && NR > linbeg && NR < linend {{ 
# print NR\"|\"id\"|\"fsrc\"|\"linbeg\"|\"linend\"|\"mark\"|\"$0\"|\"kludge }}' {} >> {}"
# .format(id,fsrc,linbeg,linend,mark,fsrc,awkout)

# 			syscmd_awkout="awk -v id=\"{}\" -v fsrc=\"{}\" -v linbeg=\"{}\" -v linend=\"{}\" -v mark=\"{}\" '/mark/ && NR > linbeg && NR < linend {{ print NR\"|\"id\"|\"fsrc\"|\"linbeg\"|\"linend\"|\"mark\"|\"$0\"|\"kludge }}' {} >> {}".format(id,fsrc,linbeg,linend,mark,fsrc,awkout)
			print( "{} {} {},{} BUGS_851 rx syscmd_awkout={}".format(progid,dttm,j,k,syscmd_awkout))
			if( a2 == "go" ) or ( a3 == "go" ) or ( a4 == "go" ):
				(out,err)=kosys(syscmd_awkout,'brief')
				print( "{} {} {},{} BUGS_842 rx out={} err={}\n".format(progid,dttm,j,k,out,err))

#			syscmd_awk="awk -v id=\"{}\" -v fsrc=\"{}\" -v linbeg=\"{}\" -v linend=\"{}\" -v mark=\"{}\" '/mark/ && NR > linbeg && NR < linend {{ print NR\"|\"id\"|\"fsrc\"|\"linbeg\"|\"linend\"|\"$0\"|\"kludge }}' {}".format(id,fsrc,linbeg,linend,mark,fsrc)
#			print( "BUGS_843 awkcmd={}\n".format(syscmd_awk))
			if( a2 == "go" ) or ( a3 == "go" ) or ( a4 == "go" ):
				(out,err)=kosys(syscmd_awkout,'brief')
				print( "{} {} {},{} BUGS_842 rx items={} err={}\n".format(progid,dttm,j,k,out,err))

			items=""
#			if( a2 == "go" ) or ( a3 == "go" ) or ( a4 == "go" ):
#				(items,err)=kosys(syscmd_awk,'brief')
#				print( "{} {} {},{} BUGS_852 rx items={} err\n".format(progid,dttm,j,k,items,err))

			n=0; sql_ins=""; 
#			awkflds="nr|id|fsrc|linbeg|linend|mark|item|kludge"
			if( not os.path.exists(awkout)):
				print( "{} {} {},{} BUGS_860 rx NOTFOUND awkout={}\n".format(progid,dttm,j,k,awkout))
				exit()

			ifp=open(awkout,"r")
			lines=ifp.readlines()
			j=0; k=0;
			for line in lines:
				j=j+1; k=0;
				nr=line.split("|")[0]
				id=line.split("|")[1]
				fsrc=line.split("|")[2]
				linbeg=line.split("|")[3]
				linend=line.split("|")[4]
				mark=line.split("|")[5]
				item=line.split("|")[6]
				kludge=line.split("|")[7]
#				linbeg=0; linend=99999; item="_item";kludge="_"; line="_line_"; 
#				print( "{} {} {},{} BUGS_861 rx line={}|{}|{}|{}|{}|{}|{}|{}\n" line={}\n".format(progid,dttm,j,k, nr,id,fsrc,linbeg,linend,mark,item,kludge,line))
				sql_ins="insert or replace into {} (id,fsrc,linbeg,headmark,item) values ('{}','{}','{}','{}','{}');".format(tbl,id,fsrc,linbeg,headmark,item)
				print( "{} {} {},{} BUGS_862 rx sql_ins={}\n".format(progid,dttm,j,k,sql_ins))
			
				if( a2 == "go" ) or ( a3 == "go" ) or ( a4 == "go" ):
					if( sql_ins != "" ):
						(tbl,cnt,schema) + sql3_executes(db3,sql_ins)
						print( "{} {} {},{} BUGS_863 rx sql3_execute id={} db3={} tbl={} fsrcs={} mark={} headmark={}\n".format(progid,dttm,j,k,id,db3,tbl,fsrc,mark,headmark))

			if( not re.search("^g",usrcmd)):
				print("e=exit q=quit s=skip enter=continue g=go: ")
#	 			usrcmd=raw_input("prompt:  " )
#				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("^\+", usrcmd)): 
					n=usrcmd.replace("+",""); 
					if( n == "" ): n=1 
					jj=j+n
					print( "BUGS_851 rx + {},{} {},{}\n".format(j,k,n,jj))
					continue
				if( re.search("^\-", usrcmd)): 
					n=usrcmd.replace("-",""); 
					if( n == "" ): n=1
					jj=j-n
					print( "BUGS_852 rx - {},{} {},{}\n".format(j,k,n,jj))
					continue
				if( re.search("^\:", usrcmd)): 
					n=usrcmd.replace(":","") 
					if( n == "" ): n=j
					jj=n
					print( "BUGS_853 rx : {},{} {},{}\n".format(j,k,n,jj))
					continue
				if( re.search("^\/", usrcmd)): 
					n=usrcmd.replace("/",""); 
					if( n == "" ): n=""
					jj=n
					print( "BUGS_854 rx / {},{} {},{}\n".format(j,k,n,jj))
					continue
				if( re.search("^.", usrcmd)): 
					n=usrcmd.replace(".",""); 
					if( n == "" ): n=j; 
					jj=n
					print( "BUGS_855 rx . {},{} {},{}\n".format(j,k,n,jj))
					continue
#				if( re.search("^s", usrcmd)): continue


				if( a2 == "go" ) or ( a3 == "go" ) or ( a4 == "go" ):
					print( "BUGS_230 ko_selects GO usrcmd={}".format(usrcmd))
					(tbl,cnt,schema) + sql3_executes(db3,sql_ins)
					print( "{} {} {},{} BUGS_820 rx sql3_execute id={} db3={} tbl={} fsrcs={} mark={} headmark={}\n".format(progid,dttm,j,k,id,db3,tbl,fsrc,mark,headmark))


			print( "{} {} {},{} BUGS_821 rs sql_ins={}\n".format(progid,dttm,j,k,sql_ins))

	return(results)

def ko_urllib(args):
	import urllib.request
	with urllib.request.urlopen('http://python.org/') as response:
		html = response.read()

	import shutil
	import tempfile
	import urllib.request

	with urllib.request.urlopen('http://python.org/') as response:
		with tempfile.NamedTemporaryFile(delete=False) as tmp_file:
			shutil.copyfileobj(response, tmp_file)

	with open(tmp_file.name) as html:
		pass


	req = urllib.request.Request('http://python.org/')
	with urllib.request.urlopen(req) as response:
		the_page = response.read()

	import urllib.parse
	import urllib.request

	url = 'http://www.someserver.com/cgi-bin/register.cgi'
	values = {'name' : 'Michael Foord',
	          'location' : 'Northampton',
	          'language' : 'Python' }

	data = urllib.parse.urlencode(values)
	data = data.encode('ascii') # data should be bytes
	req = urllib.request.Request(url, data)
	with urllib.request.urlopen(req) as response:
		the_page = response.read()

	import urllib.request
	import urllib.parse
	data = {}
	data['location'] = 'Northampton'
	data['language'] = 'Python'
	url_values = urllib.parse.urlencode(data)
	print(url_values)  # The order may differ from below.  
	name="Somebody+Here&language=Python&location=Northampton"
	url = 'http://www.example.com/example.cgi'
	full_url = url + '?' + url_values
	data = urllib.request.urlopen(full_url)
	
	req = urllib.request.Request('http://www.pretend_server.org')
	try: urllib.request.urlopen(req)
	except urllib.error.URLError as e:
		print(e.reason)      
#	(4, 'getaddrinfo failed')

	from urllib.request import Request, urlopen
	from urllib.error import URLError
	req = Request(someurl)
	try:
	    response = urlopen(req)
	except URLError as e:
	    if hasattr(e, 'reason'):
	        print('We failed to reach a server.')
	        print('Reason: ', e.reason)
	    elif hasattr(e, 'code'):
	        print('The server couldn\'t fulfill the request.')
	        print('Error code: ', e.code)
#	else:
# everything is fine
	




def http_errorcodes(args):
# Table mapping response codes to messages; entries have the
# form {code: (shortmessage, longmessage)}.
	responses = {
100: ('Continue', 'Request received, please continue'),
101: ('Switching Protocols', 'Switching to new protocol; obey Upgrade header'),
200: ('OK', 'Request fulfilled, document follows'),
201: ('Created', 'Document created, URL follows'),
202: ('Accepted', 'Request accepted, processing continues off-line'),
203: ('Non-Authoritative Information', 'Request fulfilled from cache'),
204: ('No Content', 'Request fulfilled, nothing follows'),
205: ('Reset Content', 'Clear input form for further input.'),
206: ('Partial Content', 'Partial content follows.'),
300: ('Multiple Choices', 'Object has several resources -- see URI list'),
301: ('Moved Permanently', 'Object moved permanently -- see URI list'),
302: ('Found', 'Object moved temporarily -- see URI list'),
303: ('See Other', 'Object moved -- see Method and URL list'),
304: ('Not Modified', 'Document has not changed since given time'),
305: ('Use Proxy', 'You must use proxy specified in Location to access this ' 'resource.'),
307: ('Temporary Redirect', 'Object moved temporarily -- see URI list'),
400: ('Bad Request', 'Bad request syntax or unsupported method'),
401: ('Unauthorized', 'No permission -- see authorization schemes'),
402: ('Payment Required', 'No payment -- see charging schemes'),
403: ('Forbidden', 'Request forbidden -- authorization will not help'),
404: ('Not Found', 'Nothing matches the given URI'),
405: ('Method Not Allowed', 'Specified method is invalid for this server.'),
406: ('Not Acceptable', 'URI not available in preferred format.'),
407: ('Proxy Authentication Required', 'You must authenticate with ' 'this proxy before proceeding.'),
408: ('Request Timeout', 'Request timed out; try again later.'),
409: ('Conflict', 'Request conflict.'), 
410: ('Gone', 'URI no longer exists and has been permanently removed.'),
411: ('Length Required', 'Client must specify Content-Length.'),
412: ('Precondition Failed', 'Precondition in headers is false.'),
413: ('Request Entity Too Large', 'Entity is too large.'),
414: ('Request-URI Too Long', 'URI is too long.'),
415: ('Unsupported Media Type', 'Entity body in unsupported format.'),
416: ('Requested Range Not Satisfiable', 'Cannot satisfy request range.'),
417: ('Expectation Failed', 'Expect condition could not be satisfied.'),
500: ('Internal Server Error', 'Server got itself in trouble'),
501: ('Not Implemented', 'Server does not support this operation'),
502: ('Bad Gateway', 'Invalid responses from another server/proxy.'),
503: ('Service Unavailable', 'The server cannot process the request due to a high load'),
504: ('Gateway Timeout', 'The gateway server did not receive a timely response'),
505: ('HTTP Version Not Supported', 'Cannot fulfill request.'),
    }





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))

db3fil="../ht/kumu/kumu.db3"
ids="ko1 ko2 konet iperms jkwii jtfdcr"

default_uidurls="""
zh|https://zerohedge.com
tgp|https://thegatewaypundent.com
dm|https://dailymail.uk
housatonic|https://sites.google.com/a/housatonic.com/home/research
duke|https://thedukereport.com
dm|https://dailymail.co.uk
"""

default_uidurls="""
housatonic|https://sites.google.com/a/housatonicits.com/home/
"""
# def bs(url,fmt,ofile,usrcmd):
def bs(uid,usrcmd):
	dttm=kodts('')
	dttm=kodts('kodt')
	kodt = kodts('kodt')
	dt=kodt.split("_")[0]
	tm=kodt.split("_")[1]
	bsfil="../ht/yt/txt/bs.csv"
	db3file="bs.db3"
	tblnam="bs"
	j=0; url="url"

#	bs; bs go; bs zh; bs zh go
#	if( re.search("^go",uid)):
#	if( re.match('go',uid) or re.match('',uid)):
	uidurls=""; j=0; k=0;

	print( "BUGS_100 uid={} usrcmd={}".format(uid,usrcmd))
	if( uid == "" ): 
		uid='all'
		uidurls=default_uidurls
	else:
		if( uid == "go" ): 
			uid='all'
			uidurls=default_uidurls
			usrcmd='go'
			print( "BUGS_102 j={} uid={} usrcmd={} uidurls={}".format(j,uid,usrcmd,uidurls))
		else:
			for uidurl in default_uidurls.split("\n"):
				j=j+1
				if ( re.match(uid, uidurl)):
					uidurls=uidurl
					break
			print( "BUGS_103 j={} uid={} uidurl={} usrcmd={}".format(j,uid,uidurl,usrcmd))
	if( usrcmd != "go" ):
		print( "BUGS_331 NOGO j={} uid={} usrcmd={} uidurls={}".format(j,uid,usrcmd,uidurls))
		exit()

	print( "BUGS_332 __GO j={} uid={} usrcmd={} uidurls={}".format(j,uid,usrcmd,uidurls))

#	for uidurl in uidurls.split("\n"):
#		if( len(uidurl.split("|")) < 2 ): continue
#		j=j+1
#		uid=uidurl.split("|")[0]
#		url=uidurl.split("|")[1]
#		print( "j={} uid={} url={}".format(j,uid,url))
#	exit()
	

	if not os.path.isfile(db3file):
		print("{} {} ERR_351: NOTFOUND db3file={}  ".format( progid,dttm,db3file))
		exit()

	sql_drop="drop table if exists {} ".format( tblnam )
	(tbl,cnt,schema) = sql3_executes(db3file, sql_drop)

	sql_create="create table if not exists {} ( dt varchar, tm varchar,status varchar, uid varchar, url varchar, title varchar, pdf varchar, descr varchar, unique(url))".format(tblnam)
	(tbl,cnt,schema) = sql3_executes(db3file, sql_create)

	j=0; k=0
	for uidurl in uidurls.split("\n"):
		if( len(uidurl.split("|")) < 2 ): continue
		uid=uidurl.split("|")[0]
		url=uidurl.split("|")[1]
		if( url == "" ): continue
		j=j+1
		content = requests.get(url).text
#		print( "BUGS_351 j={} url={} content={}".format(j,url,content))

		soup = BeautifulSoup(content, 'html.parser')

# print(soup.title)
		hrefs = [ element['href']
	        for element in soup.find_all('a') if 'href' in element.attrs ]
		print( "BUGS_352 j={} url={} hrefs={}".format(j,url,hrefs))
		for href in hrefs:
			k=k+1
			print( "BUGS_353 j={} k={} url={} href={}".format(j,k,url,href))


		
		exit()




#		srcs = [ element['src']
#	        for element in soup.find_all('img') if 'img' in element.attrs ]

# 		soup.find_all(re.compile("h[1-9]"))
# 		soup.find_all(re.compile("[ou]l"))

		print("BUGS_380 content={}".format(content))
		exit()

		kodt = kodts('kodt')
		dt=kodt.split("_")[0]
		tm=kodt.split("_")[1]
		status=""
		title="title"
		pdf=""
		descr="descr"

#		values="'2023-08-10','21:56','https://thegatewaypundit.com/article.html','thegatewaypundit','article','article_desc'"
		values="'{}','{}','{}','{}','{}','{}'".format(dt,tm,status,uid,url,title,pdf,descr)

		sql_insert="insert into {} values({})".format(tblnam,values)

#		sql_insert="insert into {} (dt,tm,url,site,title,descr) values ({}) where not exists (select url from {} where url='{}')".format( tblnam, values, tblnam, url )
##		sql_insert="insert into {} (dt,tm,url,site,title,descr) values ({}) if not exists (select url from {} where url='{}')".format( tblnam, values, tblnam, url )
##		sql_insert="insert into {} (dt,tm,url,site,title,descr) values ({}) WHERE not exists select url from {} where url='{}'".format( tblnam, values, tblnam, url )

	
#		print( "{} {} bs: url={} fmt={} ofile={} usrcmd={}".format(progid,dttm,url,fmt,ofile,usrcmd))
		print( "{} {} bs: url={}".format(progid,dttm,url))
		print( "{} {} bs: bsfil={}".format(progid,dttm,bsfil))
		print( "{} {} bs: db3file={}\n".format(progid,dttm,db3file))
		print( "{} {} bs: sql_create={}\n".format(progid,dttm,sql_create))
		print( "{} {} bs: sql_insert={}\n".format(progid,dttm,sql_insert))

#		(tbl,cnt,schema) = sql3_executes(db3file, sql_insert)

#		sql3_executes(db3file, sql_execute):
	exit()

db3fil_ru="kumu.db3"
tblnam_ru="ru"
rus="""
ko1|1000
ko2|1000
konet|1000
iperms|1000
jkwii|1000
jtfdcr|1000
"""

def ru(id,usrcmd):
	dttm=kodts('')
	dttm=kodts('kodt')
	kodt = kodts('kodt')
	dt=kodt.split("_")[0]
	tm=kodt.split("_")[1]
	db3file="kumu.db3"
	tblnam="ru"
	j=0; url="url"

	fmt="csv"

# https://randomuser.me/api/?results=10&format=json&seed=ko
	for ru in rus.split("\n"):
		if( len(ru.split("|")) < 2 ): continue
		j=j+1
		rid=ru.split("|")[0]
		results=ru.split("|")[1]
		url="https://randomuser.me/api/?results={}&format={}&seed={}".format(results,fmt,rid)
		csvfil="ru_{}.csv".format(rid)
		jsonfil="ru_{}.json".format(rid)
		print("j={} url={} csvfil={} json={}".format(j,url))
		print("j={} tblnam={} csvfil={} jsonfil={}".format(j,tblnam, csvfil, jsonfil))

	exit()
	


	sql_create_ru="""
CREATE TABLE ru(
  rid TEXT,
  label TEXT,
  type TEXT,
  gender TEXT,
  title TEXT,
  fname TEXT,
  lname_last TEXT,
  loc_str_number TEXT,
  loc_str_name TEXT,
  loc_city TEXT,
  loc_state TEXT,
  loc_country TEXT,
  loc_zip TEXT,
  loc_coord_lat TEXT,
  loc_coord_long TEXT,
  loc_timezone_offset TEXT,
  loc_timezone_descr TEXT,
  email TEXT,
  login_uuid TEXT,
  login_user TEXT,
  login_pass TEXT,
  login_salt TEXT,
  login_md5 TEXT,
  login_sha1 TEXT,
  login_sha256 TEXT,
  dob_date TEXT,
  dob_age TEXT,
  reg_dt TEXT,
  reg_age TEXT,
  phn TEXT,
  cell TEXT,
  id_name TEXT,
  id_val TEXT,
  pic_zn TEXT,
  pic TEXT,
  pic_tn TEXT,
  nat TEXT
);
"""
	print( "{} {} ru: id={} results={} fmt={} usrcmd={}".format(progid,dttm,id,results,fmt,usrcmd))
	print( "{} {} ru: ids={}".format(progid,dttm,ids))
	exit()

def ku(id,results,fmt,usrcmd):
	dttm=kodts('')
	print( "{} {} ku: id={} results={} fmt={} usrcmd={}".format(progid,dttm,id,results,fmt,usrcmd))
	print( "{} {} ku: ids={}".format(progid,dttm,ids))
	exit()


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={<5} pathfile={<10} tpathfile={<}".format(j,pathfile,tpathfile))
		j=j+1


def d2db3v(dtasrc,db3file,tbl,id,txtmode,usrcmd):
	progid="ko"
	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_2100 d2db3v {} {} dtasrc={} db3file={} tbl={} id={} usrcmd={}".format(progid,dttm,dtasrc,db3file,tbl,id,usrcmd)
	msg="BUGS_2101 d2db3v {} {} dtamode={} sql_select={}".format(progid,dttm,dtamode,sql_select)
	komsg(msgfil,msg,'')
	msg="BUGS_2102 d2db3v {} {} dtamode={} syscmd_find={}".format(progid,dttm,dtamode,syscmd_find)
	komsg(msgfil,msg,'')
	msg="BUGS_2103 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="ko"
	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_141 {} {} 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_142 {} {} 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_2050 syscmd_ffmpeg={}\n".format( progid, dttm, syscmd_ffmpeg ))
					print( "{} {} BUGS_2051 syscmd_jpg12png={}\n".format( progid, dttm, syscmd_jpg12png ))
					print( "{} {} BUGS_2052 syscmd_jpgs2gif={}\n".format( progid, dttm, syscmd_jpgs2gif ))
					print( "{} {} BUGS_2053 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(pathfile):
	import subprocess
	import re
	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]

		type="f"; maxdepth=1; name=file; wlfile="ko_find_{}.wl"
		syscmd_find="find {} -type {} -maxdepth {} -name \"{}\" > wlfile={}".format( path,type,maxdepth,name,wlfile )

		print( "{} {} {},{} BUGS_3140 ko_find pathfile={}\n".format(pathfile))
		print( "{} {} {},{} BUGS_3141 ko_find syscmd_find={}\n".format(syscmd_fine))
		if( goflag == "go" ):
			(out,err)=kosys(syscmd_find,'brief')
		results=ko_prompts(out)


#		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 ko_find0(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 ko_selects(db3file,sql_select,tbl,fld,val,rowid,limit):
#	print( "BUGS_3500 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 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 kolists(a1,a2):
	import subprocess
	import re
	j=0;k=0;htmout=""
	dttm=kodts('')
	db3file="./ko.db3"
	tbl="bs4"
#	files=os.system('find ./htm -type f -name "*.htm"')
#	(files,err)=kosys('find ./htm -type f -nane "*.htm"'.split(" ")[1],'')
	(files,err)=kosys('find ./htm -type f -name "*.htm"','')
	print( "BUGS_100 dttm={} j={} file={}\n".format(dttm,j,files))
	for file in files.decode().split("\n"):
		j=j+1
		print( "BUGS_101 j={} file={}\n".format(j,file))


	exit()
	fsrc="../ht/ko/kolists/kolists.htm"
	syscmd="sqlite3 {} \"select rowid,id,linbeg,linend from {}\"".format(db3,tbl)
	sql_select="select rowid,id,lenbeg,lenend from {}".format(tbl)
		
	sql3 = sqlite3.connect(db3file)
	sql3.row_factory = sqlite3.Row
	rows = sql3.cursor()
	rows.execute(sql_select)
	for row in rows:
		id=row['id']
		linbeg=row['linbeg']
		linend=row['linend']
		printf( "BUGS_3805 id={} lenbeg={} lenend={}".format( id, linbeg, linend ))
		data += row['pathfile']
	datalen=len(data)
	sql3.close()		
	printf( "BUGS_380r90 id={} lenbeg={} lenend={}".format( id, linbeg, linend ))
	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

	print( "BUGS_7426")
	lines = glob( pattern )
	print( "BUGS_7427 out={}".format(lines))
	j=0; k=0;
	llen=len(lines)
	for line in lines:
		j=j+1
		print( "BUGS_7530 {},{} llen={} line={}\n".format(j,k,llen,line))
#	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(lines)
	
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 help(args):
	global a0; global a1; global a2; global a3; global a4; global a5; global a6; global a7; global a8;
	global progid; global dttm; global j; global k;
	dttm=kodts('')
	j=0;k=0
	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( "{} {} -{}- BUGS_8410 help {},{} py ko.py ko_types <args>\n".format(progid,dttm,goflag,j,k ))
	print( "{} {} -{}- BUGS_8410 help {},{} py ko.py dict_factory <cursor, row >\n".format(progid,dttm,goflag,j,k ))
	print( "{} {} -{}- BUGS_8410 help {},{} py ko.py sql3_row2dict <row >\n".format(progid,dttm,goflag,j,k ))
	print( "{} {} -{}- BUGS_8410 help {},{} py ko.py sql3_data2dicts <db3file,sql >\n".format(progid,dttm,goflag,j,k ))
	print( "{} {} -{}- BUGS_8410 help {},{} py ko.py csvfil2dict <csvfil >\n".format(progid,dttm,goflag,j,k ))
	print( "{} {} -{}- BUGS_8410 help {},{} py ko.py csvtxt2dict <csv >\n".format(progid,dttm,goflag,j,k ))
	print( "{} {} -{}- BUGS_8410 help {},{} py ko.py sql3_rows2dicts <db3file,tbl,sql >\n".format(progid,dttm,goflag,j,k ))
	print( "{} {} -{}- BUGS_8410 help {},{} py ko.py dict2csv <mydict >\n".format(progid,dttm,goflag,j,k ))
	print( "{} {} -{}- BUGS_8410 help {},{} py ko.py bs4s1 <links,a2,a3,a4 >\n".format(progid,dttm,goflag,j,k ))
	print( "{} {} -{}- BUGS_8410 help {},{} py ko.py sql3_fldval <self,sql,parameter >\n".format(progid,dttm,goflag,j,k ))
	print( "{} {} -{}- BUGS_8410 help {},{} py ko.py sql3_factory <a1,a2,a3 >\n".format(progid,dttm,goflag,j,k ))

	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" ))

	print( progid, "bs <url> <fmt> <ofile> 		# beautiful soup" )
	print( progid, "ru <id> <results> <fmt> 	# randomuser" )
	print( progid, "ku <id> <results> <fmt> 	# kumu" )
	print( progid, "wz <id> <results> <fmt> 	# wz " )
	print( progid, "ko_finds <id> <results> <fmt> 	# wz " )
	print( progid, "ko_selects <id> <results> <fmt> 	# wz " )
	print( progid, "ko_finds <id> <results> <fmt> 	# wz " )
	print( progid, "ko_sels <id> <results> <fmt> 	# wz " )
	print( "\n" )
	print( progid, "kolists <id> <results> <fmt> 	# wz " )
	print( progid, "bs4 <id> <results> <fmt> 	# wz " )
	print( progid, "b64s <id> <results> <fmt> 	# wz " )
	print( "\n" )
	print( progid, "todos <id> <results> <fmt> 	# wz " )
	print( progid, "todo <id> <results> <fmt> 	# wz " )
	print( progid, "tododb <id> <results> <fmt> 	# wz " )
	print( progid, "todofs <id> <results> <fmt> 	# wz " )
	print( progid, "todotx <id> <results> <fmt> 	# wz " )
	print( progid, "awks <id> <results> <fmt> 	# wz " )
	print( progid, "csv2jsn <csvfil> <jsnfil>  	# wz " )
	print( progid, "jsn2csv <jsnfil> <csvfil> 	# wz " )
	print( progid, "fors <id> <results> <fmt> 	# wz " )
	print( "\n" )
	print( "{} {} {},{} HELP_8401 py {}.py ascii <linematch>\n".format(progid,dttm,j,k,progid))
	print( "{} {} {},{} HELP_8402 py {}.py dls <fdir> <filemask>	# downloads \n".format(progid,dttm,j,k,progid))
	print( "{} {} {},{} HELP_8403 py {}.py dlsmvs <fdir> <filemask>	# downloads moves\n".format(progid,dttm,j,k,progid))
	print( "{} {} {},{} HELP_8404 py {}.py dlsrms <fdir> <filemask>	# downloads remove\n".format(progid,dttm,j,k,progid))
	print( "{} {} {},{} HELP_8405 py {}.py rx <linematch>		# regular expressions\n".format(progid,dttm,j,k,progid))
	print( "{} {} {},{} HELP_8406 py {}.py db3s <fdir> <filemask>	# db3s walk\n".format(progid,dttm,j,k,progid))
	print( "{} {} {},{} HELP_8407 py {}.py bs4s <db3> <tbl> <id>	# beutifulsoup \n".format(progid,dttm,j,k,progid))
	print( "{} {} {},{} HELP_8408 py {}.py ko_dict <db3> <tbl> <id>	# ko_dict \n".format(progid,dttm,j,k,progid))
	print( "{} {} {},{} HELP_8409 py {}.py ko_dicts <db3> <tbl> <id>	# ko_dicts \n".format(progid,dttm,j,k,progid))
	print( "{} {} {},{} HELP_8410 py {}.py ko_find <db3> <tbl> <id>	# ko_dicts \n".format(progid,dttm,j,k,progid))
	print( "{} {} {},{} HELP_8411 py {}.py ko_glob <db3> <tbl> <id>	# ko_dicts \n".format(progid,dttm,j,k,progid))
	print( "{} {} {},{} HELP_8412 py {}.py ko_prompts <db3> <tbl> <id>	# ko_dicts \n".format(progid,dttm,j,k,progid))
	print( "{} {} {},{} HELP_8413 py {}.py ko_prompt <db3> <tbl> <id>	# ko_dicts \n".format(progid,dttm,j,k,progid))
	print( "{} {} {},{} HELP_8414 py {}.py sql3_factory <db3> <tbl> <id>	# ko_dicts \n".format(progid,dttm,j,k,progid))
	print( "{} {} {},{} HELP_8415 py {}.py sql3_factory <db3> <tbl> <id>	# ko_dicts \n".format(progid,dttm,j,k,progid))
	print( "\n" )
	print( progid, "md <datetag>  			# md " )
	print( progid, "vi <datetag>  			# vi " )
	print( progid, "mv <datetag> <go> 		# mv " )
	print( progid, "psv <datetag>  			# psv " )
	print( progid, "apps <datetag> 			# apps " )
	print( progid, "ifiles <url>  			# ifiles " )
	print( progid, "ff <urls>  			# firefox " )
	print( progid, "mov2mp4 <datetag> <go> 		# mov2mp4 " )
	print( progid, "items <datetag> <go> 		# items " )
	print( progid, "wl2pages <wl> <go>		# wl22pages " )
	print( progid, "awks <wl>  			# awks " )
	print( progid, "bs4s <wl>  			# bs4s " )
	print( "\n" )
	print( progid, "go0 <id> <results> <fmt> 	# go0 " )
	print( progid, "go1 <id> <results> <fmt> 	# go1 " )
	print( progid, "go2 <id> <results> <fmt> 	# go2 " )

	dttm=kodts('')
	print( "{} {} bdbdbdbdbdbdbdbdbd".format( progid, dttm ))
	exit()




def startup(args):
	global progid, dttm, usrcmd;
	global hostname; global goflag;
	global a0; global a1; global a3; global a4; global a5; global a6; global a7; global a8;
	progid = "ko"
	dttm=kodts('')
	j=0; k=0; usrcmd="";
	if( a1 == "go" ) or ( a2 == "go" ) or ( a3 == "go" ) or ( a4 == "go" ): goflag="go"



#	print( "{} {} -{}- {},{} ERR_7771 startup unsupported command usrcmd={} a1={} a2={} a3={} a4={}\n".format( progid,dttm,goflag,j,k,usrcmd,a1,a2,a3,a4))
#	print( "{} {} -{}- {},{} ERR_7772 startup unsupported command usrcmd={} argc={} args={}\n".format( progid,dttm,goflag,j,k,usrcmd,len(sys.argv),str(sys.argv)))


#	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():
	global a0; global a1; global a2; global a3; global a4; global a5; global a6; global a7; global a8;
	global progid; global dttm; global j; global k;


#	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 ): results=help('startup')
	dttm=kodts('')
	goflag=""
	for a in sys.argv:
		if( a == "go" ): goflag="go"; break;


	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( 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 == "ko_prompt" ):
		out=""; err=""; db3="urls.db3"; tbl="urls"; limit=10; results="_results_";
		sql="select * from {} limit {}".format(tbl,limit)
		print( "{} {} -{}- MSG_8420: commands {},{} db3={} sql={}".format(progid,dttm,goflag,j,k,db3,sql))
		results=ko_prompt(db3,sql)	
		print( "{} {} -{}- MSG_8420: commands {},{} db3={} sql={} results={} out={}".format(progid,dttm,goflag,j,k,db3,db3,sql,results))
		exit()

	if( a1 == "ko_prompts" ):
		out=""; err=""; db3="urls.db3"; tbl="urls"; limit=10; results="_results_";
		sql="select * from {} limit {}".format(tbl,limit)
		print( "{} {} -{}- MSG_8420: commands {},{} db3={} sql={}".format(progid,dttm,goflag,j,k,db3,sql))
		results=ko_prompts(db3,sql)	
		print( "{} {} -{}- MSG_8420: commands {},{} db3={} sql={} results={} out={}".format(progid,dttm,goflag,j,k,db3,db3,sql,results))
		exit()
		syscmd="ls -lat *.py"
		if( a2 != "" ): syscmd=a2
		(out,err)=kosys(syscmd,'')
		results=ko_prompts( syscmd, out )
		exit()

	if( a1 == "ko_dicts" ):
		pattern="../ht/*.db3"
		if( a2 != "" ): pattern=a2
		out=ko_dicts( pattern )
		print( progid,dttm, "MSG_8440: commands ko_dicts pattern={} out={}".format(progid,dttm,pattern,out))
		exit()

	if( a1 == "ko_dict" ):
		pattern="../ht/*.db3"
		if( a2 != "" ): pattern=a2
		out=ko_dicts( pattern )
		print( progid,dttm, "MSG_8440: commands ko_dict pattern={} out={}".format(progid,dttm,pattern,out))
		exit()

	if( a1 == "ko_find" ):
		pattern="../ht/*.db3"
		if( a2 != "" ): pattern=a2
		out=ko_find( pattern )
		print( progid,dttm, "MSG_8450: commands pattern={} out={}".format(progid,dttm,pattern,out))
		exit()

	if( a1 == "ko_glob" ):
		pattern="/Users/konet/Downloads/*.mp4"
		if( a2 != "" ): pattern=a2
		out=ko_glob( pattern )
		print( progid,dttm, "MSG_8450: startup pattern={} out={}".format(progid,dttm,pattern,out))
		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( a1 == "sql3_rows2dicts" ):
		(db3file,tbl,sql)=(a2,a3,a4)
		if( db3file == "" ): db3file="ko.db3"
		if( not os.path.exists(db3file)):
			print( "{} {} -{}- BUGS_9200 db3s {},{} NOTFOUND db3file={} tbl={} sql={}\n".format( progid,dttm,goflag,j,k, db3file, tbl, sql ))
			exit()

		if( tbl == "" ) and ( sql == "" ):
			print( "{} {} -{}- BUGS_9200 db3s {},{} db3file={} NOTFOUND tbl={} NOTFOUND sql={}\n".format( progid,dttm,goflag,j,k, db3file, tbl, sql ))
			exit()

		if( tbl == "" ): tbl="items"
		if( sql == "" ): sql="select * from {}".format(tbl)

		(csvdta,psvdta,jsndta,mydict)=sql3_rows2dicts(db3file,tbl,sql)
		print( "{} {} -{}- BUGS_9191 db3s {},{} db3file={} tbl={} sql={} csvdta={}\n".format( progid,dttm,goflag,j,k, db3file, tbl, sql, csvdta ))
		print( "{} {} -{}- BUGS_9192 db3s {},{} db3file={} tbl={} sql={} psvdta={}\n".format( progid,dttm,goflag,j,k, db3file, tbl, sql, psvdta ))
		print( "{} {} -{}- BUGS_9193 db3s {},{} db3file={} tbl={} sql={} jsndta={}\n".format( progid,dttm,goflag,j,k, db3file, tbl, sql, jsndta ))
		print( "{} {} -{}- BUGS_9194 db3s {},{} db3file={} tbl={} sql={} mydict={}\n".format( progid,dttm,goflag,j,k, db3file, tbl, sql, mydict ))
		exit()


	if( sys.argv[1] == "db3s" ):
		(to_db3file,to_tbl,db3s_todos) = (a2,a3,a4)
		to_db3file="ko.db3"
		usrcmd=""; ilen=0; item=""; 
		fdirs=". ./ht"
		print( "{} {} -{}- BUGS_8991 db3s {},{} a0={} a1={} a2={} a3={} a4={}\n".format( progid,dttm,goflag,j,k, a0, a1, a2, a3, a4 ))

		wlfile="ko_db3s.wl"; 
#		if( os.path.exists(wlfile)): 
#			print( "{} {} -{}- BUGS_9015 db3s {},{} os.remove wlfile={}\n".format( progid,dttm,goflag,j,k, wlfile ))
#			os.remove(wlfile)

		if( not os.path.exists(wlfile)):
			ofp=open(wlfile,"w") 
			ofp.write(""); 
			ofp.close(); 

			type="f"; maxdepth="5"; fnam="*.db3";
			for fdir in fdirs.split(" "):
				print( "{} {} -{}- BUGS_8992 db3s {},{} syscmd={} ilen={} items={}".format(progid,dttm,goflag,j,k, usrcmd, ilen, item))
				fdir="../ht"; fnam="*.db3"; type="f"; maxdepth="5";
#				syscmd="find {} -type {} -maxdepth {} -name \"{}\"".format(fdir,type,maxdepth,fnam)
				syscmd="find {} -type {} -maxdepth {} -name \"{}\" >> {}".format(fdir,type,maxdepth,fnam,wlfile)
				(out,err)=kosys(syscmd,'brief')
	
		if( not os.path.exists(wlfile)):
			print( "{} {} -{}- BUGS_9020 db3s {},{}  NOTFOUND wlfile={}\n".format(progid,dttm,goflag,j,k, wlfile))
			exit()	

#		syscmd_cat="cat {}".format(wlfile)
#		(out,err)=kosys(syscmd_cat,'')
#		items=out.decode().split("\n")
		ifp=open(wlfile,"r")
		lines=ifp.readlines()
		j=0; k=0; db3files=[];
		for line in lines:
			print( "BUGS_9030 {},{} line={}\n".format( j,k,line))
			if( re.search( '^#', line )): 
				print( "BUGS_951 {},{} SKIP_# line={}\n".format(j,k,line))
				continue
			if( line == "" ): 
				print( "BUGS_952 {},{} SKIP_BLANK line={}\n".format(j,k,line))
				continue;
			db3files.append(j)
#			db3files[j]=line.replace("\n","")
			db3files[j]=line.strip()
			j=j+1
		ifp.close()
		dlen=len(db3files)


#		j=1;
#		for db3file in db3files:
#			db3file.strip()
#			db3file.replace("\n","-")
#			print( "BUGS_9060 {},{} dlen={} db3file=>{}<=".format(j,k,dlen,db3file))
#			j=j+1
#		exit()

		for db3file in db3files:
			j=j+1; k=0;
	
			print( "{} {} -{}- BUGS_9060 db3s {},{} dlen={} db3file={}".format(progid,dttm,goflag,j,k, dlen, db3file))

#			syscmd_tables="sqlite3 {} \".tables\" | awk '{ print \$1}'".format(db3file)
#			wlfile="ko_db3s_tbls.wl"; tlen=0; tbls="_tbls_"; tbl="_tbl_"; out="_out_"; err="_err_";
#			syscmd_tables="sqlite3 {} \".tables\" | awk '{{ print $1 }}'".format(db3file)
#			syscmd_tables="sqlite3 {} \".tables\" | awk '{{ print $1 }}' > {}".format(db3file, wlfile)
#			syscmd_tables="sqlite3 {} \"select name from sqlite_master\" > {}".format(db3file, wlfile)
#			print( "BUGS_9050 tlen={} tbls={} out={} err={} syscmd_tables={}\n".format(tlen, tbls,out,err,syscmd_tables))
#			(out,err)=kosys(syscmd_tables,'')
#			tbls=[];
#			if( os.path.exists(wlfile)):
#				ifp=open(wlfile,"r")
#				tbls=ifp.readlines()
#				tbls=ifp.readlines()
#				ifp.close()
#
#			out="_out_"; err="_err_"; tbls="_tbls_"; tlen=0; 
#			tbls=out.decode().split("\n")
#			tlen=len(tbls)
#			print( "BUGS_9051 tlen={} tbls={} syscmd_tables={} out={} err={}\n".format(tlen, tbls,syscmd_tables,out,err))
#			tbls=out.decode().split("\n")
#			tlen=len(tbls)
#			print( "BUGS_9052 tlen={} tbls={}\n".format(tlen,tbls))
#			tbl="_tbl_"; cnt=0; flds="_flds_"; psvfil=db3file.replace(".db3",".psv");
#			print( "{} {} -{}- BUGS_9050 db3s {},{} psvfil={} syscmd_tables={} out={} tbl={} cnt={} psvfil={} flds={} db3file={} dlen={} tlen={}\n" .format(progid,dttm,goflag,j,k, psvfil,syscmd_tables, out, tbl,cnt,psvfil,flds,db3file,dlen,tlen))

			tbls=[]
			sql_tbls="select name from sqlite_master"
			sql3 = sqlite3.connect(db3file)
			sql3.row_factory = sqlite3.Row
			rows = sql3.cursor()
			rows.execute(sql_tbls)
			j=0; k=0; tblstr="";
			for row in rows: 
#				tblnam=row['name']
#				tblstr+="{}|".format(tblnam)
				tbl=row['name']
				tbl.strip()
				tbls.append(j)
				tbls[j]=tbl
				print( "BUGS_9100 {},{} tbl={}\n".format(j,k,tbl))
				j=j+1;
			sql3.close()

			tlen=len(tbls)
			print( "BUGS_9081 {},{} tlen={} tbls={}\n".format(j,k,tlen,tbls))
			for tbl in tbls:
				print( "{} {} -{}- BUGS_9090 {},{} tbl={} db3file={} tbl={}".format(progid,dttm,goflag,j,k,tbl,db3file,tbl))
				j=j+1; k=0;
				name=tbl
				if( name == "" ):
					print( "{} {} -{}- BUGS_9089 SKIP {},{} NAME={} db3file={} tbl={}".format(progid,dttm,goflag,j,k,name,db3file,tbl))
					continue
				print( "{} {} -{}- BUGS_9089 FOUND {},{} NAME={} db3file={} tbl={}".format(progid,dttm,goflag,j,k,name,db3file,tbl))

				flds=[]
				sql_flds="pragma table_info({})".format(tbl)
				print( "BUGS_9110 sql_flds={}\n".format(sql_flds))
				sql3 = sqlite3.connect(db3file)
				sql3.row_factory = sqlite3.Row
				rows = sql3.cursor()
				rows.execute(sql_flds)
				j=0;
			
				for row in rows: 
					print( "BUGS_9111 j={} row={}\n".format(j,row))
					fld=row['name']
					flds.append(j)
					flds[j]=fld 
					j=j+1;
				sql3.close()


				flen=len(flds)
				print( "BUGS_9120 flen={} flds={}".format(flen,flds))
#				cid|name|type|notnull|dflt_value|pk
#				fldpsv=" ".join(str(x) for x in flds)
				k=0;
				for fld in flds:
#					fldpsv="{}|".format(fld)
					print( "{} {} -{}- BUGS_9130 FOUND {},{} FLD={} db3file={} tbl={}".format(progid,dttm,goflag,j,k,fld,db3file,tbl))
					k=k+1

				sql_cnt="select count(*) cnt from {}".format(tbl)
				sql3 = sqlite3.connect(db3file)
				sql3.row_factory = sqlite3.Row
				rows = sql3.cursor()
				rows.execute(sql_cnt)
				i=0;
				for row in rows:
#					tblcnt=row['cnt']
					tblcnt=row[i]
					print( "{} {} -{}- BUGS_9161 {},{} tblcnt={} row={}\n".format(progid,dttm,goflag,j,k,tblcnt,row))
					i=i+1
				sql3.close()
				print( "{} {} -{}- BUGS_9162 {},{} tblcnt={} row={}\n".format(progid,dttm,goflag,j,k,tblcnt,row))
				fldpsv=' '.join(flds)
			
				dttm=kodts(''); cnt="_cnt_"; ttbl="db3s"
				sql_insert="insert into {} (tbl,flds,tblcnt,dttm) values ('{}','{}','{}','{}');".format(ttbl,tbl,fldpsv,cnt,dttm)
				print( "{} {} -{}- BUGS_9115 {},{} sql_insert={} tblcnt={}\n".format(progid,dttm,goflag,j,k,sql_insert,tblcnt))
				results=sql3_executes(to_db3file,sql_insert)
			exit()


			for tbl in tbls:
				dttm=kodts('')
				k=k+1
				if( tbl == "" ): 
					print( "{} {} -{}- BUGS_9061 db3s {},{} NOTFOUND tbl={} cnt={} psvfil={} flds={} db3file={} dlen={} tlen={}\n" .format(progid,dttm,goflag,j,k, tbl,cnt,psvfil,flds,db3file,dlen,tlen))
					continue
				psvfil=tbl.replace("$",".psv")

# 				syscmd_flds="sqlite3 {} -header \"pragma table_info({})\"".format(db3file,tbl)

				syscmd_flds="sqlite3 {} -header \"select * from {} limit 1\" | head -1".format(db3file,tbl)
				(flds,err)=kosys(syscmd_flds,'')	
				print( "{} {} -{}- BUGS_9065 db3s {},{} syscmd_flds={} tbl={} cnt={} psvfil={} flds={} db3file={} dlen={} tlen={}\n" .format(progid,dttm,goflag,j,k, syscmd_flds,tbl,cnt,psvfil,flds,db3file,dlen,tlen))

				syscmd_cnt="sqlite3 {} \"select count(*) cnt from {}\"\n".format(db3file,tbl)
				(cnt,err)=kosys(syscmd_cnt,'')
				print( "{} {} -{}- BUGS_9061 db3s {},{} syscmd_cnt={} db3file={} dlen={} tlen={} tbl={} cnt={} flds={} psvfil={}".format(progid,dttm,goflag,j,k,dlen,tlen,syscmd_cnt,db3file,tbl,cnt,flds, psvfil))

#				print( "{} {} -{}- BUGS_9062 db3s {},{} db3file={} dlen={} tlen={} tbl={} cnt={} flds={} psvfil={}".format(progid,dttm,goflag,j,k,dlen,tlen,db3file,tbl,cnt,flds, psvfil))

				syscmd_psv="sqlite3 {} -header \"select * from {}\" > {}".format(db3file,tbl,psvfil)
				print( "{} {} -{}- BUGS_9062 db3s {},{} db3file={} dlen={} tlen={} tbl={} cnt={} flds={} syscmd_psv={}".format(progid,dttm,goflag,j,k,dlen,tlen,db3file,tbl,cnt,flds, syscmd_psv))
				sql="insert or replace into {} (db3,tbl,flds,tblcnt,dttm) values ('{}','{}','{}','{}','{}');".format(tbl,db3file,tbl,flds,tblcnt,dttm)
				print( "{} {} -{}- BUGS_9063 db3s {},{} db3file={} dlen={} tlen={} tbl={} cnt={} flds={} sql={}".format(progid,dttm,goflag,j,k,dlen,tlen,db3file,tbl,cnt,flds, sql))

				results=sql_executes(to_db3file,sql);


		if( not os.path.exists(wlfile)):
			print( "{} {} -{}- BUGS_9020 db3s {},{} NOTFOUND wlfile={}".format(progid,dttm,goflag,j,k,wlfile))
			exit();


		print( "BUGS_9074 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] == "beautifulsoup" ) or ( sys.argv[1] == "bs" ):
		(uid,usrcmd) = (a2,a3)
#		print( "BUGS_6110 bs db3file={} dtasrc={} tbl={} id={} usrcmd={}". format(db3file,dtasrc,tbl,id,usrcmd))
		status=bs(uid,usrcmd)
		exit()

	if( sys.argv[1] == "randomuser" ) or ( sys.argv[1] == "ru" ):
		(id,usrcmd) = (a2,a3)
#		print( "BUGS_6120 ru id={} results={} fmt={} usrcmd={}". format(id,results,fmt,usrcmd))
		status=ru(id,usrcmd)
		exit()

	if( sys.argv[1] == "kumu" ) or ( sys.argv[1] == "ku" ):
		(id,results,fmt,usrcmd) = (a2,a3,a4,a5)
#		print( "BUGS_6130 ku id={} results={} fmt={} usrcmd={}". format(id,results,fmt,usrcmd))
		status=ku(id,results,fmt,usrcmd)
		exit()

	if( sys.argv[1] == "wz" ) or ( sys.argv[1] == "wz" ):
		(id,results,fmt,usrcmd) = (a2,a3,a4,a5)
#		print( "BUGS_6130 wz id={} results={} fmt={} usrcmd={}". format(id,results,fmt,usrcmd))
		status=wz(id,results,fmt,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_finds" ):
		out=ko_finds( a1, a2 )
		print( progid,dttm, "MSG: ko_finds out=", out)
		exit()

	if( sys.argv[1] == "ko_sels" ):
		db3=a1; tbl=a2; sql=a3
		out=ko_sels( db3,tbl,sql )
		print( progid,dttm, "MSG: ko_selects out=", out)
		exit()


	if( sys.argv[1] == "go0" ):
		db3=a1; tbl=a2; sql=a3
		out=go0( db3,tbl,sql )
		print( progid,dttm, "MSG_100: GO0 out=", out)
		exit()

	if( sys.argv[1] == "go1" ):
		db3=a1; tbl=a2; sql=a3
		out=go1( db3,tbl,sql )
		print( progid,dttm, "MSG_101: GO1 out=", out)
		exit()

	if( sys.argv[1] == "go2" ):
		db3=a1; tbl=a2; sql=a3
		out=go2( db3,tbl,sql )
		print( progid,dttm, "MSG_102: GO2 out=", out)
		exit()

	if( sys.argv[1] == "kolists" ):
		print( "BUGS_300 kolists\n" )
#		out=go( sys.argv[2], sys.argv[3] )
		out=kolists( sys.argv[2], sys.argv[3] )
		print( progid,dttm, "MSG: startup kolists out=", out)
		exit()

	if( sys.argv[1] == "bs4" ):
		db3=a1; tbl=a2; sql=a3
		out=bs4( db3,tbl,sql )
		print( progid,dttm, "MSG_303: BS4 out=", out)
		exit()

	if( sys.argv[1] == "b64s" ):
		db3=a1; tbl=a2; sql=a3
		out=b64s( db3,tbl,sql )
		print( progid,dttm, "MSG_203: B64S out=", out)
		exit()


	if( sys.argv[1] == "todos" ):
		db3=a1; tbl=a2; sql=a3
		out=todos( db3,tbl,sql )
		print( progid,dttm, "MSG_203: TODOS out=", out)
		exit()

	if( sys.argv[1] == "todo" ):
		db3=a1; tbl=a2; sql=a3
		out=todo( db3,tbl,sql )
		print( progid,dttm, "MSG_204: TODO out=", out)
		exit()

	if( sys.argv[1] == "tododb" ):
		db3=a1; tbl=a2; sql=a3
		out=tododb( db3,tbl,sql )
		print( progid,dttm, "MSG_205: TODODB out=", out)
		exit()

	if( sys.argv[1] == "todofs" ):
		db3=a1; tbl=a2; sql=a3
		out=todofs( db3,tbl,sql )
		print( progid,dttm, "MSG_206: TODOFS out=", out)
		exit()

	if( sys.argv[1] == "todotx" ):
		db3=a1; tbl=a2; sql=a3
		out=todotx( db3,tbl,sql )
		print( progid,dttm, "MSG_207: TODOTX out=", out)
		exit()

	if( sys.argv[1] == "awks" ):
		db3=a1; tbl=a2; sql=a3
		out=awks( db3,tbl,sql )
		print( progid,dttm, "MSG_208: AWKS out=", out)
		exit()

	if( sys.argv[1] == "csv2jsn" ):
		csvfil=a1; jsnfil=a2;
		out=csv2jsn( csvfil,jsnfil )
		print( progid,dttm, "MSG_211: AWKS csvfil={} jsnfil={} out={}".format(csvfil,jsnfil,out))
		exit()

	if( sys.argv[1] == "jsn2csv" ):
		jsnfil=a1; csvfil=a2; 
		out=jsn2csv( jsnfil,csvfil )
		print( progid,dttm, "MSG_212: AWKS jsnfil={} csvfil={} out={}".format(jsnfil,csvfil,out))
		exit()

	if( sys.argv[1] == "fors" ):
		db3=a1; tbl=a2; sql=a3
		out=fors( db3,tbl,sql )
		print( progid,dttm, "MSG_209: FORS out=", out)
		exit()


	if( sys.argv[1] == "wz" ):
		out=wz( a1, a2 )
		print( progid,dttm, "MSG: wz 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] == "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]
		results=jkwii(usid,grp)
		exit()

	if( a1 == "ko_types" ):
		args=a2
		results=ko_types(args)
		print( "{} {} -{}- BUGS_171 commands ko_types {},{} args={} results={}".format( progid,dttm,goflag,j,k,args,results))
		return(results)

	if( a1 == "sql3_row2dict" ):
		row=a2
		results=sql3_row2dict(row)
		print( "{} {} -{}- BUGS_173 commands sql3_row2dict {},{} row={} results={}".format( progid,dttm,goflag,j,k,row,results))
		return(results)

	if( a1 == "sql3_data2dicts" ):
		db3file=a2; sql=a3;
		results=sql3_data2dicts(db3file,sql)
		print( "{} {} -{}- BUGS_174 commands sql3_data2dicts {},{} db3file={} sql={} results={}".format( progid,dttm,goflag,j,k,db3file,sql,results))
		return(results)

	if( a1 == "csvfil2dict" ):
		csvfil=a2;
		results=csvfil2dict(csvfil)
		print( "{} {} -{}- BUGS_175 commands csvfil2dict {},{} csvfil={} results={}".format( progid,dttm,goflag,j,k,csvfil,results))
		return(results)

	if( a1 == "csvtxt2dict" ):
		csv=a2;
		results=csvtxt2dict(csv)
		print( "{} {} -{}- BUGS_176 commands csvtxt2dict {},{} csv={} results={}".format( progid,dttm,goflag,j,k,csv,results))
		return(results)

	if( a1 == "dict2csv" ):
		mydict=a2
		results=dict2csv(mydict)
		print( "{} {} -{}- BUGS_178 commands dict2csv {},{} mydict={} results={}".format( progid,dttm,goflag,j,k,mydict,results))
		return(results)

	if( a1 == "bs4s_find" ):
		links=a2
		results=bs4s_find(links,a3,a4,a5)
		print( "{} {} -{}- BUGS_179 commands bs4s_find {},{} links={} a3={} a4={} a5={} results={}".format( progid,dttm,goflag,j,k,links,a3,a4,a5,results))
		return(results)

	if( a1 == "sql3_fldval" ):
		sql=a2; parameter=a3
		results=sql3_fldval(self,sql,parameter)
		print( "{} {} -{}- BUGS_180 commands sql3_fldval {},{} sql={} parameter={} results={}".format( progid,dttm,goflag,j,k,sql, parameter,results))
		return(results)

	if( a1 == "ascii" ):
		linematch=""; 
		if( a2 != "" ): linematch=a2
		print( "{} {} {},{} BUGS_8811 commands dls linematch={}\n".format(progid,dttm,j,k, linematch))
		results=ascii(linematch)
		print( "{} {} {},{} BUGS_8812 commands dls results={}\n".format(progid,dttm,j,k, results ))
		exit()


	if( a1 == "urls" ):
		datetag=kodts('').split("_")[0]
		if ( a2 != "" ): datetag=a2
		fdir="../ht/yt/txt"; fnams="*.psv"; 
		urlsflds="id|grp|dttm|url|txt|basename"
		results=urls(datetag)
		print( "{} {} {},{} BUGS_8832 commands dls results={}\n".format(progid,dttm,j,k, results ))


	if( a1 == "dls" ):
		datetag=kodts('').split("_")[0]
		if ( a2 != "" ): datetag=a2
		fdir="/Users/konet/Downloads"; fnams="*.mp4"; 
		tdir_mp4="../ht/kb/mp4/mp4_{}".format(datetag)
		tdir_mp3="../ht/kb/mp3/mp3_{}".format(datetag)
		psvdir="../ht/yt/txt"; psvnams="ytlist_{}.psv".format(datetag)
			

		if( a2 != "" ): psvmask=a2
		if( a3 != "" ): itemmask=a2
		print( "{} {} {},{} BUGS_4211 commands dls psvmask={} itemmask={}\n".format(progid,dttm,j,k, psvmask, itemmask))
		results=dls(fdir,fnams,tdir_mp4,tdir_mp3,psvdir,datetag)

		print( "{} {} {},{} BUGS_4312 commands dls results={}\n".format(progid,dttm,j,k, results ))
		exit()


	if( sys.argv[1] == "dlscps" ):
		fdir="/Users/konet/Downloads"; filemask="*.mp4"; datetag=kodts('').split("_")[0]
		if( a2 != "" ): fdir=a2
		if( a3 != "" ): datetag=a2
		tdir_mp4="../ht/kb/mp4/mp4_{}".format(datetag)
		tdir_mp3="../ht/kb/mp4/mp3_{}".format(datetag)
		print( "{} {} {},{} BUGS_4221 commands dlscps fdir={} filemask={}\n".format(progid,dttm,j,k, fdir, filemask))
		results=dlscps(fdir,datetag)
		print( "{} {} {},{} BUGS_4322 commands dlscps results={}\n".format(progid,dttm,j,k, results ))
		exit()


	if( sys.argv[1] == "dlsrms" ):
		fdir="/Users/konet/Downloads"; filemask="*.mp4";
		if( a2 != "" ): fdir=a2
		if( a3 != "" ): filemask=a2
		print( "{} {} {},{} BUGS_4231 commands dlsrms fdir={} filemask={}\n".format(progid,dttm,j,k, fdir, filemask))
		results=dlsrms(fdir,filemask)
		print( "{} {} {},{} BUGS_4332 commands dlsrms results={}\n".format(progid,dttm,j,k, results ))
		exit()

	if( a1 == "sql3_factory" ):
		results=sql3_factory(a1,a2,c3)
		exit()

	if( a1 == "md" ):
		datetag=a2
		if( datetag == "" ): datetag=kodts('yyyymmdd')
		if( datetag == "go" ): datetag=kodts('yyyymmdd')

		wlfile="../ht/yt/txt/ytlist_{}.txt".format(datetag)
		wldata="# {} bitcoin=$ gold=$ silver=$ eth=$\n\n".format(datetag);
		wljkmed_acyclovir="# jkmed-{}-0600-acyclovir\n".format(datetag);
		wljkmed_h2o="# jkmed-{}-0600-h2o-16oz\n".format(datetag);
		wljkmed_heart="# jkmed-{}-0600-heart-104/67-71\n\n".format(datetag);

#		printf( "BUGS1 md wlfile={} wldata={}\n".format(wlfile,wldata))
		print( "BUGS2 md wlfile={} wldata={}\n".format(wlfile,wldata))
		print( "BUGS2 md wlfile={} wljkmed_heart={}\n".format(wlfile,wljkmed_heart))
		wl = open( wlfile, "a")
		wl.write(wldata)
		wl.write(wljkmed_acyclovir)
		wl.write(wljkmed_h2o)
		wl.write(wljkmed_heart)
		wl.close()

		results=md(datetag)
		print( "{} {} {},{} BUGS_10121 commands md datetag={}\n".format(progid,dttm,j,k, datetag ))
		exit()

	if( a1 == "vi" ):
		datetag=a2
		if( datetag == "" ): datetag=kodts('yyyymmdd')
		results=vi(datetag)
#		print( "{} {} {},{} BUGS_10122 commands vi datetag={}\n".format(progid,dttm,j,k, datetag ))
		exit()

	if( a1 == "mv" ):
		datetag=a2
		if( datetag == "" ): datetag=kodts('yyyymmdd')
		if( datetag == "go" ): datetag=kodts('yyyymmdd')
		results=mv(datetag)
		print( "{} {} {},{} BUGS_10123 commands mv datetag={}\n".format(progid,dttm,j,k, datetag ))
		exit()

	if( a1 == "psv" ):
		datetag=a2
		if( datetag == "" ): datetag=kodts('yyyymmdd')
		if( datetag == "go" ): datetag=kodts('yyyymmdd')
		results=psv(datetag)
		print( "{} {} {},{} BUGS_10124 commands psv datetag={}\n".format(progid,dttm,j,k, datetag ))
		exit()

	if( a1 == "apps" ):
		id=a2
		results=apps(id)
		print( "{} {} {},{} BUGS_10190 commands apps id={}\n".format(progid,dttm,j,k, id ))
		exit()

	if( a1 == "ifiles" ):
		url=a2
#		if( url == "" ): url="10.5.50.4"
		if( url == "" ): url="http://ka12/ifiles.html"
		results=ifiles(url)
		print( "{} {} {},{} BUGS_10190 commands ifiles url={}\n".format(progid,dttm,j,k, url ))
		exit()

	if( a1 == "ff" ):
		url=a2
#		if( url == "" ): url="10.5.50.4"
		if( url == "" ): url="http://ka12/ifiles.html"
		results=ff(urls)
		print( "{} {} {},{} BUGS_10190 commands ff url={}\n".format(progid,dttm,j,k, url ))
		exit()

	if( a1 == "items" ):
		datetag=a2
		if( datetag == "" ): datetag=kodts('yyyymmdd')
		if( datetag == "go" ): datetag=kodts('yyyymmdd')
		datetag="20240418"
		results=items(datetag)
		print( "{} {} {},{} BUGS_11350 commands items datetag={}\n".format(progid,dttm,j,k, datetag ))
		exit()

	if( a1 == "mov2mp4" ):
		datetag=a2
		if( datetag == "" ): datetag=kodts('yyyymmdd')
		if( datetag == "go" ): datetag=kodts('yyyymmdd')
		results=mov2mp4(datetag)
		print( "{} {} {},{} BUGS_10390 commands mov2mp4 datetag={}\n".format(progid,dttm,j,k, datetag ))
		exit()

	if( a1 == "wl2pages" ):
		wl=a2
		results=wl2pages(wl)
		print( "{} {} {},{} BUGS_10490 commands wl2pages wl={}\n".format(progid,dttm,j,k, wl ))
		exit()

	if( sys.argv[1] == "db3s" ):
		psvmask="20240303"; linemask="youtube";
		if( a2 != "" ): fdir=a2
		if( a3 != "" ): filmask=a3
		print( "{} {} {},{} BUGS_4201 commands db3s fdir={} filemask={}\n".format(progid,dttm,j,k, fdir, filemask))
		results=db3s(fdir,filemask)
		print( "{} {} {},{} BUGS_4302 commands db3s results={}\n".format(progid,dttm,j,k, results ))
		exit()


	if( sys.argv[1] == "awks" ):
		db3="ko.db3"; tbl="bs4s"; id="id";
		if( a2 != "" ): db3=a2; 
		if( a3 != "" ): tbl=a3; 
		if( a4 != "" ): id=a4;
		print( "{} {} {} -{}- BUGS_11011 commands awks {},{} db3={} tbl={} id={}\n".format(hostname,progid,dttm,goflag,j,k, db3,tbl,id))
		results=awks(db3,tbl,id)
		print( "{} {} {} -{}- BUGS_11012 commands awks {},{} db3={} tbl={} id={}\n".format(hostname,progid,dttm,goflag,j,k, db3,tbl,id))
		exit()

	if( sys.argv[1] == "bs4s" ):
		db3="ko.db3"; tbl="bs4s"; id="id";
		if( a2 != "" ): db3=a2; 
		if( a3 != "" ): tbl=a3; 
		if( a4 != "" ): id=a4;
		print( "{} {} {} -{}- BUGS_11021 commands bs4s {},{} db3={} tbl={} id={}\n".format(hostname,progid,dttm,goflag,j,k, db3,tbl,id))
		results=bs4s(db3,tbl,id)
		print( "{} {} {} -{}- BUGS_11022 commands bs4s {},{} db3={} tbl={} id={}\n".format(hostname,progid,dttm,goflag,j,k, db3,tbl,id))
		exit()




	print( sys.argv[1])
	if re.match( sys.argv[1], 'help' ): print( progid, "MSG: help")

	usrcmd=a1
	print( "{} {} {},{} ERR_8900 commands a1={} a2={} a3={} a4={} pqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpq\n".format(progid,dttm,j,k,a1,a2,a3,a4 ))
	print( "{} {} {},{} ERR_8900 commands unsupported command usrcmd={} a1={} a2={} a3={} a4={} pqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpq\n".format(progid,dttm,j,k,usrcmd,a1,a2,a3,a4 ))
	print( "{} {} {},{} ERR_8900 commands a1={} a2={} a3={} a4={} bdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbd\n".format(progid,dttm,j,k,a1,a2,a3,a4 ))
	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('main')
	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