コード例 #1
0
ファイル: system.py プロジェクト: mytbk/fqterm
def autoReply(lp):
	reply = "I am the auto replier, please wait..."
	reply_key = fqterm.getReplyKey(lp)
	if(reply_key==''):
		fqterm.sendParsedString(lp,"^Z")
	else:
		fqterm.sendParsedString(lp,reply_key)
	fqterm.sendString(lp,reply)
	fqterm.sendParsedString(lp,"^M")
コード例 #2
0
def autoReply(lp):
    reply = "I am the auto replier, please wait..."
    reply_key = fqterm.getReplyKey(lp)
    if (reply_key == ''):
        fqterm.sendParsedString(lp, "^Z")
    else:
        fqterm.sendParsedString(lp, reply_key)
    fqterm.sendString(lp, reply)
    fqterm.sendParsedString(lp, "^M")
コード例 #3
0
def down_folder():
    global path
    first_num = -1
    while (1):
        line = fqterm.caretY(lp)
        str_line = fqterm.getText(lp, line)

        article_num = get_list_num(str_line)
        if (first_num == -1):
            first_num = article_num
        if (article_num == None):
            print "Wrong format list"
            # end the index.html
            f = open(path + "index.html", "a+")
            write_index_footer(f)
            f.close()
            # wrong formatted list, leave out
            print "leave %s" % path
            fqterm.sendString(lp, 'q')
            path = upper_dir(path)
            time.sleep(wait_time)
            return

        article_categary = get_list_categary(str_line)
        article_title = get_list_title(str_line)

        # download if its file
        if article_categary == '[文件]':
            # log in index.html
            f = open(path + "index.html", "a+")
            f.write("<p><a href=" + article_num + ".html>")
            f.write("[文件] " + article_title + "</a></p>\n")
            f.close()
            # downlaod and save article
            f = open(path + article_num + ".html", "w")
            fqterm.sendString(lp, 'r')
            time.sleep(wait_time)
            write_html_header(f, int(article_num))
            f.write(txt2html(fqterm.getArticle(lp, 100)[0]))
            f.write("\n")
            write_html_footer(f, int(article_num))
            f.close()
            time.sleep(wait_time)
            fqterm.sendString(lp, "q")
            time.sleep(wait_time)
        # recursive callback if its directory
        elif article_categary == '[目录]':
            # log in index.html
            f = open(path + "index.html", "a+")
            f.write("<p><a href=" + article_num + "/index.html>")
            f.write("[目录] " + article_title + "</a></p>\n")
            f.close()
            # make dir and enter
            path = lower_dir(path, article_num)
            os.mkdir(path)
            print "enter %s" % path
            # create index.html and write the header
            f = open(path + "index.html", "w")
            write_index_header(f)
            f.close()
            # recursive call
            fqterm.sendString(lp, 'r')
            time.sleep(wait_time)
            # increase delay when condition not met
            down_folder()
        else:
            print "Unrecognized Categary"
            # end the index.html
            f = open(path + "index.html", "a+")
            write_index_footer(f)
            f.close()
            # wrong formatted list, leave out
            print "leave %s" % path
            fqterm.sendString(lp, 'q')
            path = upper_dir(path)
            time.sleep(wait_time)
            return
        str_next = fqterm.getText(lp, line + 1)
        # move cursor down and get the num
        fqterm.sendString(lp, 'j')
        time.sleep(wait_time)
        str_next = fqterm.getText(lp, fqterm.caretY(lp))
        article_num_next = get_list_num(str_next)
        if (article_num_next == None):
            print "Wrong format list"
            # end the index.html
            f = open(path + "index.html", "a+")
            write_index_footer(f)
            f.close()
            # wrong formatted list, leave out
            print "leave %s" % path
            fqterm.sendString(lp, 'q')
            path = upper_dir(path)
            time.sleep(wait_time)
            return
        # exit current dir when the number of the next one equals or small then last
        # this may cause problem when the server is extra slow
        if (int(article_num_next) <= int(article_num)):
            #print "leaving, because cur: %s < pre: %s" % (article_num_next , article_num)
            if (path != path_dir):
                # end the index.html
                f = open(path + "index.html", "a+")
                write_index_footer(f)
                f.close()
                # leave out
                print "leave %s" % path
                fqterm.sendString(lp, 'q')
                path = upper_dir(path)
                time.sleep(wait_time)
            return
コード例 #4
0
                # leave out
                print "leave %s" % path
                fqterm.sendString(lp, 'q')
                path = upper_dir(path)
                time.sleep(wait_time)
            return


# NOTE: make sure path ended with '/'(*nix) or '\\'(windowz)
#path_dir=path="e:\\temp\\test\\"
path_dir = path = "/home/dp2/temp/test/"

# try to save all to home dir
# path_dir=path=os.environ['HOME']+"/.fqterm/downloads/"+time.ctime()+"/"
os.makedirs(path)

