/
down_hws.py
45 lines (35 loc) · 1.13 KB
/
down_hws.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# _*_ coding:utf-8 _*_
import sqlite3
import os
import urllib2
#将系统默认编码设置为utf-8
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
#连接数据库
con = sqlite3.connect("mimi.db")
cur = con.cursor()
for i in range(1,500+1):
#从数据库中检索出更新时间和Pageurl
sql = "select 更新时间,PageUrl from content where id = " + str(i)
cur.execute(sql)
res = cur.fetchone()
updateTime = res[0]
pageUrl = res[1]
#根据PageUrl构建主题文件的ID和下载链接
themeID = pageUrl.split('/')[-1]
downUrl = pageUrl.replace("detail","download")
#构建本地存放路径
localDir = "/data/Themes/" + themeID
#判断本地路径是否存在,如果不存在则建立该路径
if not os.path.exists(localDir):
op = "mkdir " + localDir
os.system(op)
#构建本地文件名,以更新时间为文件名
localName = updateTime + ".mtz"
#判断本地文件是否存在,如果不存在则下载该文件
if not os.path.isfile(localDir + "/" + localName):
op = "wget -O " + localDir + "/" + localName + " " + downUrl
os.system(op)
print "第 " + str(i) + " 个已经下载"
i = i + 1