This repository was archived by the owner on Jul 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
55 lines (48 loc) · 1.48 KB
/
main.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
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python
# coding: utf-8
from user import get_album_list
from user import get_sid
from album import get_photo_list
from album import get_photo_image_url
from os import path
from os import makedirs
import sys
import locale
import requests
import getpass
reload(sys)
sys.setdefaultencoding(locale.getpreferredencoding())
requser = True
while True:
if requser:
requser = False
USER = raw_input(u'用户名:')
PASS = getpass.getpass()
SID = get_sid(USER, PASS)
if SID[0]:
SID = SID[1]
break
else:
if u'登录失败,请稍后重试' in SID[1]:
pass
else:
requser = True
DIR = raw_input(u'请输入保存目录:')
if not path.exists(DIR):
makedirs(DIR)
UID = raw_input(u"请输入好友ID:")
albums = get_album_list(SID, UID);
print u'共有%d个相册' % (len(albums))
for album in albums:
print u'> 正在检查相册 %s 中的照片' % (albums[album])
photos = get_photo_list(album)
print u'>> 相册 %s 中共有 %d 张照片' % (albums[album], len(photos))
if not path.exists(path.join(DIR, albums[album])):
makedirs(path.join(DIR, albums[album]))
for i in xrange(len(photos)):
print u'>>> 正在下载第 %d 张照片' % (i + 1)
url = get_photo_image_url(photos[i])
r = requests.get(url[0])
f = open(path.join(DIR, albums[album], '%d.%s' % (i + 1, r.url.split('.')[-1])), 'wb')
f.write(r.content)
f.close()