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
Binary file added Silocean/0000/DejaVuSansMono.ttf
Binary file not shown.
18 changes: 18 additions & 0 deletions Silocean/0000/Test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
"""
Created on Fri Jun 5 13:40:53 2015

@author: Tracy
"""

from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont

img = Image.open('icon.jpg')
draw = ImageDraw.Draw(img)
font = ImageFont.truetype('DejaVuSansMono.ttf',100)

draw.text((img.size[0]-100,30),"3",(255,0,0), font)

img.save('result.jpg')
12 changes: 12 additions & 0 deletions Silocean/0004/Test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
__author__ = 'Tracy'

import io, re

count = 0

with io.open('text.txt', 'r') as file:
for line in file.readlines():
list = re.findall("[a-zA-Z]+'*-*[a-zA-Z]*", line)
count += len(list)
print(count)

1 change: 1 addition & 0 deletions Silocean/0004/text.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The Dursleys had everything they wanted, but they also had a secret, and their greatest fear was that somebody would discover it. They didn't think they could bear it if anyone found out about the Potters. Mrs. Potter was Mrs. Dursley's sister, but they hadn't met for several years; in fact, Mrs. Dursley pretended she didn't have a sister, because her sister and her good-for-nothing husband were as unDursleyish as it was possible to be. The Dursleys shuddered to think what the neighbors would say if the Potters arrived in the street. The Dursleys knew that the Potters had a small son, too, but they had never even seen him. This boy was another good reason for keeping the Potters away; they didn't want Dudley mixing with a child like that.
39 changes: 39 additions & 0 deletions Silocean/0007/Test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
__author__ = 'Tracy'

import os, io, re

commentLines = 0
whiteLines = 0
comment = False

path = 'F:\AllKindsOfWorkplace\PyCharmWorkplace\PythonLearning'

count = 0
def tree(path):
filelist = os.listdir(path)
for file in filelist:
if os.path.isdir(os.path.join(path, file)):
tree(os.path.join(path, file))
else:
filename = os.path.basename(os.path.join(path, file))
if filename.endswith(".py"):
# print(filename)
file = io.open(os.path.join(path, file))
parse(file)
file.close()

def parse(file):
global commentLines
global whiteLines
global comment
for line in file.readlines():
# line = line.strip("\n")
if line.startswith("#"):
commentLines += 1
elif re.match("^[\\s&&[^\\n]]*$", line):
whiteLines += 1

tree(path)

print(commentLines)
print(whiteLines)
17 changes: 17 additions & 0 deletions Silocean/0008/Test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>This is the Title</title>

</head>
<body>
<div id="container">

<div id="nav">

<div style="display:none">
<script type="text/javascript" src="http://tajs.qq.com/stats?sId=9394293" charset="UTF-8"></script>
</div>
</body>
</html>
11 changes: 11 additions & 0 deletions Silocean/0008/Test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

# -*- coding=utf-8 -*-

from bs4 import BeautifulSoup
import io
file = io.open('Test.html', 'r')
soup = BeautifulSoup(file)
print(soup.getText().strip("\n"))


file.close()
19 changes: 19 additions & 0 deletions Silocean/0009/Test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<link rel="stylesheet" href="http://tb1.bdstatic.com/??/tb/_/thread_recommend_50cc234.css,/tb/_/grade_e31ce1c.css,/tb/_/interest_smiley_90ea01d.css,/tb/_/aside_float_bar_b8d73a2.css" />
<p class="title"><b>The Dormouse's story</b></p>

<p class="story">Once upon a time there were three little sisters; and their names were
<a href="http://example.com/elsie" class="sister" id="link1">Elsie</a>
<a href="http://example.com/lacie" class="sister" id="link2">Lacie</a>
<a href="http://example.com/tillie" class="sister" id="link3">Tillie</a>
and they lived at the bottom of a well.</p>
<img pic_type="0" class="BDE_Image" src="http://imgsrc.baidu.com/forum/w%3D580/sign=527796ed1f178a82ce3c7fa8c603737f/d3af6ccb0a46f21f6e583272f7246b600c33ae0c.jpg" bdwater="shanshanyoumei,1280,860" width="560" height="376" changedsize="true">
<p class="story">...</p>
</body>
</html>
21 changes: 21 additions & 0 deletions Silocean/0009/Test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
__author__ = 'Tracy'

from bs4 import BeautifulSoup
import io

with io.open('Test.html') as file:
html = file.read()
soup = BeautifulSoup(html)
listA = soup.find_all('a')
listL = soup.find_all('link')
listI = soup.find_all('img')
# print(listA)
# print(listL)
# print(listI)

