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
15 changes: 15 additions & 0 deletions Forec/0000/0000.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from PIL import Image, ImageDraw, ImageFont

def add_num(num, fill, font_name):
im = Image.open('in.jpg')
xsize , ysize = im.size
draw = ImageDraw.Draw(im)
text = str(num)
font = ImageFont.truetype(font_name, xsize//3)
draw.text((ysize//5 * 4, 0), text, fill, font)
im.save("out.jpg")

num = 4
fill = (255, 0, 255)
font_name = "verdana.ttf"
add_num(num, fill, font_name)
Binary file added Forec/0000/in.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Forec/0000/out.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Forec/0000/verdana.ttf
Binary file not shown.
1 change: 1 addition & 0 deletions Forec/0004/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I love you baby, so I just love you baby, no matter how fast baby
1 change: 1 addition & 0 deletions Forec/0006/1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I love you Beijing
1 change: 1 addition & 0 deletions Forec/0006/2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I love you London
1 change: 1 addition & 0 deletions Forec/0006/3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I love you changchang
14 changes: 14 additions & 0 deletions Forec/0008/0008.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# coding = 'utf-8'
__author__ = 'Forec'

import requests
from bs4 import BeautifulSoup
import re
import pdb

# url = input()
url = 'http://forec.github.io/2015/11/01/Computer-Organization-Architecture5/'
html = requests.get(url)

soup = BeautifulSoup(html.text,"html.parser")
print(soup.body.text.encode('GBK','ignore').decode('GBK'))
1 change: 1 addition & 0 deletions Forec/0009/0009.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#coding = utf-8
# 输入链接
__author__ = 'Forec'

import requests
Expand Down
73 changes: 73 additions & 0 deletions Forec/0010/0010.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#coding = utf-8
# Make check codes
__author__ = 'Forec'

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

num = ''.join(random.sample('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',4))

def random_col():
return (random.randint(50,200),random.randint(50,200),random.randint(50,200))

def make( strs, width = 400, height = 200):
im = Image.new( 'RGB', (width, height ), (255,255,255))
draw = ImageDraw.Draw(im)
font = ImageFont.truetype('verdana.ttf',width//4)
font_width , font_height = font.getsize(strs)
strs_len = len(strs)
x = (width - font_width) // 2
y = (height - font_height ) //2
total_dex = 0
for i in strs:
draw.text((x,y), i, random_col(), font)
temp = random.randint(-30,30)
total_dex += temp
im = im.rotate(temp)
draw = ImageDraw.Draw(im)
x += font_width/strs_len
im = im.rotate(-total_dex)
draw = ImageDraw.Draw(im)
draw.line(
[(random.randint(0,width//4),
random.randint(0,height//4)
),
(random.randint(width//4*3,width),
random.randint(height//4*3,height)
)],
fill = random_col(),
width = width // 80
)
draw.line(
[(random.randint(0,width//4),
random.randint(height//4*3,height)
),
(random.randint(width//3*2,width),
random.randint(0,height//3)
)],
fill = random_col(),
width = width // 80
)
draw.line(
[(random.randint(width//4*3,width),
random.randint(height//4*3,height)
),
(random.randint(width//3*2,width),
random.randint(0,height//3)
)],
fill = random_col(),
width = width // 80
)
# im = im.crop((width//10,height//10,width,height))
for x in range(width):
for y in range(height):
col = im.getpixel((x,y))
if col == (255,255,255) or col == (0,0,0):
draw.point((x,y), fill = random_col())
im = im.filter(ImageFilter.BLUR)
# im.show()
# im = im.convert('L')
im.save('out.jpg')

if __name__ == '__main__':
make(num)
Binary file added Forec/0010/out.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Forec/0010/verdana.ttf
Binary file not shown.
15 changes: 15 additions & 0 deletions Forec/0011/0011.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# coding = utf-8
__author__ = 'Forec'
word_filter = set()
with open('filtered_words.txt',"r") as f:
for x in f.readlines():
word_filter |= {x.rstrip('\n')}
while True:
s = input()
if s == 'exit':
break
elif s in word_filter:
print('Freedom')
else:
print('Human Rights')

11 changes: 11 additions & 0 deletions Forec/0011/filtered_words.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
����
����Ա
����Ա
�쵼
ţ��
ţ��
����
����
love
sex
jiangge
14 changes: 14 additions & 0 deletions Forec/0012/0012.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# coding = utf-8
__author__ = 'Forec'
word_filter = set()
with open('filtered_words.txt',"r") as f:
for x in f.readlines():
word_filter |= {x.strip('\n')}
while True:
s = input()
if s =='exit':
break
for x in word_filter:
if x in s:
s = s.replace(x,'*'*len(x))
print(s)
11 changes: 11 additions & 0 deletions Forec/0012/filtered_words.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
����
����Ա
����Ա
�쵼
ţ��
ţ��
����
����
love
sex
jiangge
32 changes: 32 additions & 0 deletions Forec/0013/0013.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# coding = utf-8
__author__ = 'Forec'
import urllib, urllib.request
import re

url = "http://tieba.baidu.com/p/2166231880"
urlhd = urllib.request.Request( url, headers = {
'Connection': 'Keep-Alive',
'Accept': 'text/html, application/xhtml+xml, */*',
'Accept-Language': 'en-US,en;q=0.8,zh-Hans-CN;q=0.5,zh-Hans;q=0.3',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko'
})
page = urllib.request.urlopen(urlhd)
try:
data = page.read().decode('utf-8')
except:
exit(0)

imgre = re.compile(r'src=\"(.*?)\"')
results = imgre.findall(data)
picnum =0
for x in results:
if '.jpg' not in x:
continue
img = urllib.request.urlopen(x,timeout = 3).read()
try:
f = open(str(picnum)+'.jpg','wb')
f.write(img)
picnum+=1
f.close;
except:
print('无法将图片%s写入%s' % (x, str(picnum) +'.jpg' ) )
16 changes: 16 additions & 0 deletions Forec/0014/0014.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# coding = utf-8
__author__ = 'Forec'
import xlwt
import re

book = xlwt.Workbook(encoding = 'utf-8', style_compression=0)
sheet = book.add_sheet('student',cell_overwrite_ok = True)
line = 0
info = re.compile(r'\"(\d+)\":\[\"(.*?)\",(\d+),(\d+),(\d+)\]')
with open('student.txt',"r") as f:
data = f.read()
for x in info.findall(data):
for i in range(len(x)):
sheet.write(line,i,x[i])
line+=1
book.save('student.xls')
5 changes: 5 additions & 0 deletions Forec/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 Forec/0014/student.xls
Binary file not shown.
16 changes: 16 additions & 0 deletions Forec/0015/0015.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# coding = utf-8
__author__ = 'Forec'
import xlwt
import re

book = xlwt.Workbook(encoding = 'utf-8', style_compression=0)
sheet = book.add_sheet('student',cell_overwrite_ok = True)
line = 0
info = re.compile(r'\"(\d+)\" : \"(.*?)\"')
with open('city.txt',"r") as f:
data = f.read()
for x in info.findall(data):
for i in range(len(x)):
sheet.write(line,i,x[i])
line+=1
book.save('city.xls')
5 changes: 5 additions & 0 deletions Forec/0015/city.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"1" : "�Ϻ�",
"2" : "����",
"3" : "�ɶ�"
}
Binary file added Forec/0015/city.xls
Binary file not shown.