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
6 changes: 6 additions & 0 deletions Jaccorot/0009/0009.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#!/usr/bin/python
#coding=utf-8

"""

第 0009 题:一个HTML文件,找出里面的链接

"""

from bs4 import BeautifulSoup

def find_the_link(filepath):
Expand Down
6 changes: 6 additions & 0 deletions Jaccorot/0010/0010.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#!/usr/bin/python
#coding=utf-8

"""

第 0010 题:使用 Python 生成字母验证码图片

"""

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

Expand Down
28 changes: 28 additions & 0 deletions Jaccorot/0011/0011.py
Original file line number Diff line number Diff line change
@@ -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()
11 changes: 11 additions & 0 deletions Jaccorot/0011/filtered_words.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
北京
程序员
公务员
领导
牛比
牛逼
你娘
你妈
love
sex
jiangge
22 changes: 22 additions & 0 deletions Jaccorot/0012/0012.py
Original file line number Diff line number Diff line change
@@ -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()
11 changes: 11 additions & 0 deletions Jaccorot/0012/filtered_words.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
北京
程序员
公务员
领导
牛比
牛逼
你娘
你妈
love
sex
jiangge
30 changes: 30 additions & 0 deletions Jaccorot/0013/0013.py
Original file line number Diff line number Diff line change
@@ -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')
42 changes: 42 additions & 0 deletions Jaccorot/0014/0014.py
Original file line number Diff line number Diff line change
@@ -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')


5 changes: 5 additions & 0 deletions Jaccorot/0014/student.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"1":["张三",150,120,100],
"2":["李四",90,99,95],
"3":["王五",60,66,68]
}
39 changes: 39 additions & 0 deletions Jaccorot/0015/0015.py
Original file line number Diff line number Diff line change
@@ -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')
5 changes: 5 additions & 0 deletions Jaccorot/0015/city.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"1" : "上海",
"2" : "北京",
"3" : "成都"
}
37 changes: 37 additions & 0 deletions Jaccorot/0016/0016.py
Original file line number Diff line number Diff line change
@@ -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')
5 changes: 5 additions & 0 deletions Jaccorot/0016/numbers.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[
[1, 82, 65535],
[20, 90, 13],
[26, 809, 1024]
]