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
73 changes: 73 additions & 0 deletions burness/0010/image_verification.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#-*- coding: utf-8-*-

# Source:https://github.com/Show-Me-the-Code/show-me-the-code
# Author:Burness Duan
# Date:2014-12-29
# Python 3.3


import random
import string
from PIL import Image, ImageDraw, ImageFont, ImageFilter


def random_string(y):
'''
生成指定长度的随机字符串
'''
return ''.join(random.choice(string.ascii_letters) for x in range(y))


def create_verifi_image(strs,
size=(120, 30),
img_type = 'jpg',
mode = 'RGB',
bg_color= (255, 255, 255),
fg_color = (0, 0, 255),
font_size =18,
font_type = 'ahronbd.ttf',
draw_lines=True,
n_line=(1, 2),
draw_points=True,
point_chance = 2,
):

width, height = size
img = Image.new(mode, size, bg_color)
draw = ImageDraw.Draw(img)
if draw_lines:
line_num = random.randint(*n_line)
for i in range(line_num):
begin = (random.randint(0, size[0]), random.randint(0, size[1]))
end = (random.randint(0, size[0]), random.randint(0, size[1]))
draw.line([begin, end], fill=(0, 0, 0))

if draw_points:
chance = min(100, max(0, int(point_chance)))
for w in range(width):
for h in range(height):
tmp = random.randint(0,100)
if tmp >100 -chance:
draw.point((w,h),fill =(0,0,0))
font = ImageFont.truetype(font_type, font_size)
font_width, font_height = font.getsize(strs)
draw.text(((width-font_width)/3,(height-font_height)/3),strs,font=font, fill=fg_color)
params = [1 - float(random.randint(1, 2)) / 100, 0, 0, 0, 1 - float(random.randint(1, 10)) / 100,
float(random.randint(1, 2)) / 500,
0.001,
float(random.randint(1, 2)) / 500
]
img = img.transform(size, Image.PERSPECTIVE, params)
img = img.filter(ImageFilter.EDGE_ENHANCE_MORE)
return img


if __name__ == '__main__':
strs = random_string(4)
code_img = create_verifi_image(strs)
code_img.show()
code_img.save('validate.jpg')




Binary file added burness/0010/validate.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions burness/0011/filter_word.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#-*- coding: utf-8-*-

# Source:https://github.com/Show-Me-the-Code/show-me-the-code
# Author:Burness Duan
# Date:2014-12-29
# Python 3.3


def filter_word(input_word):
input_word = input_word.split()
filter_word_list = []
with open('./filter_word.txt','r') as f:
for content in f:
# print content
filter_word_list.append(content.strip('\n'))
# print(filter_word_list)
return filter_word_list

if __name__ == '__main__':
input_words = input('Input some words')
input_words_list = input_words.split()
filter_word_list = filter_word(input_words)
# print(filter_word_list)
# print(input_words)
# print(set(input_words_list).intersection(filter_word_list))
if not set(input_words_list).intersection(filter_word_list):
print('Human Rights')
else:
print('Freedom')

11 changes: 11 additions & 0 deletions burness/0011/filter_word.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
����
����Ա
����Ա
�쵼
ţ��
ţ��
����
����
love
sex
jiangge
11 changes: 11 additions & 0 deletions burness/0012/filter_word.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
����
����Ա
����Ա
�쵼
ţ��
ţ��
����
����
love
sex
jiangge
29 changes: 29 additions & 0 deletions burness/0012/filter_words_print.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#-*- coding: utf-8-*-

# Source:https://github.com/Show-Me-the-Code/show-me-the-code
# Author:Burness Duan
# Date:2014-12-29
# Python 3.3


def filter_word(input_word):
input_word = input_word.split()
filter_word_list = []
with open('./filter_word.txt','r') as f:
for content in f:
filter_word_list.append(content.strip('\n'))
return filter_word_list

if __name__ == '__main__':
input_words = input('Input some words')
input_words_list = input_words.split()
filter_word_list = filter_word(input_words)