# enter
fqterm.sendString(lp, 'x')
time.sleep(wait_time)
# create index.html and write the header
f = open(path + "index.html", "w")
write_index_header(f)
f.close()
down_folder()
# end the index.html
f = open(path + "index.html", "a+")
write_index_footer(f)
f.close()
# exit
fqterm.sendString(lp, 'q')
コード例 #5
0
ファイル: download.py プロジェクト: ashang/fqterm
def down_folder():
	global path
	first_num = -1
	while(1):
		line=fqterm.caretY(lp) 
		str_line=fqterm.getText(lp,line)
	
		article_num = get_list_num(str_line)
		if (first_num == -1):
			first_num = article_num
		if(article_num==None):
			print "Wrong format list"
			# end the index.html
			f=open(path+"index.html","a+")
			write_index_ender(f)
			f.close()
			# wrong formated list, leave out
			print "leave %s" % path
			fqterm.sendString(lp,'q')
			path=upper_dir(path)
			time.sleep(wait_time)
			return	

		article_categary = get_list_categary(str_line)
		article_title = get_list_title(str_line)	

		# download if its file
		if article_categary == '[文件]':
			# log in index.html
			f=open(path+"index.html","a+")
			f.write("<p><a href="+article_num+".html>")
			f.write("[文件] "+article_title+"</a></p>\n")
			f.close()
			# downlaod and save article 
			f=open(path+article_num+".html","w")
			fqterm.sendString(lp,'r')
			time.sleep(wait_time)
			write_html_header(f,int(article_num))
			f.write(txt2html(fqterm.getArticle(lp, 100)[0]))
			f.write("\n")
			write_html_ender(f,int(article_num))
			f.close()
			time.sleep(wait_time)
			fqterm.sendString(lp,"q")
			time.sleep(wait_time)
		# recursive callback if its directory
		elif article_categary == '[目录]':
			# log in index.html
			f=open(path+"index.html","a+")
			f.write("<p><a href="+article_num+"/index.html>")
			f.write("[目录] "+article_title+"</a></p>\n")
			f.close()
			# make dir and enter
			path=lower_dir(path,article_num)
			os.mkdir(path)
			print "enter %s" % path
			# create index.html and write the header
			f=open(path+"index.html","w")
			write_index_header(f)
			f.close()
			# recursive call
			fqterm.sendString(lp,'r')
			time.sleep(wait_time)
			# increase delay when condition not met
			down_folder()
		else:
			print "Unrecognized Categary"
			# end the index.html
			f=open(path+"index.html","a+")
			write_index_ender(f)
			f.close()
			# wrong formated list, leave out
			print "leave %s" % path
			fqterm.sendString(lp,'q')
			path=upper_dir(path)
			time.sleep(wait_time)
			return	
		str_next=fqterm.getText(lp,line+1)
		# move cursor down and get the num
		fqterm.sendString(lp,'j')
		time.sleep(wait_time)
		str_next=fqterm.getText(lp,fqterm.caretY(lp))
		article_num_next = get_list_num(str_next)
		if(article_num_next==None):
			print "Wrong format list"
			# end the index.html
			f=open(path+"index.html","a+")
			write_index_ender(f)
			f.close()
			# wrong formated list, leave out
			print "leave %s" % path
			fqterm.sendString(lp,'q')
			path=upper_dir(path)
			time.sleep(wait_time)
			return	
		# exit current dir when the number of the next one equals or small then last
		# this may cause problem when the server is extra slow 
		if(int(article_num_next) <= int(article_num)):
			#print "leaving, because cur: %s < pre: %s" % (article_num_next , article_num)
			if(path!=path_dir):
				# end the index.html
				f=open(path+"index.html","a+")
				write_index_ender(f)
				f.close()
				# leave out
				print "leave %s" % path
				fqterm.sendString(lp,'q')
				path=upper_dir(path)
				time.sleep(wait_time)
			return
コード例 #6
0
ファイル: download.py プロジェクト: ashang/fqterm
				# leave out
				print "leave %s" % path
				fqterm.sendString(lp,'q')
				path=upper_dir(path)
				time.sleep(wait_time)
			return

# NOTE: make sure path ended with '/'(*nix) or '\\'(windowz)
#path_dir=path="e:\\temp\\test\\"
path_dir=path="/home/dp2/temp/test/"

# try to save all to home dir
# path_dir=path=os.environ['HOME']+"/.fqterm/downloads/"+time.ctime()+"/"
os.makedirs(path)

# enter
fqterm.sendString(lp,'x') 
time.sleep(wait_time)
# create index.html and write the header
f=open(path+"index.html","w")
write_index_header(f)
f.close()
down_folder()
# end the index.html
f=open(path+"index.html","a+")
write_index_ender(f)
f.close()
# exit
fqterm.sendString(lp,'q')

コード例 #7
0
ファイル: continuous.py プロジェクト: xiongyw/fqterm
# This is demo script to continuousely download 4 articles
import fqterm
import sys, time

# f=open("/home/dp2/test.txt","w")
f = open("c:\\test.txt", "w")

lp = long(sys.argv[0])

for i in range(4):
    fqterm.sendString(lp, "r")
    time.sleep(1)
    f.write(fqterm.getArticle(lp, 100)[0])
    time.sleep(1)
    fqterm.sendString(lp, "q")
    time.sleep(1)
    fqterm.sendString(lp, "j")
    time.sleep(1)
f.close()
コード例 #8
0
	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:
		fqterm.sendString(ID, item)
		print item
		#if dataEvents.has_key(ID):
			#dataEvents[ID].wait()
	fqterm.sendString(ID, '\n')
	#WaitFor(ID, SST_LIST)

	interval=random.random()*7+3
	#print interval
	time.sleep(interval)
コード例 #9
0
ファイル: continuous.py プロジェクト: ashang/fqterm
# This is demo script to continuousely download 4 articles
import fqterm
import sys, time

# f=open("/home/dp2/test.txt","w")
f = open("c:\\test.txt", "w")

lp=long(sys.argv[0])

for i in range(4):
	fqterm.sendString(lp,"r")
	time.sleep(1)
	f.write(fqterm.getArticle(lp, 100)[0])
	time.sleep(1)
	fqterm.sendString(lp,"q")
	time.sleep(1)
	fqterm.sendString(lp,"j")
	time.sleep(1)
f.close()