File tree Expand file tree Collapse file tree 5 files changed +117
-2
lines changed
Expand file tree Collapse file tree 5 files changed +117
-2
lines changed Original file line number Diff line number Diff line change 1+ # Source:https://github.com/Show-Me-the-Code/show-me-the-code
2+ # Author:renzongxian
3+ # Date:2014-12-24
4+ # Python 3.4
5+
6+ """
7+
8+ 第 0013 题: 用 Python 写一个爬图片的程序,爬 这个链接里的日本妹子图片 :-)
9+
10+ """
11+
12+ import urllib .request
13+ import re
14+ import os
15+
16+
17+ def fetch_pictures (url ):
18+ html_content = urllib .request .urlopen (url ).read ()
19+ r = re .compile ('<img pic_type="0" class="BDE_Image" src="(.*?)"' )
20+ picture_url_list = r .findall (html_content .decode ('utf-8' ))
21+
22+ os .mkdir ('pictures' )
23+ os .chdir (os .path .join (os .getcwd (), 'pictures' ))
24+ for i in range (len (picture_url_list )):
25+ picture_name = str (i ) + '.jpg'
26+ try :
27+ urllib .request .urlretrieve (picture_url_list [i ], picture_name )
28+ print ("Success to download " + picture_url_list [i ])
29+ except :
30+ print ("Fail to download " + picture_url_list [i ])
31+
32+ if __name__ == '__main__' :
33+ fetch_pictures ("http://tieba.baidu.com/p/2166231880" )
Original file line number Diff line number Diff line change 11# Source:https://github.com/Show-Me-the-Code/show-me-the-code
22# Author:renzongxian
3- # Date:2014-12-22
3+ # Date:2014-12-23
44# Python 3.4
55
66"""
Original file line number Diff line number Diff line change 11# Source:https://github.com/Show-Me-the-Code/show-me-the-code
22# Author:renzongxian
3- # Date:2014-12-22
3+ # Date:2014-12-23
44# Python 3.4
55
66"""
Original file line number Diff line number Diff line change 1+ # Source:https://github.com/Show-Me-the-Code/show-me-the-code
2+ # Author:renzongxian
3+ # Date:2014-12-24
4+ # Python 3.4
5+
6+ """
7+
8+ 第 0021 题: 通常,登陆某个网站或者 APP,需要使用用户名和密码。密码是如何加密后存储起来的呢?
9+ 请使用 Python 对密码加密。
10+
11+ """
12+
13+ import uuid
14+ import hashlib
15+
16+
17+ def encrypt_password (password ):
18+ salt = uuid .uuid4 ().hex
19+ result = password
20+ for i in range (10 ):
21+ result = hashlib .sha256 (salt .encode () + result .encode ()).hexdigest ()
22+ return salt + ':' + result
23+
24+ if __name__ == '__main__' :
25+ pw = input ('Please input your password:' )
26+ print ("The password stored in the database is:" + encrypt_password (pw ))
27+
Original file line number Diff line number Diff line change 1+ # Source:https://github.com/Show-Me-the-Code/show-me-the-code
2+ # Author:renzongxian
3+ # Date:2014-12-24
4+ # Python 3.4
5+
6+ """
7+
8+ 第 0022 题: iPhone 6、iPhone 6 Plus 早已上市开卖。请查看你写得 第 0005 题的代码是否可以复用。
9+
10+ """
11+
12+ from PIL import Image
13+ import os
14+ import sys
15+
16+
17+ def resize_image (image , t_weight , t_height ):
18+ im = Image .open (image )
19+ weight , height = im .size
20+ if weight > t_weight or height > t_height :
21+ dw = weight / t_weight
22+ dh = height / t_height
23+ ds = max (dw , dh )
24+ new_weight = int (weight / ds )
25+ new_height = int (height / ds )
26+ im = im .resize ((new_weight , new_height ))
27+ print ("Succeed to resize the image %s to %s*%s " % (image , new_weight , new_height ))
28+ im .save (image )
29+ else :
30+ print ("The image %s doesn't need to be resized." % image )
31+
32+
33+ if __name__ == "__main__" :
34+ trans_weight = 0
35+ trans_height = 0
36+ if len (sys .argv ) <= 1 :
37+ print ("Need at least 1 parameter. Try to execute 'python 0022.py $dir_path'" )
38+ else :
39+ while True :
40+ flag = input ("请选择你要转换的分辨率: 1. iPhone 6 2. iPhone 6 Plus:" )
41+ if flag == '1' :
42+ trans_weight = 750
43+ trans_height = 1334
44+ break
45+ elif flag == '2' :
46+ trans_weight = 1080
47+ trans_height = 1920
48+ break
49+ else :
50+ print ("输入有误,重新选择!" )
51+ for dir_path in sys .argv [1 :]:
52+ for image_name in os .listdir (dir_path ):
53+ image_path = os .path .join (dir_path , image_name )
54+ resize_image (image_path , trans_weight , trans_height )
55+
You can’t perform that action at this time.
0 commit comments