words_string=''
for word in input_words_list:
if word in filter_word_list:
word = '*'*len(word)
words_string += word + ' '
print(words_string)


Binary file added burness/0013/0.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added burness/0013/1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added burness/0013/10.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added burness/0013/11.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added burness/0013/12.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added burness/0013/13.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added burness/0013/14.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added burness/0013/15.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added burness/0013/16.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added burness/0013/17.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added burness/0013/18.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added burness/0013/19.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added burness/0013/2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added burness/0013/20.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added burness/0013/21.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added burness/0013/22.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added burness/0013/23.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added burness/0013/24.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added burness/0013/25.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added burness/0013/26.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added burness/0013/27.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added burness/0013/28.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added burness/0013/29.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added burness/0013/3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added burness/0013/30.jpg
Binary file added burness/0013/31.jpg
Binary file added burness/0013/32.jpg
Binary file added burness/0013/33.jpg
Binary file added burness/0013/34.jpg
Binary file added burness/0013/35.jpg
Binary file added burness/0013/36.jpg
Binary file added burness/0013/37.jpg
Binary file added burness/0013/38.jpg
Binary file added burness/0013/39.jpg
Binary file added burness/0013/4.jpg
Binary file added burness/0013/40.jpg
Binary file added burness/0013/41.jpg
Binary file added burness/0013/42.jpg
Binary file added burness/0013/43.jpg
Binary file added burness/0013/44.jpg
Binary file added burness/0013/45.jpg
Binary file added burness/0013/46.jpg
Binary file added burness/0013/47.jpg
Binary file added burness/0013/48.jpg
Binary file added burness/0013/5.jpg
Binary file added burness/0013/6.jpg
Binary file added burness/0013/7.jpg
Binary file added burness/0013/8.jpg
Binary file added burness/0013/9.jpg
53 changes: 53 additions & 0 deletions burness/0013/get_photos.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import urllib2
from HTMLParser import HTMLParser
from traceback import print_exc
from sys import stderr

class _DeHTMLParser(HTMLParser):
'''
利用HTMLParse来解析网页元素
'''
def __init__(self):
HTMLParser.__init__(self)
self.img_links = []

def handle_starttag(self, tag, attrs):
if tag == 'img':
# print(attrs)
try:
if ('pic_type','0') in attrs:
for name, value in attrs:
if name == 'src':
self.img_links.append(value)
except Exception as e:
print(e)


return self.img_links


def dehtml(text):
try:
parser = _DeHTMLParser()
parser.feed(text)
parser.close()
return parser.img_links
except:
print_exc(file=stderr)
return text


def main():
html = urllib2.urlopen('http://tieba.baidu.com/p/2166231880')
content = html.read()
print(dehtml(content))
i = 0
for img_list in dehtml(content):
img_content = urllib2.urlopen(img_list).read()
path_name = str(i)+'.jpg'
with open(path_name,'wb') as f:
f.write(img_content)
i+=1

if __name__ == '__main__':
main()
Binary file added burness/0013/path_name
Binary file not shown.
8 changes: 5 additions & 3 deletions burness/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
## Python 练习册,每天一个小程序 ##


#### 说明: ####

- Python 练习册,每天一个小程序。注:将 Python 换成其他语言,大多数题目也试用
- Python 练习册,每天一个小程序。注:将 Python 换成其他语言,大多数题目也试用`
- 不会出现诸如「打印九九乘法表」、「打印水仙花」之类的题目
- 欢迎大家 Pull Request 出题目,贴代码(Gist、Blog皆可):-)

Expand Down Expand Up @@ -162,4 +161,7 @@

- 阅读资料 [Hashing Strings with Python](http://www.pythoncentral.io/hashing-strings-with-python/)

- 阅读资料 [Python's safest method to store and retrieve passwords from a database](http://stackoverflow.com/questions/2572099/pythons-safest-method-to-store-and-retrieve-passwords-from-a-database)
- 阅读资料 [Python's safest method to store and retrieve passwords from a database](http://stackoverflow.com/questions/2572099/pythons-safest-method-to-store-and-retrieve-passwords-from-a-database)