Skip to content

Commit d59f0e2

Browse files
committed
Merge pull request Show-Me-the-Code#16 from agmcs/master
task 0007-0015
2 parents d5baa22 + 08d92be commit d59f0e2

19 files changed

Lines changed: 217 additions & 0 deletions

File tree

agmcs/0007/0007.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import os, re
2+
3+
path = '\..'
4+
blank = 0
5+
comment = 0
6+
total = 0
7+
8+
def getline(path):
9+
global blank
10+
global comment
11+
global total
12+
with open(path,'r')as f:
13+
data = f.readlines()
14+
for x in data:
15+
if x == '\n':
16+
blank += 1
17+
if x.find('#')!= -1:
18+
if re.search("\'.*?#.*?\'",x) or re.search("\".*?#.*?\"",x):
19+
pass
20+
else:
21+
comment += 1
22+
total += 1
23+
24+
def getfile(path):
25+
abspath = os.path.abspath(path)
26+
dirlist = os.listdir(abspath)
27+
for x in dirlist:
28+
curpath = os.path.join(abspath,x)
29+
if os.path.isfile(curpath):
30+
if os.path.splitext(curpath)[1] == '.py':
31+
getline(curpath)
32+
else:
33+
getfile(curpath)
34+
35+
getfile('..')
36+
37+
print "total:%d, comment:%d, blank:%d"%(total,comment,blank)

agmcs/0009/0009.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#coding:utf-8
2+
import re
3+
4+
with open('1.html','rb')as f:
5+
data = f.read()
6+
7+
data = data.replace('\r','').replace('\b','').replace('\n','')
8+
find = re.compile(r'href="(.*?)"')
9+
result = find.findall(data)
10+
for x in result:
11+
print x

agmcs/0009/1.html

Lines changed: 3 additions & 0 deletions
Large diffs are not rendered by default.

agmcs/0010/0010.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from PIL import Image, ImageDraw, ImageFont
2+
import random
3+
4+
im = Image.new('RGBA',(120,50),(255,255,255))
5+
text = random.sample('abcdefghijklmnopqrstuvwxyz\
6+
ABCDEFGHIJKLMNOPQRSTUVWXYZ',4)
7+
8+
draw = ImageDraw.Draw(im)
9+
font = ImageFont.truetype("msyh.ttf",40)
10+
11+
x=0
12+
y=0
13+
for i in xrange(200):
14+
x1 = random.randint(0,120)
15+
y1 = random.randint(0,50)
16+
x2 = random.randint(0,120)
17+
y2 = random.randint(0,50)
18+
fill = (random.randint(130,250),random.randint(130,250),random.randint(130,250))
19+
draw.line(((x1,y1),(x2,y2)),fill=fill)
20+
21+
for word in text:
22+
fill = (random.randint(0,130),random.randint(0,130),random.randint(0,130))
23+
draw.text((x,y),word,font=font,fill=fill)
24+
x+=30
25+
26+
for i in xrange(1000):
27+
x1 = random.randint(0,119)
28+
y1 = random.randint(0,49)
29+
fill = (random.randint(20,250),random.randint(20,250),random.randint(20,250))
30+
im.putpixel((x1,y1),fill)
31+
32+
im.save('1.jpg')

agmcs/0010/1.jpg

4.11 KB
Loading

agmcs/0011/0011.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#coding:utf-8
2+
with open('filtered_words.txt','r')as f:
3+
data = f.read()
4+
5+
filt = data.split('\n')
6+
7+
while True:
8+
flag = False
9+
text = raw_input("please input:")
10+
for x in filt:
11+
if text.find(x) != -1:
12+
flag = True
13+
if flag:
14+
print "Freedom"
15+
else:
16+
print "Human Rights"

agmcs/0011/filtered_words.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
����
2+
����Ա
3+
����Ա
4+
�쵼
5+
ţ��
6+
ţ��
7+
����
8+
����
9+
love
10+
sex
11+
jiangge

agmcs/0012/0012.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#coding:utf-8
2+
with open('filtered_words.txt','r')as f:
3+
data = f.read().decode('gbk')
4+
5+
filt = data.split('\n')
6+
7+
while True:
8+
text = raw_input("please input:")
9+
text = text.decode('gbk')
10+
for x in filt:
11+
if text.find(x) != -1:
12+
text = text.replace(x,'*'*len(x))
13+
print text

agmcs/0012/filtered_words.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
����
2+
����Ա
3+
����Ա
4+
�쵼
5+
ţ��
6+
ţ��
7+
����
8+
����
9+
love
10+
sex
11+
jiangge

agmcs/0013/0013.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#coding:utf-8
2+
import requests, re, os
3+
4+
url = 'http://tieba.baidu.com/p/2166231880'
5+
6+
header = {
7+
'Accept': '*/*',
8+
'Accept-Encoding':'gzip,deflate,sdch',
9+
'Accept-Language':'zh-CN,zh;q=0.8',
10+
'Connection':'keep-alive'
11+
}
12+
html = requests.get(url,headers = header)
13+
14+
data = html.content.decode('utf-8')
15+
find = re.compile(r'<img pic_type="0" class="BDE_Image" src="(.*?).jpg" bdwater')
16+
result = find.findall(data)
17+
18+
for img_url in result:
19+
name = img_url.split('/')[-1]
20+
img_url = img_url+'.jpg'
21+
html = requests.get(img_url,headers = header)
22+
im = html.content
23+
with open(name+'.jpg','wb')as f:
24+
f.write(im)

0 commit comments

Comments
 (0)