diff --git a/Jaccorot/0009/0009.py b/Jaccorot/0009/0009.py index 4835336e..65a70b0c 100644 --- a/Jaccorot/0009/0009.py +++ b/Jaccorot/0009/0009.py @@ -1,6 +1,12 @@ #!/usr/bin/python #coding=utf-8 +""" + +第 0009 题:一个HTML文件,找出里面的链接 + +""" + from bs4 import BeautifulSoup def find_the_link(filepath): diff --git a/Jaccorot/0010/0010.py b/Jaccorot/0010/0010.py index ab8451c2..21b9a422 100644 --- a/Jaccorot/0010/0010.py +++ b/Jaccorot/0010/0010.py @@ -1,6 +1,12 @@ #!/usr/bin/python #coding=utf-8 +""" + +第 0010 题:使用 Python 生成字母验证码图片 + +""" + from PIL import Image, ImageDraw, ImageFont, ImageFilter import random diff --git a/Jaccorot/0011/0011.py b/Jaccorot/0011/0011.py new file mode 100644 index 00000000..0d9d3bca --- /dev/null +++ b/Jaccorot/0011/0011.py @@ -0,0 +1,28 @@ +#!/usr/bin/python +# coding=utf-8 + +""" +第 0011 题: 敏感词文本文件 filtered_words.txt,里面的内容为以下内容,当用户输入敏感词语时,则打印出 Freedom, +否则打印出 Human Rights。 +""" + + +def trans_to_words(): + type_in = raw_input(">") + judge_flag = False + with open('filtered_words.txt') as f: + text = f.read().decode('utf-8').encode('gbk') + + for i in text.split("\n"): + if i in type_in: + judge_flag = True + + if judge_flag: + print "Freedom" + else: + print "Human Rights" + + +if __name__ == "__main__": + while True: + trans_to_words() diff --git a/Jaccorot/0011/filtered_words.txt b/Jaccorot/0011/filtered_words.txt new file mode 100644 index 00000000..69373b64 --- /dev/null +++ b/Jaccorot/0011/filtered_words.txt @@ -0,0 +1,11 @@ +北京 +程序员 +公务员 +领导 +牛比 +牛逼 +你娘 +你妈 +love +sex +jiangge \ No newline at end of file diff --git a/Jaccorot/0012/0012.py b/Jaccorot/0012/0012.py new file mode 100644 index 00000000..dae4d5e9 --- /dev/null +++ b/Jaccorot/0012/0012.py @@ -0,0 +1,22 @@ +#!/usr/bin/python +# coding=utf-8 + +""" +第 0012 题: 敏感词文本文件 filtered_words.txt,里面的内容 和 0011题一样, +当用户输入敏感词语,则用 星号 * 替换,例如当用户输入「北京是个好城市」,则变成「**是个好城市」。 +""" + + +def trans_to_words(): + type_in = raw_input(">") + with open('filtered_words.txt') as f: + text = f.read().decode('utf-8').encode('gbk') + print text.split("\n") + for i in text.split("\n"): + if i in type_in: + type_in = type_in.replace(i, '**') + print type_in + +if __name__ == "__main__": + while True: + trans_to_words() diff --git a/Jaccorot/0012/filtered_words.txt b/Jaccorot/0012/filtered_words.txt new file mode 100644 index 00000000..69373b64 --- /dev/null +++ b/Jaccorot/0012/filtered_words.txt @@ -0,0 +1,11 @@ +北京 +程序员 +公务员 +领导 +牛比 +牛逼 +你娘 +你妈 +love +sex +jiangge \ No newline at end of file diff --git a/Jaccorot/0013/0013.py b/Jaccorot/0013/0013.py new file mode 100644 index 00000000..ad340a09 --- /dev/null +++ b/Jaccorot/0013/0013.py @@ -0,0 +1,30 @@ +#!/usr/bin/python +# coding=utf-8 + +""" +第 0013 题: 用 Python 写一个爬图片的程序,爬 这个链接里的日本妹子图片 :-) +""" + +import os +import urllib +from bs4 import BeautifulSoup +from urlparse import urlsplit + + +def catch_tieba_pics(url): + content = urllib.urlopen(url) + bs = BeautifulSoup(content, 'lxml') + for i in bs.find_all('img', {"class": "BDE_Image"}): + download_pic(i['src']) + + +def download_pic(url): + image_content = urllib.urlopen(url).read() + file_name = os.path.basename(urlsplit(url)[2]) + output = open(file_name, 'wb') + output.write(image_content) + output.close() + + +if __name__ == '__main__': + catch_tieba_pics('http://tieba.baidu.com/p/2166231880') diff --git a/Jaccorot/0014/0014.py b/Jaccorot/0014/0014.py new file mode 100644 index 00000000..5eaa5b05 --- /dev/null +++ b/Jaccorot/0014/0014.py @@ -0,0 +1,42 @@ +#!/usr/bin/python +# coding=utf-8 + +""" +第 0014 题: 纯文本文件 student.txt为学生信息, 里面的内容(包括花括号)如下所示, +请将上述内容写到 student.xls 文件中,如下图所示: +""" + +import os +import json +import xlwt + +def read_txt(path): + with open(path, 'r') as f: + text = f.read().decode('utf-8') + text_json = json.loads(text) + return text_json + + +def save_into_excel(content_dict, excel_name): + wb = xlwt.Workbook() + ws = wb.add_sheet("student", cell_overwrite_ok=True) + row = 0 + col = 0 + + for k, v in sorted(content_dict.items(),key=lambda d:d[0]): + ws.write(row, col, k) + for i in v: + col += 1 + ws.write(row, col, i) + + row += 1 + col = 0 + + wb.save(excel_name) + + +if __name__ == "__main__": + read_content = read_txt(os.path.join(os.path.split(__file__)[0], 'student.txt')) + save_into_excel(read_content, 'student.xls') + + diff --git a/Jaccorot/0014/student.txt b/Jaccorot/0014/student.txt new file mode 100644 index 00000000..ea9b1593 --- /dev/null +++ b/Jaccorot/0014/student.txt @@ -0,0 +1,5 @@ +{ + "1":["张三",150,120,100], + "2":["李四",90,99,95], + "3":["王五",60,66,68] +} \ No newline at end of file diff --git a/Jaccorot/0015/0015.py b/Jaccorot/0015/0015.py new file mode 100644 index 00000000..113927c3 --- /dev/null +++ b/Jaccorot/0015/0015.py @@ -0,0 +1,39 @@ +#!/usr/bin/python +# coding=utf-8 + +""" +纯文本文件 city.txt为城市信息, 里面的内容(包括花括号)如下所示: +请将上述内容写到 city.xls 文件中,如下图所示: +""" + +import os +import json +import xlwt + +def read_txt(path): + with open(path, 'r') as f: + text = f.read().decode('utf-8') + text_json = json.loads(text) + return text_json + + +def save_into_excel(content_dict, excel_name): + wb = xlwt.Workbook() + ws = wb.add_sheet("city", cell_overwrite_ok=True) + row = 0 + col = 0 + + for k, v in sorted(content_dict.items(),key=lambda d:d[0]): + ws.write(row, col, k) + col += 1 + ws.write(row, col, v) + + row += 1 + col = 0 + + wb.save(excel_name) + + +if __name__ == "__main__": + read_content = read_txt(os.path.join(os.path.split(__file__)[0], 'city.txt')) + save_into_excel(read_content, 'city.xls') diff --git a/Jaccorot/0015/city.txt b/Jaccorot/0015/city.txt new file mode 100644 index 00000000..312f5c19 --- /dev/null +++ b/Jaccorot/0015/city.txt @@ -0,0 +1,5 @@ +{ + "1" : "上海", + "2" : "北京", + "3" : "成都" +} \ No newline at end of file diff --git a/Jaccorot/0016/0016.py b/Jaccorot/0016/0016.py new file mode 100644 index 00000000..c0fe6620 --- /dev/null +++ b/Jaccorot/0016/0016.py @@ -0,0 +1,37 @@ +#!/usr/bin/python +# coding=utf-8 + +""" + 纯文本文件 numbers.txt, 里面的内容(包括方括号)如下所示: +请将上述内容写到 numbers.xls 文件中,如下图所示: +""" + +import os +import json +import xlwt + +def read_txt(path): + with open(path, 'r') as f: + text = f.read().decode('utf-8') + text_json = json.loads(text) + return text_json + + +def save_into_excel(content_dict, excel_name): + wb = xlwt.Workbook() + ws = wb.add_sheet("numbers", cell_overwrite_ok=True) + row = 0 + col = 0 + for i in content_dict: + for k in i: + ws.write(row, col, k) + col += 1 + row += 1 + col = 0 + + wb.save(excel_name) + + +if __name__ == "__main__": + read_content = read_txt(os.path.join(os.path.split(__file__)[0], 'numbers.txt')) + save_into_excel(read_content, 'numbers.xls') diff --git a/Jaccorot/0016/numbers.txt b/Jaccorot/0016/numbers.txt new file mode 100644 index 00000000..c43c0378 --- /dev/null +++ b/Jaccorot/0016/numbers.txt @@ -0,0 +1,5 @@ +[ + [1, 82, 65535], + [20, 90, 13], + [26, 809, 1024] +] \ No newline at end of file