# Python Script for CTerm 3.2
# 把指定文件夹下的所有 TXT 文件自动连续发表
# 先把所有".txt"文件存放在某文件夹下，然后在此脚本文件中设定文件夹名。
# Nullspace, Batli. 在SMTH、BYHH上测试通过

import CTerm
import tools
import sys, string, random, glob, os

ID=long(sys.argv[0])
#print "sessionID is %s"%ID

random.seed()
os.chdir(r'd:\test')			# 此处设定文件夹名！
filenames = glob.glob(r'*.*')
#filenames.extend(  )
for n in filenames:
	print n
	if len(n)>=5 and n[0:5]=='album':
		continue
	if n[-4:len(n)]!='.txt':
		continue
	f=file(n, 'r')
	title=f.readline()
	title=title.strip()
	while title and title.strip()=='':
		title=f.readline()
		title=title.strip()
	if not title:
		continue
	content=f.read()
	
	if not title or not content:
		continue

	data=['\x10', title, '\n', '\n', content, '\x17']

	for item in data:
		SendString(ID, item)
		if dataEvents.has_key(ID):
			dataEvents[ID].wait()
	SendString(ID, '\n')
	WaitFor(ID, SST_LIST)

	interval=random.random()*7+3
	#print interval
	time.sleep(interval)
