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
37 changes: 37 additions & 0 deletions agmcs/0007/0007.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import os, re

path = '\..'
blank = 0
comment = 0
total = 0

def getline(path):
global blank
global comment
global total
with open(path,'r')as f:
data = f.readlines()
for x in data:
if x == '\n':
blank += 1
if x.find('#')!= -1:
if re.search("\'.*?#.*?\'",x) or re.search("\".*?#.*?\"",x):
pass
else:
comment += 1
total += 1

def getfile(path):
abspath = os.path.abspath(path)
dirlist = os.listdir(abspath)
for x in dirlist:
curpath = os.path.join(abspath,x)
if os.path.isfile(curpath):
if os.path.splitext(curpath)[1] == '.py':
getline(curpath)
else:
getfile(curpath)

getfile('..')

print "total:%d, comment:%d, blank:%d"%(total,comment,blank)
11 changes: 11 additions & 0 deletions agmcs/0009/0009.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#coding:utf-8
import re

with open('1.html','rb')as f:
data = f.read()

data = data.replace('\r','').replace('\b','').replace('\n','')
find = re.compile(r'href="(.*?)"')
result = find.findall(data)
for x in result:
print x
3 changes: 3 additions & 0 deletions agmcs/0009/1.html

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions agmcs/0010/0010.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from PIL import Image, ImageDraw, ImageFont
import random

im = Image.new('RGBA',(120,50),(255,255,255))
text = random.sample('abcdefghijklmnopqrstuvwxyz\
ABCDEFGHIJKLMNOPQRSTUVWXYZ',4)

draw = ImageDraw.Draw(im)
font = ImageFont.truetype("msyh.ttf",40)

x=0
y=0
for i in xrange(200):
x1 = random.randint(0,120)
y1 = random.randint(0,50)
x2 = random.randint(0,120)
y2 = random.randint(0,50)
fill = (random.randint(130,250),random.randint(130,250),random.randint(130,250))
draw.line(((x1,y1),(x2,y2)),fill=fill)

for word in text:
fill = (random.randint(0,130),random.randint(0,130),random.randint(0,130))
draw.text((x,y),word,font=font,fill=fill)
x+=30

for i in xrange(1000):
x1 = random.randint(0,119)
y1 = random.randint(0,49)
fill = (random.randint(20,250),random.randint(20,250),random.randint(20,250))
im.putpixel((x1,y1),fill)

im.save('1.jpg')
Binary file added agmcs/0010/1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions agmcs/0011/0011.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#coding:utf-8
with open('filtered_words.txt','r')as f:
data = f.read()

filt = data.split('\n')

while True:
flag = False
text = raw_input("please input:")
for x in filt:
if text.find(x) != -1:
flag = True
if flag:
print "Freedom"
else:
print "Human Rights"
11 changes: 11 additions & 0 deletions agmcs/0011/filtered_words.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
����
����Ա
����Ա
�쵼
ţ��
ţ��
����
����
love
sex
jiangge
13 changes: 13 additions & 0 deletions agmcs/0012/0012.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#coding:utf-8
with open('filtered_words.txt','r')as f:
data = f.read().decode('gbk')

filt = data.split('\n')

while True:
text = raw_input("please input:")
text = text.decode('gbk')
for x in filt:
if text.find(x) != -1:
text = text.replace(x,'*'*len(x))
print text
11 changes: 11 additions & 0 deletions agmcs/0012/filtered_words.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
����
����Ա
����Ա
�쵼
ţ��
ţ��
����
����
love
sex
jiangge
24 changes: 24 additions & 0 deletions agmcs/0013/0013.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#coding:utf-8
import requests, re, os

url = 'http://tieba.baidu.com/p/2166231880'

header = {
'Accept': '*/*',
'Accept-Encoding':'gzip,deflate,sdch',
'Accept-Language':'zh-CN,zh;q=0.8',
'Connection':'keep-alive'
}
html = requests.get(url,headers = header)

data = html.content.decode('utf-8')
find = re.compile(r'<img pic_type="0" class="BDE_Image" src="(.*?).jpg" bdwater')
result = find.findall(data)

for img_url in result:
name = img_url.split('/')[-1]
img_url = img_url+'.jpg'
html = requests.get(img_url,headers = header)
im = html.content
with open(name+'.jpg','wb')as f:
f.write(im)
17 changes: 17 additions & 0 deletions agmcs/0014/0014.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#coding:utf-8
import json
import xlwt

with open('student.txt','r')as f:
data = f.read().decode('gbk')
data = json.loads(data)

book =xlwt.Workbook(encoding = 'utf-8')
sheet =book.add_sheet('student')

for i in range(len(data)):
d = data[str(i+1)]
sheet.write(i,0,i+1)
for j in range(len(d)):
sheet.write(i,j+1,d[j])
book.save('student.xls')
5 changes: 5 additions & 0 deletions agmcs/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]
}
Binary file added agmcs/0014/student.xls
Binary file not shown.
14 changes: 14 additions & 0 deletions agmcs/0015/0015.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import json, xlwt

with open('city.txt','r')as f:
data = f.read().decode('gbk')
data = json.loads(data)

book = xlwt.Workbook(encoding='utf-8')
sheet = book.add_sheet('city')

for i in range(len(data)):
sheet.write(i,0,i)
sheet.write(i,1,data[str(i+1)])
book.save('city.xls')

5 changes: 5 additions & 0 deletions agmcs/0015/city.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"1" : "�Ϻ�",
"2" : "����",
"3" : "�ɶ�"
}
Binary file added agmcs/0015/city.xls
Binary file not shown.
13 changes: 13 additions & 0 deletions agmcs/0016/0016.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import json, xlwt

with open('numbers.txt','r')as f:
data = f.read().decode('gbk')
data = json.loads(data)

book = xlwt.Workbook(encoding = 'utf-8')
sheet = book.add_sheet('numbers')
for i in range(len(data)):
for j in range(len(data[i])):
sheet.write(i,j,data[i][j])
book.save('numbers.xls')

5 changes: 5 additions & 0 deletions agmcs/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]
]
Binary file added agmcs/0016/numbers.xls
Binary file not shown.