Esempio n. 1
0
# send current article to one assigned email address
# 1. need CJK codec 
import smtplib
from email.Header import Header
from email.Message import Message
import fqterm,sys,string

lp=long(sys.argv[0])
article=fqterm.getArticle(lp, 100)[0]

from_addr = "*****@*****.**"
to_addr="*****@*****.**"

subject = article.split("\n")
subject = subject[1]
subject = subject[7:]

mess = Message()
h = Header(subject,'GB2312')
mess['Subject']=h

msg = ("Content-Type: text/plain; charset= GB2312\r\n"
	"From: %s\r\nTo: %s\r\n%s\r\n\r\n"
	% (from_addr,to_addr, mess.as_string()))
msg = msg + article

smtp_host = "smtp.email.com"
server = smtplib.SMTP(smtp_host)
server.set_debuglevel(1)
#maybe your smtp need auth
#server.login(usr,pwd)
Esempio n. 2
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
Esempio n. 3
0
# 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()
Esempio n. 4
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_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
Esempio n. 5
0
# 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()