📄 auto-downloader
字号:
#!/bin/bash# THU wlxt auto-downloader ## Usage:# $chmod a+x auto-downloader# $./auto-downloader## dinstein@FREE dinstein@163.com http://dinstein.cublog.cn##CHAR="gbk" # your local Characters Encodingecho "Please input username:"read USER #read usernameecho "Please input password:"read -s PASSWD #read password#echo "Please input your local Characters Encoding (gbk gbk or utf-8 etc.)"#read CHARecho "Start"if [ ! -d "gonggao" ]; then mkdir gonggaofiif [ ! -d "print" ]; then mkdir printfiif [ -f "new.txt" ]; then cat new.txt >>history.txt rm new.txt unix2dos history.txt 2>/dev/nullfiif [ -f "gonggao/new.html" ]; then rm gonggao/new.html echo "<H1>What's New</H1>" >> gonggao/new.htmlfifor del in {MyCourse,MyCourse1,MyCourse2,CourseID,pw1,pw2,pw3,cookies,gonggao2.html,gonggao.html};doif [ -f "$del" ]; then rm $delfidoneecho "Get cookies..."curl -s -c cookies "http://learn.tsinghua.edu.cn/use_go.jsp?userid=$USER&&userpass=$PASSWD" >> pw1 #get cookiesiconv -f gbk -t $CHAR pw1 >> pw2echo "get Mycourse..."cat pw2 |grep window.alert|cut -d'(' -f2|cut -d')' -f1 >> pw3FLAG=`cat pw3|grep "" -c`if [ $FLAG != 0 ];then cat pw3 rm pw1 pw2 pw3 cookies exitficurl -s -b cookies "http://learn.tsinghua.edu.cn/lesson/student/MyCourse.jsp?typepage=1" >>MyCourse1 #get MyCourseiconv -f gbk -t $CHAR MyCourse1 >> MyCourse2echo "get CourseID..."grep course_id MyCourse2|cut -d'=' -f3-|cut -d'"' -f1 >>CourseID #get CourseIDecho "get MyCourse Name..."grep 200 MyCourse2|cut -d'(' -f1 |sed 's/[<> ~!@#$%^&*()]//g' >>MyCourse #get MyCourse name# gonggao.html beginif [ -f "gonggao.html" ];then rm gonggao.htmlfiecho "<TABLE height=483 cellSpacing=0 cellPadding=0 width="810%" border=0> <TBODY> <TR> <TD width="90%" height="100%"> <IFRAME name=content_frame src=gonggao/new.html marginWidth=0 marginHeight=0 frameBorder=0 width=800 height="100%"> </IFRAME> </TD> </TR> </TBODY></TABLE> <H2>Please click the link following</H2>" >>gonggao.htmlecho "<A href="gonggao/new.html" target=content_frame>What's new</A> " >> gonggao.htmlcount1=1for CourseName in `cat MyCourse`; do CourseID=`cat CourseID|head -$count1|tail -1` echo "<A href=\"gonggao/"$CourseID".html\" target=content_frame>"$CourseName"</A>" >> gonggao2.html count1=$[count1+1]doneif [ -f gonggao2.html ];then iconv -f $CHAR -t gbk gonggao2.html >> gonggao.html rm gonggao2.htmlfi#gonggao.html endcount1=1for CourseName in `cat MyCourse`; do echo "checking $CourseName..." CourseID=`cat CourseID|head -$count1|tail -1` if [ ! -d $CourseName ]; then mkdir $CourseName fi cd $CourseName if [ -f down ];then rm down* fi if [ -f cookies2 ];then rm cookies2 fi curl -s -b ../cookies -c cookies2 "http://learn.tsinghua.edu.cn/lesson/student/course_locate.jsp?course_id=$CourseID" >>/dev/null #get Course cookies curl -s -b cookies2 "http://learn.tsinghua.edu.cn/lesson/student/download.jsp?course_id=$CourseID" >> down #get file informations iconv -f gbk -t $CHAR down >> down2 cat down2 |grep uploadFile|cut -d'"' -f10-|cut -d'"' -f1 >>down3 #down3 save the filepath cat down2 |grep window.open|cut -d'&' -f2|cut -d'=' -f2|cut -d'_' -f1-|sed -e 's/ /_/g' >>down4 #down4 save the file name #cat down2 |grep window.open|cut -d'&' -f2|cut -d'=' -f2|cut -d'_' -f1-|sed -e 's/ /_/g' -e 's/[0-9]\{7,10\}_//g' -e 's/_[0-9]\{7,10\}//g' >>down4 #down4 save the file name count2=1; for FileName in `cat down4`; do FilePath=`cat down3|head -$count2|tail -1` if [ ! -f $FileName ]; then echo "start download" $CourseName $FileName curl -b cookies2 "http://learn.tsinghua.edu.cn$FilePath" >> $FileName #start download file echo $CourseName $FileName >> ../new.txt if [ ! -f no.txt ];then cp $FileName ../print/ fi fi count2=$[count2+1] done#gonggao begin flag=0 if [ -f Temp ];then for del in `ls Temp*`;do rm $del done fi if [ -f "../gonggao/$CourseID.html" ];then rm ../gonggao/$CourseID.html fi touch Temp echo "<H1>"$CourseName"</H1>" >> Temp.$CourseID.html.1 URL1=`curl -s -b cookies2 "http://learn.tsinghua.edu.cn/public/bbs/getnoteid_student.jsp?course_id=$CourseID" |cut -d"\"" -f2-|cut -d"\"" -f1` curl -s -b cookies2 "$URL1" >> Temp.gg1 cat Temp.gg1 |grep bbs_type|cut -d"'" -f2-|cut -d"'" -f1 >> Temp.URL2 iconv -f gbk -t $CHAR Temp.gg1 >> Temp.gg1.1 cat Temp.gg1.1 |grep bbs_type |sed -e 's/note_reply.*\&id=\([0-9]*\)/\1.html/g' -e 's/\&course_id=[0-9]*'//g >>Temp.$CourseID.html.1 iconv -f $CHAR -t gbk Temp.$CourseID.html.1 >> ../gonggao/$CourseID.html C=1 for URL3 in `cat Temp.URL2`;do NoteID=`echo $URL3 |cut -d'=' -f3-|cut -d'&' -f1` if [ ! -f "../gonggao/$NoteID.html" ];then curl -s -b cookies2 "http://learn.tsinghua.edu.cn/public/bbs/$URL3" >>Temp.$NoteID iconv -f gbk -t $CHAR Temp.$NoteID >> Temp.$NoteID.1 cat Temp.$NoteID.1 | sed '1,72d'|grep -v sendmail | sed 's/onMouseOver=\".*\"//g'|sed 's/onMouseOut=\".*\"//g' >> Temp.$NoteID.html.1 if [ $flag -eq 0 ];then echo "<H1>"$CourseName"</H1>" >> ../gonggao/new flag=1 fi NEW=`cat Temp.$CourseID.html.1|grep $NoteID` echo $NEW >> ../gonggao/new echo " ">> ../gonggao/new C=$[C+1] iconv -f $CHAR -t gbk Temp.$NoteID.html.1 >> ../gonggao/$NoteID.html fi done rm Temp* #gonggao end rm down* cookies2 cd .. count1=$[count1+1]donerm cookies* MyCourse* CourseID pw1 pw2 pw3if [ -f "new.txt" ]; then unix2dos new.txt 2>/dev/null echo "" echo "New Courseware:" cat new.txtfiif [ -f "gonggao/new" ]; then echo "" echo "New gonggao:" cat gonggao/new|sed s/\<[^\>]*\>//g echo "Please check gonggao.html" sed s/$/\<br\>/g gonggao/new >> gonggao/new.html.1 iconv -f $CHAR -t gbk gonggao/new.html.1 >> gonggao/new.html rm gonggao/new gonggao/new.html.1fi
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -