pkucannot
unread,Jul 10, 2009, 7:22:14 PM7/10/09Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to CTerm
文本复制,在未名和水木用没出过问题,希望对大家有帮助
ArticleID : 要复制的文章的编号
TextIdle : 两个操作之间的间隔时间(跟网速有关,比如可以设定 TextIdle=1)
返回结果result,result[0]是题目,result[1]是文章内容
def copyArticle(CTermID, ArticleID ):
SendString(CTermID, (str)(ArticleID)+'\n')
time.sleep(TextIdle)
SendString(CTermID, 'r')
time.sleep(TextIdle)
s = GetText(CTermID, 1, 1)
s = s[0:len(s)-1]
s = s.lstrip('标 题:')
s = s.rstrip(' ')
title = s
content = ''
status = 0 # 1 : End Page
Page = 1
LineList = []
while True:
s = GetText(CTermID, 23, 23)
if s.find('阅读文章')!=-1 and s.find('结束')!=-1 and s.find('上一封')!
=-1 and s.find('下一封')!= -1:
status = 1
elif s.find('看到末尾啦')!= -1 or s.find('下面还有喔 (100%)')!=-1:
SendString(CTermID, 'q')
time.sleep(TextIdle)
status = 1
else:
for i in range(23, -1, -1):
s = GetText(CTermID, i, i)
if s.rstrip(' ') == '--':
SendString(CTermID, 'q')
time.sleep(TextIdle)
status = 1
break
if status == 0:
LineList = []
if Page == 1:
start = 3
else:
start = 1
for i in range(1, 23):
s = GetText(CTermID, i, i)
LineList.insert(len(LineList), s)
for i in range(start, len(LineList)):
s = LineList[i]
if s.endswith(' '):
s = s[0:len(s)-3]+'\n'
elif s.endswith(' '):
s = s[0:len(s)-2]
content += s
SendString(CTermID, ' ')
time.sleep(TextIdle)
Page += 1
else:
LineList2 = []
for i in range(0, 23):
s = GetText(CTermID, i, i)
LineList2.insert(len(LineList2), s)
for i in range(len(LineList2)-1, -1 , -1):
findend=0
s = LineList2[i].rstrip(' ')
if s == '--':
findend=1
end = i-1
break
if findend==0:
end=len(LineList2)-2
flag = 0
if len(LineList) == 0:
flag = 1
start = 4
else:
LastNonSpaceLine = -1
for j in range(len(LineList)-1, -1, -1):
if LineList[j].isspace() == 0:
LastNonSpaceLine = j
break
if LastNonSpaceLine != -1:
for i in range(min(end, LastNonSpaceLine), -1,
-1):
if LineList2[i] == LineList[LastNonSpaceLine]:
flag = 1 #是否是上一屏的最后一行
for j in range(i-1, -1, -1):
if LineList2[j] != LineList
[LastNonSpaceLine-i+j]:
flag = 0
break
if flag == 1:
start = i+1
break
if flag != 1:
start = 0
for i in range(start, end+1):
s = LineList2[i]
if s.endswith(' '):
s = s[0:len(s)-3]+'\n'
elif s.endswith(' '):
s = s[0:len(s)-2]
content += s
SendString(CTermID, 'q')
result = ['','']
result[0] = title
content=content.rstrip()+'\n\n'
result[1] = content
return result