Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions renzongxian/0013/0013.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Source:https://github.com/Show-Me-the-Code/show-me-the-code
# Author:renzongxian
# Date:2014-12-24
# Python 3.4

"""

第 0013 题: 用 Python 写一个爬图片的程序,爬 这个链接里的日本妹子图片 :-)

"""

import urllib.request
import re
import os


def fetch_pictures(url):
html_content = urllib.request.urlopen(url).read()
r = re.compile('<img pic_type="0" class="BDE_Image" src="(.*?)"')
picture_url_list = r.findall(html_content.decode('utf-8'))

os.mkdir('pictures')
os.chdir(os.path.join(os.getcwd(), 'pictures'))
for i in range(len(picture_url_list)):
picture_name = str(i) + '.jpg'
try:
urllib.request.urlretrieve(picture_url_list[i], picture_name)
print("Success to download " + picture_url_list[i])
except:
print("Fail to download " + picture_url_list[i])

if __name__ == '__main__':
fetch_pictures("http://tieba.baidu.com/p/2166231880")
2 changes: 1 addition & 1 deletion renzongxian/0016/0016.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Source:https://github.com/Show-Me-the-Code/show-me-the-code
# Author:renzongxian
# Date:2014-12-22
# Date:2014-12-23
# Python 3.4

"""
Expand Down
2 changes: 1 addition & 1 deletion renzongxian/0017/0017.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Source:https://github.com/Show-Me-the-Code/show-me-the-code
# Author:renzongxian
# Date:2014-12-22
# Date:2014-12-23
# Python 3.4

"""
Expand Down
27 changes: 27 additions & 0 deletions renzongxian/0021/0021.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Source:https://github.com/Show-Me-the-Code/show-me-the-code
# Author:renzongxian
# Date:2014-12-24
# Python 3.4

"""

第 0021 题: 通常,登陆某个网站或者 APP,需要使用用户名和密码。密码是如何加密后存储起来的呢?
请使用 Python 对密码加密。

"""

import uuid
import hashlib


def encrypt_password(password):
salt = uuid.uuid4().hex
result = password
for i in range(10):
result = hashlib.sha256(salt.encode() + result.encode()).hexdigest()
return salt + ':' + result

if __name__ == '__main__':
pw = input('Please input your password:')
print("The password stored in the database is:" + encrypt_password(pw))

55 changes: 55 additions & 0 deletions renzongxian/0022/0022.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Source:https://github.com/Show-Me-the-Code/show-me-the-code
# Author:renzongxian
# Date:2014-12-24
# Python 3.4

"""

第 0022 题: iPhone 6、iPhone 6 Plus 早已上市开卖。请查看你写得 第 0005 题的代码是否可以复用。

"""

from PIL import Image
import os
import sys


def resize_image(image, t_weight, t_height):
im = Image.open(image)
weight, height = im.size
if weight > t_weight or height > t_height:
dw = weight / t_weight
dh = height / t_height
ds = max(dw, dh)
new_weight = int(weight / ds)
new_height = int(height / ds)
im = im.resize((new_weight, new_height))
print("Succeed to resize the image %s to %s*%s " % (image, new_weight, new_height))
im.save(image)
else:
print("The image %s doesn't need to be resized." % image)


if __name__ == "__main__":
trans_weight = 0
trans_height = 0
if len(sys.argv) <= 1:
print("Need at least 1 parameter. Try to execute 'python 0022.py $dir_path'")
else:
while True:
flag = input("请选择你要转换的分辨率: 1. iPhone 6 2. iPhone 6 Plus:")
if flag == '1':
trans_weight = 750
trans_height = 1334
break
elif flag == '2':
trans_weight = 1080
trans_height = 1920
break
else:
print("输入有误,重新选择!")
for dir_path in sys.argv[1:]:
for image_name in os.listdir(dir_path):
image_path = os.path.join(dir_path, image_name)
resize_image(image_path, trans_weight, trans_height)