From a59431d014db8533d2bf797e0b48b2cbe7bf024a Mon Sep 17 00:00:00 2001 From: Jaccorot Date: Sun, 11 Oct 2015 23:43:30 +0800 Subject: [PATCH 1/8] add 0001 --- Jaccorot/0001/0001.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Jaccorot/0001/0001.py diff --git a/Jaccorot/0001/0001.py b/Jaccorot/0001/0001.py new file mode 100644 index 00000000..89480858 --- /dev/null +++ b/Jaccorot/0001/0001.py @@ -0,0 +1,22 @@ +#!/usr/local/bin/python +#coding=utf-8 + +#第 0001 题:做为 Apple Store App 独立开发者,你要搞限时促销,为你的应用生成激活码(或者优惠券), +#使用 Python 如何生成 200 个激活码(或者优惠券)? + +import uuid + + +def create_code(num, length): +#生成”num“个激活码,每个激活码含有”length“位 + result = [] + while True: + uuid_id = uuid.uuid1() + temp = str(uuid_id).replace('-', '')[:length] + if not temp in result: + result.append(temp) + if len(result) == num: + break + return result + +print create_code(200, 20) From 3fbfb354bedd8a8806c5a8ff37e4c100fcdbf514 Mon Sep 17 00:00:00 2001 From: Jaccorot Date: Fri, 16 Oct 2015 18:52:02 +0800 Subject: [PATCH 2/8] fix 0010 --- Jaccorot/0010/0010.py | 6 ++++++ 1 file changed, 6 insertions(+) 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 From c820d616bcebce4832c004645d98c1e013754619 Mon Sep 17 00:00:00 2001 From: Jaccorot Date: Tue, 20 Oct 2015 22:24:45 +0800 Subject: [PATCH 3/8] add 0011 --- Jaccorot/0011/0011.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 Jaccorot/0011/0011.py diff --git a/Jaccorot/0011/0011.py b/Jaccorot/0011/0011.py new file mode 100644 index 00000000..e69de29b From ca6a28de8dc35f57b59058c4fb1a7e876d0f9f79 Mon Sep 17 00:00:00 2001 From: Jaccorot Date: Wed, 21 Oct 2015 22:15:01 +0800 Subject: [PATCH 4/8] add 0012 --- Jaccorot/0012/0012.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 Jaccorot/0012/0012.py diff --git a/Jaccorot/0012/0012.py b/Jaccorot/0012/0012.py new file mode 100644 index 00000000..e69de29b From c1160e39668d386e338d9abd0f4a368000d7b3b8 Mon Sep 17 00:00:00 2001 From: Jaccorot Date: Thu, 22 Oct 2015 21:21:36 +0800 Subject: [PATCH 5/8] fix 0011 0012 --- Jaccorot/0009/0009.py | 6 ++++++ Jaccorot/0011/0011.py | 28 ++++++++++++++++++++++++++++ Jaccorot/0011/filtered_words.txt | 11 +++++++++++ Jaccorot/0012/0012.py | 22 ++++++++++++++++++++++ Jaccorot/0012/filtered_words.txt | 11 +++++++++++ 5 files changed, 78 insertions(+) create mode 100644 Jaccorot/0011/filtered_words.txt create mode 100644 Jaccorot/0012/filtered_words.txt 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/0011/0011.py b/Jaccorot/0011/0011.py index e69de29b..0d9d3bca 100644 --- a/Jaccorot/0011/0011.py +++ 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 index e69de29b..dae4d5e9 100644 --- a/Jaccorot/0012/0012.py +++ 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 From b9d9ddabfd0a56807bd54daa4e4ab93d13aae4f8 Mon Sep 17 00:00:00 2001 From: Jaccorot Date: Fri, 23 Oct 2015 20:43:21 +0800 Subject: [PATCH 6/8] add 0013 --- Jaccorot/0013/0013.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Jaccorot/0013/0013.py 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') From b709d29ff469956e6f5268381a5070d911990470 Mon Sep 17 00:00:00 2001 From: Jaccorot Date: Sun, 25 Oct 2015 23:53:34 +0800 Subject: [PATCH 7/8] add 0014 --- Jaccorot/0014/0014.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 Jaccorot/0014/0014.py diff --git a/Jaccorot/0014/0014.py b/Jaccorot/0014/0014.py new file mode 100644 index 00000000..e69de29b From 9bff757d94873b438bc42294973d78a94d8df9a7 Mon Sep 17 00:00:00 2001 From: Jaccorot Date: Mon, 26 Oct 2015 21:14:44 +0800 Subject: [PATCH 8/8] fix 0014,add 0015 0016 --- Jaccorot/0014/0014.py | 42 +++++++++++++++++++++++++++++++++++++++ Jaccorot/0014/student.txt | 5 +++++ Jaccorot/0015/0015.py | 39 ++++++++++++++++++++++++++++++++++++ Jaccorot/0015/city.txt | 5 +++++ Jaccorot/0016/0016.py | 37 ++++++++++++++++++++++++++++++++++ Jaccorot/0016/numbers.txt | 5 +++++ 6 files changed, 133 insertions(+) create mode 100644 Jaccorot/0014/student.txt create mode 100644 Jaccorot/0015/0015.py create mode 100644 Jaccorot/0015/city.txt create mode 100644 Jaccorot/0016/0016.py create mode 100644 Jaccorot/0016/numbers.txt diff --git a/Jaccorot/0014/0014.py b/Jaccorot/0014/0014.py index e69de29b..5eaa5b05 100644 --- a/Jaccorot/0014/0014.py +++ 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