for x in listA:
print(x['href'])
for x in listL:
print(x['href'])
for x in listI:
print(x['src'])
Binary file added Silocean/0010/DejaVuSansMono.ttf
Binary file not shown.
Binary file added Silocean/0010/Result.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions Silocean/0010/Test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
__author__ = 'Tracy'
import Image,ImageDraw,ImageFont,ImageFilter
import random

image = Image.new('RGB', (50*4, 50), (255,255,255))

font = ImageFont.truetype('DejaVuSansMono.ttf', 24)

draw = ImageDraw.Draw(image)

def randColor():
return (random.randint(64,255), random.randint(64,255), random.randint(64,255))

def randColor2():
return (random.randint(32,127), random.randint(32,127), random.randint(32,127))

def randChar():
return chr(random.randint(65,90))

for x in range(50*4):
for y in range(50):
draw.point((x, y), randColor())

for x in range(4):
draw.text((50*x+10, 10), randChar(), randColor2(), font)

image = image.filter(ImageFilter.BLUR)
image.save('Result.jpg')
image.show()
22 changes: 22 additions & 0 deletions Silocean/0011/Test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import io

file = io.open('filtered_words.txt', 'r')
list = []
for word in file.readlines():
list.append(word.strip('\n'))

print(list)

def isValid(word):
for x in list:
if word == x:
return False
return True

myword = input("please input a word:")
if isValid(myword):
print('Human Rights')
else:
print('Freedom')

file.close()
11 changes: 11 additions & 0 deletions Silocean/0011/filtered_words.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
����
����Ա
����Ա
�쵼
ţ��
ţ��
����
����
love
sex
jiangge
20 changes: 20 additions & 0 deletions Silocean/0012/Test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import io

file = io.open('filtered_words.txt', 'r')
list = []
for word in file.readlines():
list.append(word.strip('\n'))

print(list)

def isValid(mystr):
result = mystr
for x in list:
if result.find(x) != -1:
result = result.replace(x, '**')
return result

mystr = input("please input a string:")
print (isValid(mystr))

file.close()
11 changes: 11 additions & 0 deletions Silocean/0012/filtered_words.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
����
����Ա
����Ա
�쵼
ţ��
ţ��
����
����
love
sex
jiangge
21 changes: 21 additions & 0 deletions Silocean/0013/Test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
__author__ = 'Tracy'
from urllib import urlopen
from bs4 import BeautifulSoup

f = urlopen('http://tieba.baidu.com/p/2166231880').read()

s = BeautifulSoup(f)

images = s.find_all('img', pic_type='0')
count = 1
def download(src):
global count
file_name = str(count) + '.jpg'
content = urlopen(src).read()
with open(file_name, 'wb') as f:
f.write(content)
count += 1

for image in images:
download(image['src'])

5 changes: 5 additions & 0 deletions Silocean/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]
}
21 changes: 21 additions & 0 deletions Silocean/0014/Test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
__author__ = 'Tracy'
import xlwt

with open('Student.txt', 'r') as f:
content = f.read()

dic = eval(content)

file = xlwt.Workbook()
table = file.add_sheet('Test', cell_overwrite_ok=True)


def deal(key, value):
table.write(int(key) - 1, 0, key)
for x in range(len(value)):
table.write(int(key) - 1, x + 1, str(value[x]).decode('gbk'))

for key, value in dic.items():
deal(key, value)

file.save('result.xls')
Binary file added Silocean/0014/result.xls
Binary file not shown.
15 changes: 15 additions & 0 deletions Silocean/0015/Test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
__author__ = 'Tracy'
import xlwt

with open('city.txt') as f:
content = f.read()
dic = eval(content)

file = xlwt.Workbook()
table = file.add_sheet("Test", cell_overwrite_ok=True)

for k, v in dic.items():
table.write(int(k)-1, 0, k)
table.write(int(k)-1, 1, str(v).decode('gbk'))

file.save('result.xls')
5 changes: 5 additions & 0 deletions Silocean/0015/city.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"1" : "�Ϻ�",
"2" : "����",
"3" : "�ɶ�"
}
Binary file added Silocean/0015/result.xls
Binary file not shown.
15 changes: 15 additions & 0 deletions Silocean/0016/Test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
__author__ = 'Tracy'
import xlwt

with open('numbers.txt') as f:
content = f.read()
lists = eval(content)

file = xlwt.Workbook()
table = file.add_sheet('Test',cell_overwrite_ok=True)

for row in range(len(lists)):
for col in range(len(lists[row])):
table.write(row, col, lists[row][col])

file.save('result.xls')
5 changes: 5 additions & 0 deletions Silocean/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 Silocean/0016/result.xls
Binary file not shown.